wps.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /*
  2. * Wi-Fi Protected Setup
  3. * Copyright (c) 2007-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef WPS_H
  9. #define WPS_H
  10. #include "wps_defs.h"
  11. /**
  12. * enum wsc_op_code - EAP-WSC OP-Code values
  13. */
  14. enum wsc_op_code {
  15. WSC_UPnP = 0 /* No OP Code in UPnP transport */,
  16. WSC_Start = 0x01,
  17. WSC_ACK = 0x02,
  18. WSC_NACK = 0x03,
  19. WSC_MSG = 0x04,
  20. WSC_Done = 0x05,
  21. WSC_FRAG_ACK = 0x06
  22. };
  23. struct wps_registrar;
  24. struct upnp_wps_device_sm;
  25. struct wps_er;
  26. struct wps_parse_attr;
  27. /**
  28. * struct wps_credential - WPS Credential
  29. * @ssid: SSID
  30. * @ssid_len: Length of SSID
  31. * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
  32. * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
  33. * @key_idx: Key index
  34. * @key: Key
  35. * @key_len: Key length in octets
  36. * @mac_addr: MAC address of the Credential receiver
  37. * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
  38. * this may be %NULL, if not used
  39. * @cred_attr_len: Length of cred_attr in octets
  40. * @ap_channel: AP channel
  41. */
  42. struct wps_credential {
  43. u8 ssid[32];
  44. size_t ssid_len;
  45. u16 auth_type;
  46. u16 encr_type;
  47. u8 key_idx;
  48. u8 key[64];
  49. size_t key_len;
  50. u8 mac_addr[ETH_ALEN];
  51. const u8 *cred_attr;
  52. size_t cred_attr_len;
  53. u16 ap_channel;
  54. };
  55. #define WPS_DEV_TYPE_LEN 8
  56. #define WPS_DEV_TYPE_BUFSIZE 21
  57. #define WPS_SEC_DEV_TYPE_MAX_LEN 128
  58. /* maximum number of advertised WPS vendor extension attributes */
  59. #define MAX_WPS_VENDOR_EXTENSIONS 10
  60. /* maximum size of WPS Vendor extension attribute */
  61. #define WPS_MAX_VENDOR_EXT_LEN 1024
  62. /* maximum number of parsed WPS vendor extension attributes */
  63. #define MAX_WPS_PARSE_VENDOR_EXT 10
  64. /**
  65. * struct wps_device_data - WPS Device Data
  66. * @mac_addr: Device MAC address
  67. * @device_name: Device Name (0..32 octets encoded in UTF-8)
  68. * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
  69. * @model_name: Model Name (0..32 octets encoded in UTF-8)
  70. * @model_number: Model Number (0..32 octets encoded in UTF-8)
  71. * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
  72. * @pri_dev_type: Primary Device Type
  73. * @sec_dev_type: Array of secondary device types
  74. * @num_sec_dev_type: Number of secondary device types
  75. * @os_version: OS Version
  76. * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
  77. * @p2p: Whether the device is a P2P device
  78. */
  79. struct wps_device_data {
  80. u8 mac_addr[ETH_ALEN];
  81. char *device_name;
  82. char *manufacturer;
  83. char *model_name;
  84. char *model_number;
  85. char *serial_number;
  86. u8 pri_dev_type[WPS_DEV_TYPE_LEN];
  87. #define WPS_SEC_DEVICE_TYPES 5
  88. u8 sec_dev_type[WPS_SEC_DEVICE_TYPES][WPS_DEV_TYPE_LEN];
  89. u8 num_sec_dev_types;
  90. u32 os_version;
  91. u8 rf_bands;
  92. u16 config_methods;
  93. struct wpabuf *vendor_ext_m1;
  94. struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
  95. int p2p;
  96. };
  97. /**
  98. * struct wps_config - WPS configuration for a single registration protocol run
  99. */
  100. struct wps_config {
  101. /**
  102. * wps - Pointer to long term WPS context
  103. */
  104. struct wps_context *wps;
  105. /**
  106. * registrar - Whether this end is a Registrar
  107. */
  108. int registrar;
  109. /**
  110. * pin - Enrollee Device Password (%NULL for Registrar or PBC)
  111. */
  112. const u8 *pin;
  113. /**
  114. * pin_len - Length on pin in octets
  115. */
  116. size_t pin_len;
  117. /**
  118. * pbc - Whether this is protocol run uses PBC
  119. */
  120. int pbc;
  121. /**
  122. * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
  123. */
  124. const struct wpabuf *assoc_wps_ie;
  125. /**
  126. * new_ap_settings - New AP settings (%NULL if not used)
  127. *
  128. * This parameter provides new AP settings when using a wireless
  129. * stations as a Registrar to configure the AP. %NULL means that AP
  130. * will not be reconfigured, i.e., the station will only learn the
  131. * current AP settings by using AP PIN.
  132. */
  133. const struct wps_credential *new_ap_settings;
  134. /**
  135. * peer_addr: MAC address of the peer in AP; %NULL if not AP
  136. */
  137. const u8 *peer_addr;
  138. /**
  139. * use_psk_key - Use PSK format key in Credential
  140. *
  141. * Force PSK format to be used instead of ASCII passphrase when
  142. * building Credential for an Enrollee. The PSK value is set in
  143. * struct wpa_context::psk.
  144. */
  145. int use_psk_key;
  146. /**
  147. * dev_pw_id - Device Password ID for Enrollee when PIN is used
  148. */
  149. u16 dev_pw_id;
  150. /**
  151. * p2p_dev_addr - P2P Device Address from (Re)Association Request
  152. *
  153. * On AP/GO, this is set to the P2P Device Address of the associating
  154. * P2P client if a P2P IE is included in the (Re)Association Request
  155. * frame and the P2P Device Address is included. Otherwise, this is set
  156. * to %NULL to indicate the station does not have a P2P Device Address.
  157. */
  158. const u8 *p2p_dev_addr;
  159. /**
  160. * pbc_in_m1 - Do not remove PushButton config method in M1 (AP)
  161. *
  162. * This can be used to enable a workaround to allow Windows 7 to use
  163. * PBC with the AP.
  164. */
  165. int pbc_in_m1;
  166. /**
  167. * peer_pubkey_hash - Peer public key hash or %NULL if not known
  168. */
  169. const u8 *peer_pubkey_hash;
  170. };
  171. struct wps_data * wps_init(const struct wps_config *cfg);
  172. void wps_deinit(struct wps_data *data);
  173. /**
  174. * enum wps_process_res - WPS message processing result
  175. */
  176. enum wps_process_res {
  177. /**
  178. * WPS_DONE - Processing done
  179. */
  180. WPS_DONE,
  181. /**
  182. * WPS_CONTINUE - Processing continues
  183. */
  184. WPS_CONTINUE,
  185. /**
  186. * WPS_FAILURE - Processing failed
  187. */
  188. WPS_FAILURE,
  189. /**
  190. * WPS_PENDING - Processing continues, but waiting for an external
  191. * event (e.g., UPnP message from an external Registrar)
  192. */
  193. WPS_PENDING
  194. };
  195. enum wps_process_res wps_process_msg(struct wps_data *wps,
  196. enum wsc_op_code op_code,
  197. const struct wpabuf *msg);
  198. struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
  199. int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
  200. int wps_is_selected_pin_registrar(const struct wpabuf *msg);
  201. int wps_ap_priority_compar(const struct wpabuf *wps_a,
  202. const struct wpabuf *wps_b);
  203. int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
  204. int ver1_compat);
  205. const u8 * wps_get_uuid_e(const struct wpabuf *msg);
  206. int wps_is_20(const struct wpabuf *msg);
  207. struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
  208. struct wpabuf * wps_build_assoc_resp_ie(void);
  209. struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
  210. const u8 *uuid,
  211. enum wps_request_type req_type,
  212. unsigned int num_req_dev_types,
  213. const u8 *req_dev_types);
  214. /**
  215. * struct wps_registrar_config - WPS Registrar configuration
  216. */
  217. struct wps_registrar_config {
  218. /**
  219. * new_psk_cb - Callback for new PSK
  220. * @ctx: Higher layer context data (cb_ctx)
  221. * @mac_addr: MAC address of the Enrollee
  222. * @p2p_dev_addr: P2P Device Address of the Enrollee or all zeros if not
  223. * @psk: The new PSK
  224. * @psk_len: The length of psk in octets
  225. * Returns: 0 on success, -1 on failure
  226. *
  227. * This callback is called when a new per-device PSK is provisioned.
  228. */
  229. int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
  230. const u8 *psk, size_t psk_len);
  231. /**
  232. * set_ie_cb - Callback for WPS IE changes
  233. * @ctx: Higher layer context data (cb_ctx)
  234. * @beacon_ie: WPS IE for Beacon
  235. * @probe_resp_ie: WPS IE for Probe Response
  236. * Returns: 0 on success, -1 on failure
  237. *
  238. * This callback is called whenever the WPS IE in Beacon or Probe
  239. * Response frames needs to be changed (AP only). Callee is responsible
  240. * for freeing the buffers.
  241. */
  242. int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
  243. struct wpabuf *probe_resp_ie);
  244. /**
  245. * pin_needed_cb - Callback for requesting a PIN
  246. * @ctx: Higher layer context data (cb_ctx)
  247. * @uuid_e: UUID-E of the unknown Enrollee
  248. * @dev: Device Data from the unknown Enrollee
  249. *
  250. * This callback is called whenever an unknown Enrollee requests to use
  251. * PIN method and a matching PIN (Device Password) is not found in
  252. * Registrar data.
  253. */
  254. void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
  255. const struct wps_device_data *dev);
  256. /**
  257. * reg_success_cb - Callback for reporting successful registration
  258. * @ctx: Higher layer context data (cb_ctx)
  259. * @mac_addr: MAC address of the Enrollee
  260. * @uuid_e: UUID-E of the Enrollee
  261. * @dev_pw: Device Password (PIN) used during registration
  262. * @dev_pw_len: Length of dev_pw in octets
  263. *
  264. * This callback is called whenever an Enrollee completes registration
  265. * successfully.
  266. */
  267. void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
  268. const u8 *uuid_e, const u8 *dev_pw,
  269. size_t dev_pw_len);
  270. /**
  271. * set_sel_reg_cb - Callback for reporting selected registrar changes
  272. * @ctx: Higher layer context data (cb_ctx)
  273. * @sel_reg: Whether the Registrar is selected
  274. * @dev_passwd_id: Device Password ID to indicate with method or
  275. * specific password the Registrar intends to use
  276. * @sel_reg_config_methods: Bit field of active config methods
  277. *
  278. * This callback is called whenever the Selected Registrar state
  279. * changes (e.g., a new PIN becomes available or PBC is invoked). This
  280. * callback is only used by External Registrar implementation;
  281. * set_ie_cb() is used by AP implementation in similar caes, but it
  282. * provides the full WPS IE data instead of just the minimal Registrar
  283. * state information.
  284. */
  285. void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
  286. u16 sel_reg_config_methods);
  287. /**
  288. * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
  289. * @ctx: Higher layer context data (cb_ctx)
  290. * @addr: MAC address of the Enrollee
  291. * @uuid_e: UUID of the Enrollee
  292. * @pri_dev_type: Primary device type
  293. * @config_methods: Config Methods
  294. * @dev_password_id: Device Password ID
  295. * @request_type: Request Type
  296. * @dev_name: Device Name (if available)
  297. */
  298. void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
  299. const u8 *pri_dev_type, u16 config_methods,
  300. u16 dev_password_id, u8 request_type,
  301. const char *dev_name);
  302. /**
  303. * cb_ctx: Higher layer context data for Registrar callbacks
  304. */
  305. void *cb_ctx;
  306. /**
  307. * skip_cred_build: Do not build credential
  308. *
  309. * This option can be used to disable internal code that builds
  310. * Credential attribute into M8 based on the current network
  311. * configuration and Enrollee capabilities. The extra_cred data will
  312. * then be used as the Credential(s).
  313. */
  314. int skip_cred_build;
  315. /**
  316. * extra_cred: Additional Credential attribute(s)
  317. *
  318. * This optional data (set to %NULL to disable) can be used to add
  319. * Credential attribute(s) for other networks into M8. If
  320. * skip_cred_build is set, this will also override the automatically
  321. * generated Credential attribute.
  322. */
  323. const u8 *extra_cred;
  324. /**
  325. * extra_cred_len: Length of extra_cred in octets
  326. */
  327. size_t extra_cred_len;
  328. /**
  329. * disable_auto_conf - Disable auto-configuration on first registration
  330. *
  331. * By default, the AP that is started in not configured state will
  332. * generate a random PSK and move to configured state when the first
  333. * registration protocol run is completed successfully. This option can
  334. * be used to disable this functionality and leave it up to an external
  335. * program to take care of configuration. This requires the extra_cred
  336. * to be set with a suitable Credential and skip_cred_build being used.
  337. */
  338. int disable_auto_conf;
  339. /**
  340. * static_wep_only - Whether the BSS supports only static WEP
  341. */
  342. int static_wep_only;
  343. /**
  344. * dualband - Whether this is a concurrent dualband AP
  345. */
  346. int dualband;
  347. /**
  348. * force_per_enrollee_psk - Force per-Enrollee random PSK
  349. *
  350. * This forces per-Enrollee random PSK to be generated even if a default
  351. * PSK is set for a network.
  352. */
  353. int force_per_enrollee_psk;
  354. };
  355. /**
  356. * enum wps_event - WPS event types
  357. */
  358. enum wps_event {
  359. /**
  360. * WPS_EV_M2D - M2D received (Registrar did not know us)
  361. */
  362. WPS_EV_M2D,
  363. /**
  364. * WPS_EV_FAIL - Registration failed
  365. */
  366. WPS_EV_FAIL,
  367. /**
  368. * WPS_EV_SUCCESS - Registration succeeded
  369. */
  370. WPS_EV_SUCCESS,
  371. /**
  372. * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
  373. */
  374. WPS_EV_PWD_AUTH_FAIL,
  375. /**
  376. * WPS_EV_PBC_OVERLAP - PBC session overlap detected
  377. */
  378. WPS_EV_PBC_OVERLAP,
  379. /**
  380. * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
  381. */
  382. WPS_EV_PBC_TIMEOUT,
  383. /**
  384. * WPS_EV_PBC_ACTIVE - PBC mode was activated
  385. */
  386. WPS_EV_PBC_ACTIVE,
  387. /**
  388. * WPS_EV_PBC_DISABLE - PBC mode was disabled
  389. */
  390. WPS_EV_PBC_DISABLE,
  391. /**
  392. * WPS_EV_ER_AP_ADD - ER: AP added
  393. */
  394. WPS_EV_ER_AP_ADD,
  395. /**
  396. * WPS_EV_ER_AP_REMOVE - ER: AP removed
  397. */
  398. WPS_EV_ER_AP_REMOVE,
  399. /**
  400. * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
  401. */
  402. WPS_EV_ER_ENROLLEE_ADD,
  403. /**
  404. * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
  405. */
  406. WPS_EV_ER_ENROLLEE_REMOVE,
  407. /**
  408. * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned
  409. */
  410. WPS_EV_ER_AP_SETTINGS,
  411. /**
  412. * WPS_EV_ER_SET_SELECTED_REGISTRAR - ER: SetSelectedRegistrar event
  413. */
  414. WPS_EV_ER_SET_SELECTED_REGISTRAR,
  415. /**
  416. * WPS_EV_AP_PIN_SUCCESS - External Registrar used correct AP PIN
  417. */
  418. WPS_EV_AP_PIN_SUCCESS
  419. };
  420. /**
  421. * union wps_event_data - WPS event data
  422. */
  423. union wps_event_data {
  424. /**
  425. * struct wps_event_m2d - M2D event data
  426. */
  427. struct wps_event_m2d {
  428. u16 config_methods;
  429. const u8 *manufacturer;
  430. size_t manufacturer_len;
  431. const u8 *model_name;
  432. size_t model_name_len;
  433. const u8 *model_number;
  434. size_t model_number_len;
  435. const u8 *serial_number;
  436. size_t serial_number_len;
  437. const u8 *dev_name;
  438. size_t dev_name_len;
  439. const u8 *primary_dev_type; /* 8 octets */
  440. u16 config_error;
  441. u16 dev_password_id;
  442. } m2d;
  443. /**
  444. * struct wps_event_fail - Registration failure information
  445. * @msg: enum wps_msg_type
  446. */
  447. struct wps_event_fail {
  448. int msg;
  449. u16 config_error;
  450. u16 error_indication;
  451. u8 peer_macaddr[ETH_ALEN];
  452. } fail;
  453. struct wps_event_success {
  454. u8 peer_macaddr[ETH_ALEN];
  455. } success;
  456. struct wps_event_pwd_auth_fail {
  457. int enrollee;
  458. int part;
  459. u8 peer_macaddr[ETH_ALEN];
  460. } pwd_auth_fail;
  461. struct wps_event_er_ap {
  462. const u8 *uuid;
  463. const u8 *mac_addr;
  464. const char *friendly_name;
  465. const char *manufacturer;
  466. const char *manufacturer_url;
  467. const char *model_description;
  468. const char *model_name;
  469. const char *model_number;
  470. const char *model_url;
  471. const char *serial_number;
  472. const char *upc;
  473. const u8 *pri_dev_type;
  474. u8 wps_state;
  475. } ap;
  476. struct wps_event_er_enrollee {
  477. const u8 *uuid;
  478. const u8 *mac_addr;
  479. int m1_received;
  480. u16 config_methods;
  481. u16 dev_passwd_id;
  482. const u8 *pri_dev_type;
  483. const char *dev_name;
  484. const char *manufacturer;
  485. const char *model_name;
  486. const char *model_number;
  487. const char *serial_number;
  488. } enrollee;
  489. struct wps_event_er_ap_settings {
  490. const u8 *uuid;
  491. const struct wps_credential *cred;
  492. } ap_settings;
  493. struct wps_event_er_set_selected_registrar {
  494. const u8 *uuid;
  495. int sel_reg;
  496. u16 dev_passwd_id;
  497. u16 sel_reg_config_methods;
  498. enum {
  499. WPS_ER_SET_SEL_REG_START,
  500. WPS_ER_SET_SEL_REG_DONE,
  501. WPS_ER_SET_SEL_REG_FAILED
  502. } state;
  503. } set_sel_reg;
  504. };
  505. /**
  506. * struct upnp_pending_message - Pending PutWLANResponse messages
  507. * @next: Pointer to next pending message or %NULL
  508. * @addr: NewWLANEventMAC
  509. * @msg: NewMessage
  510. * @type: Message Type
  511. */
  512. struct upnp_pending_message {
  513. struct upnp_pending_message *next;
  514. u8 addr[ETH_ALEN];
  515. struct wpabuf *msg;
  516. enum wps_msg_type type;
  517. };
  518. /**
  519. * struct wps_context - Long term WPS context data
  520. *
  521. * This data is stored at the higher layer Authenticator or Supplicant data
  522. * structures and it is maintained over multiple registration protocol runs.
  523. */
  524. struct wps_context {
  525. /**
  526. * ap - Whether the local end is an access point
  527. */
  528. int ap;
  529. /**
  530. * registrar - Pointer to WPS registrar data from wps_registrar_init()
  531. */
  532. struct wps_registrar *registrar;
  533. /**
  534. * wps_state - Current WPS state
  535. */
  536. enum wps_state wps_state;
  537. /**
  538. * ap_setup_locked - Whether AP setup is locked (only used at AP)
  539. */
  540. int ap_setup_locked;
  541. /**
  542. * uuid - Own UUID
  543. */
  544. u8 uuid[16];
  545. /**
  546. * ssid - SSID
  547. *
  548. * This SSID is used by the Registrar to fill in information for
  549. * Credentials. In addition, AP uses it when acting as an Enrollee to
  550. * notify Registrar of the current configuration.
  551. */
  552. u8 ssid[32];
  553. /**
  554. * ssid_len - Length of ssid in octets
  555. */
  556. size_t ssid_len;
  557. /**
  558. * dev - Own WPS device data
  559. */
  560. struct wps_device_data dev;
  561. /**
  562. * dh_ctx - Context data for Diffie-Hellman operation
  563. */
  564. void *dh_ctx;
  565. /**
  566. * dh_privkey - Diffie-Hellman private key
  567. */
  568. struct wpabuf *dh_privkey;
  569. /**
  570. * dh_pubkey_oob - Diffie-Hellman public key
  571. */
  572. struct wpabuf *dh_pubkey;
  573. /**
  574. * config_methods - Enabled configuration methods
  575. *
  576. * Bit field of WPS_CONFIG_*
  577. */
  578. u16 config_methods;
  579. /**
  580. * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
  581. */
  582. u16 encr_types;
  583. /**
  584. * auth_types - Authentication types (bit field of WPS_AUTH_*)
  585. */
  586. u16 auth_types;
  587. /**
  588. * network_key - The current Network Key (PSK) or %NULL to generate new
  589. *
  590. * If %NULL, Registrar will generate per-device PSK. In addition, AP
  591. * uses this when acting as an Enrollee to notify Registrar of the
  592. * current configuration.
  593. *
  594. * When using WPA/WPA2-Person, this key can be either the ASCII
  595. * passphrase (8..63 characters) or the 32-octet PSK (64 hex
  596. * characters). When this is set to the ASCII passphrase, the PSK can
  597. * be provided in the psk buffer and used per-Enrollee to control which
  598. * key type is included in the Credential (e.g., to reduce calculation
  599. * need on low-powered devices by provisioning PSK while still allowing
  600. * other devices to get the passphrase).
  601. */
  602. u8 *network_key;
  603. /**
  604. * network_key_len - Length of network_key in octets
  605. */
  606. size_t network_key_len;
  607. /**
  608. * psk - The current network PSK
  609. *
  610. * This optional value can be used to provide the current PSK if
  611. * network_key is set to the ASCII passphrase.
  612. */
  613. u8 psk[32];
  614. /**
  615. * psk_set - Whether psk value is set
  616. */
  617. int psk_set;
  618. /**
  619. * ap_settings - AP Settings override for M7 (only used at AP)
  620. *
  621. * If %NULL, AP Settings attributes will be generated based on the
  622. * current network configuration.
  623. */
  624. u8 *ap_settings;
  625. /**
  626. * ap_settings_len - Length of ap_settings in octets
  627. */
  628. size_t ap_settings_len;
  629. /**
  630. * friendly_name - Friendly Name (required for UPnP)
  631. */
  632. char *friendly_name;
  633. /**
  634. * manufacturer_url - Manufacturer URL (optional for UPnP)
  635. */
  636. char *manufacturer_url;
  637. /**
  638. * model_description - Model Description (recommended for UPnP)
  639. */
  640. char *model_description;
  641. /**
  642. * model_url - Model URL (optional for UPnP)
  643. */
  644. char *model_url;
  645. /**
  646. * upc - Universal Product Code (optional for UPnP)
  647. */
  648. char *upc;
  649. /**
  650. * cred_cb - Callback to notify that new Credentials were received
  651. * @ctx: Higher layer context data (cb_ctx)
  652. * @cred: The received Credential
  653. * Return: 0 on success, -1 on failure
  654. */
  655. int (*cred_cb)(void *ctx, const struct wps_credential *cred);
  656. /**
  657. * event_cb - Event callback (state information about progress)
  658. * @ctx: Higher layer context data (cb_ctx)
  659. * @event: Event type
  660. * @data: Event data
  661. */
  662. void (*event_cb)(void *ctx, enum wps_event event,
  663. union wps_event_data *data);
  664. /**
  665. * rf_band_cb - Fetch currently used RF band
  666. * @ctx: Higher layer context data (cb_ctx)
  667. * Return: Current used RF band or 0 if not known
  668. */
  669. int (*rf_band_cb)(void *ctx);
  670. /**
  671. * cb_ctx: Higher layer context data for callbacks
  672. */
  673. void *cb_ctx;
  674. struct upnp_wps_device_sm *wps_upnp;
  675. /* Pending messages from UPnP PutWLANResponse */
  676. struct upnp_pending_message *upnp_msgs;
  677. u16 ap_nfc_dev_pw_id;
  678. struct wpabuf *ap_nfc_dh_pubkey;
  679. struct wpabuf *ap_nfc_dh_privkey;
  680. struct wpabuf *ap_nfc_dev_pw;
  681. };
  682. struct wps_registrar *
  683. wps_registrar_init(struct wps_context *wps,
  684. const struct wps_registrar_config *cfg);
  685. void wps_registrar_deinit(struct wps_registrar *reg);
  686. int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
  687. const u8 *uuid, const u8 *pin, size_t pin_len,
  688. int timeout);
  689. int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
  690. int wps_registrar_wps_cancel(struct wps_registrar *reg);
  691. int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
  692. int wps_registrar_button_pushed(struct wps_registrar *reg,
  693. const u8 *p2p_dev_addr);
  694. void wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e,
  695. const u8 *dev_pw, size_t dev_pw_len);
  696. void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
  697. const struct wpabuf *wps_data,
  698. int p2p_wildcard);
  699. int wps_registrar_update_ie(struct wps_registrar *reg);
  700. int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
  701. char *buf, size_t buflen);
  702. int wps_registrar_config_ap(struct wps_registrar *reg,
  703. struct wps_credential *cred);
  704. int wps_registrar_add_nfc_pw_token(struct wps_registrar *reg,
  705. const u8 *pubkey_hash, u16 pw_id,
  706. const u8 *dev_pw, size_t dev_pw_len,
  707. int pk_hash_provided_oob);
  708. int wps_registrar_add_nfc_password_token(struct wps_registrar *reg,
  709. const u8 *oob_dev_pw,
  710. size_t oob_dev_pw_len);
  711. int wps_build_credential_wrap(struct wpabuf *msg,
  712. const struct wps_credential *cred);
  713. unsigned int wps_pin_checksum(unsigned int pin);
  714. unsigned int wps_pin_valid(unsigned int pin);
  715. unsigned int wps_generate_pin(void);
  716. int wps_pin_str_valid(const char *pin);
  717. void wps_free_pending_msgs(struct upnp_pending_message *msgs);
  718. struct wpabuf * wps_get_oob_cred(struct wps_context *wps);
  719. int wps_oob_use_cred(struct wps_context *wps, struct wps_parse_attr *attr);
  720. int wps_attr_text(struct wpabuf *data, char *buf, char *end);
  721. const char * wps_ei_str(enum wps_error_indication ei);
  722. struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
  723. const char *filter);
  724. void wps_er_refresh(struct wps_er *er);
  725. void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
  726. void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
  727. u16 sel_reg_config_methods);
  728. int wps_er_pbc(struct wps_er *er, const u8 *uuid, const u8 *addr);
  729. const u8 * wps_er_get_sta_uuid(struct wps_er *er, const u8 *addr);
  730. int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *addr,
  731. const u8 *pin, size_t pin_len);
  732. int wps_er_set_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
  733. const struct wps_credential *cred);
  734. int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
  735. const u8 *pin, size_t pin_len,
  736. const struct wps_credential *cred);
  737. struct wpabuf * wps_er_config_token_from_cred(struct wps_context *wps,
  738. struct wps_credential *cred);
  739. struct wpabuf * wps_er_nfc_config_token(struct wps_er *er, const u8 *uuid,
  740. const u8 *addr);
  741. int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
  742. char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
  743. size_t buf_len);
  744. void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
  745. u16 wps_config_methods_str2bin(const char *str);
  746. struct wpabuf * wps_build_nfc_pw_token(u16 dev_pw_id,
  747. const struct wpabuf *pubkey,
  748. const struct wpabuf *dev_pw);
  749. struct wpabuf * wps_nfc_token_build(int ndef, int id, struct wpabuf *pubkey,
  750. struct wpabuf *dev_pw);
  751. int wps_nfc_gen_dh(struct wpabuf **pubkey, struct wpabuf **privkey);
  752. struct wpabuf * wps_nfc_token_gen(int ndef, int *id, struct wpabuf **pubkey,
  753. struct wpabuf **privkey,
  754. struct wpabuf **dev_pw);
  755. struct wpabuf * wps_build_nfc_handover_req(struct wps_context *ctx,
  756. struct wpabuf *nfc_dh_pubkey);
  757. struct wpabuf * wps_build_nfc_handover_sel(struct wps_context *ctx,
  758. struct wpabuf *nfc_dh_pubkey);
  759. /* ndef.c */
  760. struct wpabuf * ndef_parse_wifi(const struct wpabuf *buf);
  761. struct wpabuf * ndef_build_wifi(const struct wpabuf *buf);
  762. struct wpabuf * ndef_build_wifi_hc(int begin);
  763. struct wpabuf * ndef_build_wifi_hr(void);
  764. #ifdef CONFIG_WPS_STRICT
  765. int wps_validate_beacon(const struct wpabuf *wps_ie);
  766. int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe,
  767. const u8 *addr);
  768. int wps_validate_probe_req(const struct wpabuf *wps_ie, const u8 *addr);
  769. int wps_validate_assoc_req(const struct wpabuf *wps_ie);
  770. int wps_validate_assoc_resp(const struct wpabuf *wps_ie);
  771. int wps_validate_m1(const struct wpabuf *tlvs);
  772. int wps_validate_m2(const struct wpabuf *tlvs);
  773. int wps_validate_m2d(const struct wpabuf *tlvs);
  774. int wps_validate_m3(const struct wpabuf *tlvs);
  775. int wps_validate_m4(const struct wpabuf *tlvs);
  776. int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2);
  777. int wps_validate_m5(const struct wpabuf *tlvs);
  778. int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2);
  779. int wps_validate_m6(const struct wpabuf *tlvs);
  780. int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2);
  781. int wps_validate_m7(const struct wpabuf *tlvs);
  782. int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, int wps2);
  783. int wps_validate_m8(const struct wpabuf *tlvs);
  784. int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, int wps2);
  785. int wps_validate_wsc_ack(const struct wpabuf *tlvs);
  786. int wps_validate_wsc_nack(const struct wpabuf *tlvs);
  787. int wps_validate_wsc_done(const struct wpabuf *tlvs);
  788. int wps_validate_upnp_set_selected_registrar(const struct wpabuf *tlvs);
  789. #else /* CONFIG_WPS_STRICT */
  790. static inline int wps_validate_beacon(const struct wpabuf *wps_ie){
  791. return 0;
  792. }
  793. static inline int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie,
  794. int probe, const u8 *addr)
  795. {
  796. return 0;
  797. }
  798. static inline int wps_validate_probe_req(const struct wpabuf *wps_ie,
  799. const u8 *addr)
  800. {
  801. return 0;
  802. }
  803. static inline int wps_validate_assoc_req(const struct wpabuf *wps_ie)
  804. {
  805. return 0;
  806. }
  807. static inline int wps_validate_assoc_resp(const struct wpabuf *wps_ie)
  808. {
  809. return 0;
  810. }
  811. static inline int wps_validate_m1(const struct wpabuf *tlvs)
  812. {
  813. return 0;
  814. }
  815. static inline int wps_validate_m2(const struct wpabuf *tlvs)
  816. {
  817. return 0;
  818. }
  819. static inline int wps_validate_m2d(const struct wpabuf *tlvs)
  820. {
  821. return 0;
  822. }
  823. static inline int wps_validate_m3(const struct wpabuf *tlvs)
  824. {
  825. return 0;
  826. }
  827. static inline int wps_validate_m4(const struct wpabuf *tlvs)
  828. {
  829. return 0;
  830. }
  831. static inline int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2)
  832. {
  833. return 0;
  834. }
  835. static inline int wps_validate_m5(const struct wpabuf *tlvs)
  836. {
  837. return 0;
  838. }
  839. static inline int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2)
  840. {
  841. return 0;
  842. }
  843. static inline int wps_validate_m6(const struct wpabuf *tlvs)
  844. {
  845. return 0;
  846. }
  847. static inline int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2)
  848. {
  849. return 0;
  850. }
  851. static inline int wps_validate_m7(const struct wpabuf *tlvs)
  852. {
  853. return 0;
  854. }
  855. static inline int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap,
  856. int wps2)
  857. {
  858. return 0;
  859. }
  860. static inline int wps_validate_m8(const struct wpabuf *tlvs)
  861. {
  862. return 0;
  863. }
  864. static inline int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap,
  865. int wps2)
  866. {
  867. return 0;
  868. }
  869. static inline int wps_validate_wsc_ack(const struct wpabuf *tlvs)
  870. {
  871. return 0;
  872. }
  873. static inline int wps_validate_wsc_nack(const struct wpabuf *tlvs)
  874. {
  875. return 0;
  876. }
  877. static inline int wps_validate_wsc_done(const struct wpabuf *tlvs)
  878. {
  879. return 0;
  880. }
  881. static inline int wps_validate_upnp_set_selected_registrar(
  882. const struct wpabuf *tlvs)
  883. {
  884. return 0;
  885. }
  886. #endif /* CONFIG_WPS_STRICT */
  887. #endif /* WPS_H */