wps.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * Wi-Fi Protected Setup
  3. * Copyright (c) 2007-2008, 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_Start = 0x01,
  22. WSC_ACK = 0x02,
  23. WSC_NACK = 0x03,
  24. WSC_MSG = 0x04,
  25. WSC_Done = 0x05,
  26. WSC_FRAG_ACK = 0x06
  27. };
  28. struct wps_registrar;
  29. /**
  30. * struct wps_credential - WPS Credential
  31. * @ssid: SSID
  32. * @ssid_len: Length of SSID
  33. * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
  34. * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
  35. * @key_idx: Key index
  36. * @key: Key
  37. * @key_len: Key length in octets
  38. * @mac_addr: MAC address of the peer
  39. */
  40. struct wps_credential {
  41. u8 ssid[32];
  42. size_t ssid_len;
  43. u16 auth_type;
  44. u16 encr_type;
  45. u8 key_idx;
  46. u8 key[64];
  47. size_t key_len;
  48. u8 mac_addr[ETH_ALEN];
  49. };
  50. /**
  51. * struct wps_device_data - WPS Device Data
  52. * @mac_addr: Device MAC address
  53. * @device_name: Device Name (0..32 octets encoded in UTF-8)
  54. * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
  55. * @model_name: Model Name (0..32 octets encoded in UTF-8)
  56. * @model_number: Model Number (0..32 octets encoded in UTF-8)
  57. * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
  58. * @categ: Primary Device Category
  59. * @oui: Primary Device OUI
  60. * @sub_categ: Primary Device Sub-Category
  61. * @os_version: OS Version
  62. * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
  63. */
  64. struct wps_device_data {
  65. u8 mac_addr[ETH_ALEN];
  66. char *device_name;
  67. char *manufacturer;
  68. char *model_name;
  69. char *model_number;
  70. char *serial_number;
  71. u16 categ;
  72. u32 oui;
  73. u16 sub_categ;
  74. u32 os_version;
  75. u8 rf_bands;
  76. };
  77. /**
  78. * struct wps_config - WPS configuration for a single registration protocol run
  79. */
  80. struct wps_config {
  81. /**
  82. * wps - Pointer to long term WPS context
  83. */
  84. struct wps_context *wps;
  85. /**
  86. * registrar - Whether this end is a Registrar
  87. */
  88. int registrar;
  89. /**
  90. * pin - Enrollee Device Password (%NULL for Registrar or PBC)
  91. */
  92. const u8 *pin;
  93. /**
  94. * pin_len - Length on pin in octets
  95. */
  96. size_t pin_len;
  97. /**
  98. * pbc - Whether this is protocol run uses PBC
  99. */
  100. int pbc;
  101. /**
  102. * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
  103. */
  104. const struct wpabuf *assoc_wps_ie;
  105. };
  106. struct wps_data * wps_init(const struct wps_config *cfg);
  107. void wps_deinit(struct wps_data *data);
  108. /**
  109. * enum wps_process_res - WPS message processing result
  110. */
  111. enum wps_process_res {
  112. /**
  113. * WPS_DONE - Processing done
  114. */
  115. WPS_DONE,
  116. /**
  117. * WPS_CONTINUE - Processing continues
  118. */
  119. WPS_CONTINUE,
  120. /**
  121. * WPS_FAILURE - Processing failed
  122. */
  123. WPS_FAILURE
  124. };
  125. enum wps_process_res wps_process_msg(struct wps_data *wps,
  126. enum wsc_op_code op_code,
  127. const struct wpabuf *msg);
  128. struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
  129. int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
  130. int wps_is_selected_pin_registrar(const struct wpabuf *msg);
  131. const u8 * wps_get_uuid_e(const struct wpabuf *msg);
  132. struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
  133. struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
  134. const u8 *uuid,
  135. enum wps_request_type req_type);
  136. /**
  137. * struct wps_registrar_config - WPS Registrar configuration
  138. */
  139. struct wps_registrar_config {
  140. /**
  141. * new_psk_cb - Callback for new PSK
  142. * @ctx: Higher layer context data (cb_ctx)
  143. * @mac_addr: MAC address of the Enrollee
  144. * @psk: The new PSK
  145. * @psk_len: The length of psk in octets
  146. * Returns: 0 on success, -1 on failure
  147. *
  148. * This callback is called when a new per-device PSK is provisioned.
  149. */
  150. int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
  151. size_t psk_len);
  152. /**
  153. * set_ie_cb - Callback for WPS IE changes
  154. * @ctx: Higher layer context data (cb_ctx)
  155. * @beacon_ie: WPS IE for Beacon
  156. * @beacon_ie_len: WPS IE length for Beacon
  157. * @probe_resp_ie: WPS IE for Probe Response
  158. * @probe_resp_ie_len: WPS IE length for Probe Response
  159. * Returns: 0 on success, -1 on failure
  160. *
  161. * This callback is called whenever the WPS IE in Beacon or Probe
  162. * Response frames needs to be changed (AP only).
  163. */
  164. int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
  165. const u8 *probe_resp_ie, size_t probe_resp_ie_len);
  166. /**
  167. * pin_needed_cb - Callback for requesting a PIN
  168. * @ctx: Higher layer context data (cb_ctx)
  169. * @uuid_e: UUID-E of the unknown Enrollee
  170. * @dev: Device Data from the unknown Enrollee
  171. *
  172. * This callback is called whenever an unknown Enrollee requests to use
  173. * PIN method and a matching PIN (Device Password) is not found in
  174. * Registrar data.
  175. */
  176. void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
  177. const struct wps_device_data *dev);
  178. /**
  179. * cb_ctx: Higher layer context data for Registrar callbacks
  180. */
  181. void *cb_ctx;
  182. };
  183. /**
  184. * enum wps_event - WPS event types
  185. */
  186. enum wps_event {
  187. /**
  188. * WPS_EV_M2D - M2D received (Registrar did not know us)
  189. */
  190. WPS_EV_M2D,
  191. /**
  192. * WPS_EV_FAIL - Registration failed
  193. */
  194. WPS_EV_FAIL,
  195. /**
  196. * WPS_EV_SUCCESS - Registration succeeded
  197. */
  198. WPS_EV_SUCCESS
  199. };
  200. /**
  201. * union wps_event_data - WPS event data
  202. */
  203. union wps_event_data {
  204. /**
  205. * struct wps_event_m2d - M2D event data
  206. */
  207. struct wps_event_m2d {
  208. u16 config_methods;
  209. const u8 *manufacturer;
  210. size_t manufacturer_len;
  211. const u8 *model_name;
  212. size_t model_name_len;
  213. const u8 *model_number;
  214. size_t model_number_len;
  215. const u8 *serial_number;
  216. size_t serial_number_len;
  217. const u8 *dev_name;
  218. size_t dev_name_len;
  219. const u8 *primary_dev_type; /* 8 octets */
  220. u16 config_error;
  221. u16 dev_password_id;
  222. } m2d;
  223. /**
  224. * struct wps_event_fail - Registration failure information
  225. * @msg: enum wps_msg_type
  226. */
  227. struct wps_event_fail {
  228. int msg;
  229. } fail;
  230. };
  231. /**
  232. * struct wps_context - Long term WPS context data
  233. *
  234. * This data is stored at the higher layer Authenticator or Supplicant data
  235. * structures and it is maintained over multiple registration protocol runs.
  236. */
  237. struct wps_context {
  238. /**
  239. * ap - Whether the local end is an access point
  240. */
  241. int ap;
  242. /**
  243. * registrar - Pointer to WPS registrar data from wps_registrar_init()
  244. */
  245. struct wps_registrar *registrar;
  246. /**
  247. * wps_state - Current WPS state
  248. */
  249. enum wps_state wps_state;
  250. /**
  251. * ap_setup_locked - Whether AP setup is locked (only used at AP)
  252. */
  253. int ap_setup_locked;
  254. /**
  255. * uuid - Own UUID
  256. */
  257. u8 uuid[16];
  258. /**
  259. * ssid - SSID
  260. *
  261. * This SSID is used by the Registrar to fill in information for
  262. * Credentials. In addition, AP uses it when acting as an Enrollee to
  263. * notify Registrar of the current configuration.
  264. */
  265. u8 ssid[32];
  266. /**
  267. * ssid_len - Length of ssid in octets
  268. */
  269. size_t ssid_len;
  270. /**
  271. * dev - Own WPS device data
  272. */
  273. struct wps_device_data dev;
  274. /**
  275. * config_methods - Enabled configuration methods
  276. *
  277. * Bit field of WPS_CONFIG_*
  278. */
  279. u16 config_methods;
  280. /**
  281. * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
  282. */
  283. u16 encr_types;
  284. /**
  285. * auth_types - Authentication types (bit field of WPS_AUTH_*)
  286. */
  287. u16 auth_types;
  288. /**
  289. * network_key - The current Network Key (PSK) or %NULL to generate new
  290. *
  291. * If %NULL, Registrar will generate per-device PSK. In addition, AP
  292. * uses this when acting as an Enrollee to notify Registrar of the
  293. * current configuration.
  294. */
  295. u8 *network_key;
  296. /**
  297. * network_key_len - Length of network_key in octets
  298. */
  299. size_t network_key_len;
  300. /**
  301. * cred_cb - Callback to notify that new Credentials were received
  302. * @ctx: Higher layer context data (cb_ctx)
  303. * @cred: The received Credential
  304. * Return: 0 on success, -1 on failure
  305. */
  306. int (*cred_cb)(void *ctx, const struct wps_credential *cred);
  307. /**
  308. * event_cb - Event callback (state information about progress)
  309. * @ctx: Higher layer context data (cb_ctx)
  310. * @event: Event type
  311. * @data: Event data
  312. */
  313. void (*event_cb)(void *ctx, enum wps_event event,
  314. union wps_event_data *data);
  315. /**
  316. * cb_ctx: Higher layer context data for callbacks
  317. */
  318. void *cb_ctx;
  319. };
  320. struct wps_registrar *
  321. wps_registrar_init(struct wps_context *wps,
  322. const struct wps_registrar_config *cfg);
  323. void wps_registrar_deinit(struct wps_registrar *reg);
  324. int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
  325. const u8 *pin, size_t pin_len);
  326. int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
  327. int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
  328. int wps_registrar_button_pushed(struct wps_registrar *reg);
  329. void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
  330. const struct wpabuf *wps_data);
  331. unsigned int wps_pin_checksum(unsigned int pin);
  332. unsigned int wps_pin_valid(unsigned int pin);
  333. unsigned int wps_generate_pin(void);
  334. #endif /* WPS_H */