wps.h 27 KB

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