wps.h 25 KB

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