wps.h 25 KB

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