wps_er.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * Wi-Fi Protected Setup - External Registrar
  3. * Copyright (c) 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. #include "includes.h"
  15. #include "common.h"
  16. #include "uuid.h"
  17. #include "eloop.h"
  18. #include "httpread.h"
  19. #include "http_client.h"
  20. #include "http_server.h"
  21. #include "upnp_xml.h"
  22. #include "wps_i.h"
  23. #include "wps_upnp.h"
  24. #include "wps_upnp_i.h"
  25. /* TODO:
  26. * send notification of new AP device with wpa_msg
  27. * re-send notifications with wpa_msg if ER re-started (to update wpa_gui-qt4)
  28. * (also re-send SSDP M-SEARCH in this case to find new APs)
  29. * parse UPnP event messages
  30. */
  31. static void wps_er_ap_timeout(void *eloop_data, void *user_ctx);
  32. struct wps_er_ap {
  33. struct wps_er_ap *next;
  34. struct wps_er *er;
  35. struct in_addr addr;
  36. char *location;
  37. struct http_client *http;
  38. char *friendly_name;
  39. char *manufacturer;
  40. char *manufacturer_url;
  41. char *model_description;
  42. char *model_name;
  43. char *model_number;
  44. char *model_url;
  45. char *serial_number;
  46. char *udn;
  47. char *upc;
  48. char *scpd_url;
  49. char *control_url;
  50. char *event_sub_url;
  51. int subscribed;
  52. unsigned int id;
  53. };
  54. struct wps_er {
  55. struct wps_registrar *reg;
  56. char ifname[17];
  57. char *mac_addr_text; /* mac addr of network i.f. we use */
  58. u8 mac_addr[ETH_ALEN]; /* mac addr of network i.f. we use */
  59. char *ip_addr_text; /* IP address of network i.f. we use */
  60. unsigned ip_addr; /* IP address of network i.f. we use (host order) */
  61. int multicast_sd;
  62. int ssdp_sd;
  63. struct wps_er_ap *ap;
  64. struct http_server *http_srv;
  65. int http_port;
  66. unsigned int next_ap_id;
  67. };
  68. static void wps_er_pin_needed_cb(void *ctx, const u8 *uuid_e,
  69. const struct wps_device_data *dev)
  70. {
  71. wpa_printf(MSG_DEBUG, "WPS ER: PIN needed");
  72. }
  73. static struct wps_er_ap * wps_er_ap_get(struct wps_er *er,
  74. struct in_addr *addr)
  75. {
  76. struct wps_er_ap *ap;
  77. for (ap = er->ap; ap; ap = ap->next) {
  78. if (ap->addr.s_addr == addr->s_addr)
  79. break;
  80. }
  81. return ap;
  82. }
  83. static struct wps_er_ap * wps_er_ap_get_id(struct wps_er *er, unsigned int id)
  84. {
  85. struct wps_er_ap *ap;
  86. for (ap = er->ap; ap; ap = ap->next) {
  87. if (ap->id == id)
  88. break;
  89. }
  90. return ap;
  91. }
  92. static void wps_er_ap_free(struct wps_er *er, struct wps_er_ap *ap)
  93. {
  94. /* TODO: if ap->subscribed, unsubscribe from events if the AP is still
  95. * alive */
  96. wpa_printf(MSG_DEBUG, "WPS ER: Removing AP entry for %s (%s)",
  97. inet_ntoa(ap->addr), ap->location);
  98. eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
  99. os_free(ap->location);
  100. http_client_free(ap->http);
  101. os_free(ap->friendly_name);
  102. os_free(ap->manufacturer);
  103. os_free(ap->manufacturer_url);
  104. os_free(ap->model_description);
  105. os_free(ap->model_name);
  106. os_free(ap->model_number);
  107. os_free(ap->model_url);
  108. os_free(ap->serial_number);
  109. os_free(ap->udn);
  110. os_free(ap->upc);
  111. os_free(ap->scpd_url);
  112. os_free(ap->control_url);
  113. os_free(ap->event_sub_url);
  114. os_free(ap);
  115. }
  116. static void wps_er_ap_timeout(void *eloop_data, void *user_ctx)
  117. {
  118. struct wps_er *er = eloop_data;
  119. struct wps_er_ap *ap = user_ctx;
  120. wpa_printf(MSG_DEBUG, "WPS ER: AP advertisement timed out");
  121. wps_er_ap_free(er, ap);
  122. }
  123. static void wps_er_http_subscribe_cb(void *ctx, struct http_client *c,
  124. enum http_client_event event)
  125. {
  126. struct wps_er_ap *ap = ctx;
  127. switch (event) {
  128. case HTTP_CLIENT_OK:
  129. wpa_printf(MSG_DEBUG, "WPS ER: Subscribed to events");
  130. break;
  131. case HTTP_CLIENT_FAILED:
  132. case HTTP_CLIENT_INVALID_REPLY:
  133. case HTTP_CLIENT_TIMEOUT:
  134. wpa_printf(MSG_DEBUG, "WPS ER: Failed to subscribe to events");
  135. break;
  136. }
  137. http_client_free(ap->http);
  138. ap->http = NULL;
  139. }
  140. static void wps_er_subscribe(struct wps_er_ap *ap)
  141. {
  142. struct wpabuf *req;
  143. struct sockaddr_in dst;
  144. char *url, *path;
  145. if (ap->event_sub_url == NULL) {
  146. wpa_printf(MSG_DEBUG, "WPS ER: No eventSubURL - cannot "
  147. "subscribe");
  148. return;
  149. }
  150. if (ap->http) {
  151. wpa_printf(MSG_DEBUG, "WPS ER: Pending HTTP request - cannot "
  152. "send subscribe request");
  153. return;
  154. }
  155. url = http_client_url_parse(ap->event_sub_url, &dst, &path);
  156. if (url == NULL) {
  157. wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse eventSubURL");
  158. return;
  159. }
  160. req = wpabuf_alloc(os_strlen(ap->event_sub_url) + 1000);
  161. if (req == NULL) {
  162. os_free(url);
  163. return;
  164. }
  165. wpabuf_printf(req,
  166. "SUBSCRIBE %s HTTP/1.1\r\n"
  167. "HOST: %s:%d\r\n"
  168. "CALLBACK: <http://%s:%d/event/%d>\r\n"
  169. "NT: upnp:event\r\n"
  170. "TIMEOUT: Second-%d\r\n"
  171. "\r\n",
  172. path, inet_ntoa(dst.sin_addr), ntohs(dst.sin_port),
  173. ap->er->ip_addr_text, ap->er->http_port, ap->id, 1800);
  174. os_free(url);
  175. wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Subscription request",
  176. wpabuf_head(req), wpabuf_len(req));
  177. ap->http = http_client_addr(&dst, req, 1000, wps_er_http_subscribe_cb,
  178. ap);
  179. if (ap->http == NULL)
  180. wpabuf_free(req);
  181. }
  182. static void wps_er_parse_device_description(struct wps_er_ap *ap,
  183. struct wpabuf *reply)
  184. {
  185. /* Note: reply includes null termination after the buffer data */
  186. const char *data = wpabuf_head(reply);
  187. wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Device info",
  188. wpabuf_head(reply), wpabuf_len(reply));
  189. ap->friendly_name = xml_get_first_item(data, "friendlyName");
  190. wpa_printf(MSG_DEBUG, "WPS ER: friendlyName='%s'", ap->friendly_name);
  191. ap->manufacturer = xml_get_first_item(data, "manufacturer");
  192. wpa_printf(MSG_DEBUG, "WPS ER: manufacturer='%s'", ap->manufacturer);
  193. ap->manufacturer_url = xml_get_first_item(data, "manufacturerURL");
  194. wpa_printf(MSG_DEBUG, "WPS ER: manufacturerURL='%s'",
  195. ap->manufacturer_url);
  196. ap->model_description = xml_get_first_item(data, "modelDescription");
  197. wpa_printf(MSG_DEBUG, "WPS ER: modelDescription='%s'",
  198. ap->model_description);
  199. ap->model_name = xml_get_first_item(data, "modelName");
  200. wpa_printf(MSG_DEBUG, "WPS ER: modelName='%s'", ap->model_name);
  201. ap->model_number = xml_get_first_item(data, "modelNumber");
  202. wpa_printf(MSG_DEBUG, "WPS ER: modelNumber='%s'", ap->model_number);
  203. ap->model_url = xml_get_first_item(data, "modelURL");
  204. wpa_printf(MSG_DEBUG, "WPS ER: modelURL='%s'", ap->model_url);
  205. ap->serial_number = xml_get_first_item(data, "serialNumber");
  206. wpa_printf(MSG_DEBUG, "WPS ER: serialNumber='%s'", ap->serial_number);
  207. ap->udn = xml_get_first_item(data, "UDN");
  208. wpa_printf(MSG_DEBUG, "WPS ER: UDN='%s'", ap->udn);
  209. ap->upc = xml_get_first_item(data, "UPC");
  210. wpa_printf(MSG_DEBUG, "WPS ER: UPC='%s'", ap->upc);
  211. ap->scpd_url = http_link_update(
  212. xml_get_first_item(data, "SCPDURL"), ap->location);
  213. wpa_printf(MSG_DEBUG, "WPS ER: SCPDURL='%s'", ap->scpd_url);
  214. ap->control_url = http_link_update(
  215. xml_get_first_item(data, "controlURL"), ap->location);
  216. wpa_printf(MSG_DEBUG, "WPS ER: controlURL='%s'", ap->control_url);
  217. ap->event_sub_url = http_link_update(
  218. xml_get_first_item(data, "eventSubURL"), ap->location);
  219. wpa_printf(MSG_DEBUG, "WPS ER: eventSubURL='%s'", ap->event_sub_url);
  220. }
  221. static void wps_er_http_dev_desc_cb(void *ctx, struct http_client *c,
  222. enum http_client_event event)
  223. {
  224. struct wps_er_ap *ap = ctx;
  225. struct wpabuf *reply;
  226. int subscribe = 0;
  227. switch (event) {
  228. case HTTP_CLIENT_OK:
  229. reply = http_client_get_body(c);
  230. if (reply == NULL)
  231. break;
  232. wps_er_parse_device_description(ap, reply);
  233. subscribe = 1;
  234. break;
  235. case HTTP_CLIENT_FAILED:
  236. case HTTP_CLIENT_INVALID_REPLY:
  237. case HTTP_CLIENT_TIMEOUT:
  238. wpa_printf(MSG_DEBUG, "WPS ER: Failed to fetch device info");
  239. break;
  240. }
  241. http_client_free(ap->http);
  242. ap->http = NULL;
  243. if (subscribe)
  244. wps_er_subscribe(ap);
  245. }
  246. static void wps_er_ap_add(struct wps_er *er, struct in_addr *addr,
  247. const char *location, int max_age)
  248. {
  249. struct wps_er_ap *ap;
  250. ap = wps_er_ap_get(er, addr);
  251. if (ap) {
  252. /* Update advertisement timeout */
  253. eloop_cancel_timeout(wps_er_ap_timeout, er, ap);
  254. eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
  255. return;
  256. }
  257. ap = os_zalloc(sizeof(*ap));
  258. if (ap == NULL)
  259. return;
  260. ap->er = er;
  261. ap->id = ++er->next_ap_id;
  262. ap->location = os_strdup(location);
  263. if (ap->location == NULL) {
  264. os_free(ap);
  265. return;
  266. }
  267. ap->next = er->ap;
  268. er->ap = ap;
  269. ap->addr.s_addr = addr->s_addr;
  270. eloop_register_timeout(max_age, 0, wps_er_ap_timeout, er, ap);
  271. wpa_printf(MSG_DEBUG, "WPS ER: Added AP entry for %s (%s)",
  272. inet_ntoa(ap->addr), ap->location);
  273. /* Fetch device description */
  274. ap->http = http_client_url(ap->location, NULL, 10000,
  275. wps_er_http_dev_desc_cb, ap);
  276. }
  277. static void wps_er_ap_remove(struct wps_er *er, struct in_addr *addr)
  278. {
  279. struct wps_er_ap *prev = NULL, *ap = er->ap;
  280. while (ap) {
  281. if (ap->addr.s_addr == addr->s_addr) {
  282. if (prev)
  283. prev->next = ap->next;
  284. else
  285. er->ap = ap->next;
  286. wps_er_ap_free(er, ap);
  287. return;
  288. }
  289. prev = ap;
  290. ap = ap->next;
  291. }
  292. }
  293. static void wps_er_ap_remove_all(struct wps_er *er)
  294. {
  295. struct wps_er_ap *prev, *ap;
  296. ap = er->ap;
  297. er->ap = NULL;
  298. while (ap) {
  299. prev = ap;
  300. ap = ap->next;
  301. wps_er_ap_free(er, prev);
  302. }
  303. }
  304. static void wps_er_ssdp_rx(int sd, void *eloop_ctx, void *sock_ctx)
  305. {
  306. struct wps_er *er = eloop_ctx;
  307. struct sockaddr_in addr; /* client address */
  308. socklen_t addr_len;
  309. int nread;
  310. char buf[MULTICAST_MAX_READ], *pos, *pos2, *start;
  311. int wfa = 0, byebye = 0;
  312. int max_age = -1;
  313. char *location = NULL;
  314. addr_len = sizeof(addr);
  315. nread = recvfrom(sd, buf, sizeof(buf) - 1, 0,
  316. (struct sockaddr *) &addr, &addr_len);
  317. if (nread <= 0)
  318. return;
  319. buf[nread] = '\0';
  320. wpa_printf(MSG_DEBUG, "WPS ER: Received SSDP from %s",
  321. inet_ntoa(addr.sin_addr));
  322. wpa_hexdump_ascii(MSG_MSGDUMP, "WPS ER: Received SSDP contents",
  323. (u8 *) buf, nread);
  324. if (sd == er->multicast_sd) {
  325. /* Reply to M-SEARCH */
  326. if (os_strncmp(buf, "HTTP/1.1 200 OK", 15) != 0)
  327. return; /* unexpected response header */
  328. } else {
  329. /* Unsolicited message (likely NOTIFY or M-SEARCH) */
  330. if (os_strncmp(buf, "NOTIFY ", 7) != 0)
  331. return; /* only process notifications */
  332. }
  333. for (start = buf; start && *start; start = pos) {
  334. pos = os_strchr(start, '\n');
  335. if (pos) {
  336. if (pos[-1] == '\r')
  337. pos[-1] = '\0';
  338. *pos++ = '\0';
  339. }
  340. if (os_strstr(start, "schemas-wifialliance-org:device:"
  341. "WFADevice:1"))
  342. wfa = 1;
  343. if (os_strstr(start, "schemas-wifialliance-org:service:"
  344. "WFAWLANConfig:1"))
  345. wfa = 1;
  346. if (os_strncasecmp(start, "LOCATION:", 9) == 0) {
  347. start += 9;
  348. while (*start == ' ')
  349. start++;
  350. location = start;
  351. } else if (os_strncasecmp(start, "NTS:", 4) == 0) {
  352. if (os_strstr(start, "ssdp:byebye"))
  353. byebye = 1;
  354. } else if (os_strncasecmp(start, "CACHE-CONTROL:", 14) == 0) {
  355. start += 9;
  356. while (*start == ' ')
  357. start++;
  358. pos2 = os_strstr(start, "max-age=");
  359. if (pos2 == NULL)
  360. continue;
  361. pos2 += 8;
  362. max_age = atoi(pos2);
  363. }
  364. }
  365. if (!wfa)
  366. return; /* Not WPS advertisement/reply */
  367. if (byebye) {
  368. wps_er_ap_remove(er, &addr.sin_addr);
  369. return;
  370. }
  371. if (!location)
  372. return; /* Unknown location */
  373. if (max_age < 1)
  374. return; /* No max-age reported */
  375. wpa_printf(MSG_DEBUG, "WPS ER: AP discovered: %s "
  376. "(packet source: %s max-age: %d)",
  377. location, inet_ntoa(addr.sin_addr), max_age);
  378. wps_er_ap_add(er, &addr.sin_addr, location, max_age);
  379. }
  380. static void wps_er_send_ssdp_msearch(struct wps_er *er)
  381. {
  382. struct wpabuf *msg;
  383. struct sockaddr_in dest;
  384. msg = wpabuf_alloc(500);
  385. if (msg == NULL)
  386. return;
  387. wpabuf_put_str(msg,
  388. "M-SEARCH * HTTP/1.1\r\n"
  389. "HOST: 239.255.255.250:1900\r\n"
  390. "MAN: \"ssdp:discover\"\r\n"
  391. "MX: 3\r\n"
  392. "ST: urn:schemas-wifialliance-org:device:WFADevice:1"
  393. "\r\n"
  394. "\r\n");
  395. os_memset(&dest, 0, sizeof(dest));
  396. dest.sin_family = AF_INET;
  397. dest.sin_addr.s_addr = inet_addr(UPNP_MULTICAST_ADDRESS);
  398. dest.sin_port = htons(UPNP_MULTICAST_PORT);
  399. if (sendto(er->multicast_sd, wpabuf_head(msg), wpabuf_len(msg), 0,
  400. (struct sockaddr *) &dest, sizeof(dest)) < 0)
  401. wpa_printf(MSG_DEBUG, "WPS ER: M-SEARCH sendto failed: "
  402. "%d (%s)", errno, strerror(errno));
  403. wpabuf_free(msg);
  404. }
  405. static void wps_er_http_event(struct wps_er *er, struct http_request *req,
  406. unsigned int ap_id)
  407. {
  408. struct wps_er_ap *ap = wps_er_ap_get_id(er, ap_id);
  409. if (ap == NULL) {
  410. wpa_printf(MSG_DEBUG, "WPS ER: HTTP event from unknown AP id "
  411. "%u", ap_id);
  412. return;
  413. }
  414. wpa_printf(MSG_MSGDUMP, "WPS ER: HTTP event from AP id %u: %s",
  415. ap_id, http_request_get_data(req));
  416. /* TODO */
  417. http_request_deinit(req);
  418. }
  419. static void wps_er_http_notify(struct wps_er *er, struct http_request *req)
  420. {
  421. char *uri = http_request_get_uri(req);
  422. if (os_strncmp(uri, "/event/", 7) == 0) {
  423. wps_er_http_event(er, req, atoi(uri + 7));
  424. } else {
  425. wpa_printf(MSG_DEBUG, "WPS ER: Unknown HTTP NOTIFY for '%s'",
  426. uri);
  427. http_request_deinit(req);
  428. }
  429. }
  430. static void wps_er_http_req(void *ctx, struct http_request *req)
  431. {
  432. struct wps_er *er = ctx;
  433. struct sockaddr_in *cli = http_request_get_cli_addr(req);
  434. enum httpread_hdr_type type = http_request_get_type(req);
  435. wpa_printf(MSG_DEBUG, "WPS ER: HTTP request: '%s' (type %d) from "
  436. "%s:%d",
  437. http_request_get_uri(req), type,
  438. inet_ntoa(cli->sin_addr), ntohs(cli->sin_port));
  439. switch (type) {
  440. case HTTPREAD_HDR_TYPE_NOTIFY:
  441. wps_er_http_notify(er, req);
  442. break;
  443. default:
  444. wpa_printf(MSG_DEBUG, "WPS ER: Unsupported HTTP request type "
  445. "%d", type);
  446. http_request_deinit(req);
  447. break;
  448. }
  449. }
  450. struct wps_er *
  451. wps_er_init(struct wps_context *wps, const char *ifname)
  452. {
  453. struct wps_er *er;
  454. struct wps_registrar_config rcfg;
  455. struct in_addr addr;
  456. er = os_zalloc(sizeof(*er));
  457. if (er == NULL)
  458. return NULL;
  459. er->multicast_sd = -1;
  460. er->ssdp_sd = -1;
  461. os_strlcpy(er->ifname, ifname, sizeof(er->ifname));
  462. os_memset(&rcfg, 0, sizeof(rcfg));
  463. rcfg.pin_needed_cb = wps_er_pin_needed_cb;
  464. rcfg.cb_ctx = er;
  465. er->reg = wps_registrar_init(wps, &rcfg);
  466. if (er->reg == NULL) {
  467. wps_er_deinit(er);
  468. return NULL;
  469. }
  470. if (get_netif_info(ifname,
  471. &er->ip_addr, &er->ip_addr_text,
  472. er->mac_addr, &er->mac_addr_text)) {
  473. wpa_printf(MSG_INFO, "WPS UPnP: Could not get IP/MAC address "
  474. "for %s. Does it have IP address?", ifname);
  475. wps_er_deinit(er);
  476. return NULL;
  477. }
  478. if (add_ssdp_network(ifname)) {
  479. wps_er_deinit(er);
  480. return NULL;
  481. }
  482. er->multicast_sd = ssdp_open_multicast_sock(er->ip_addr);
  483. if (er->multicast_sd < 0) {
  484. wps_er_deinit(er);
  485. return NULL;
  486. }
  487. er->ssdp_sd = ssdp_listener_open();
  488. if (er->ssdp_sd < 0) {
  489. wps_er_deinit(er);
  490. return NULL;
  491. }
  492. if (eloop_register_sock(er->multicast_sd, EVENT_TYPE_READ,
  493. wps_er_ssdp_rx, er, NULL) ||
  494. eloop_register_sock(er->ssdp_sd, EVENT_TYPE_READ,
  495. wps_er_ssdp_rx, er, NULL)) {
  496. wps_er_deinit(er);
  497. return NULL;
  498. }
  499. addr.s_addr = er->ip_addr;
  500. er->http_srv = http_server_init(&addr, -1, wps_er_http_req, er);
  501. if (er->http_srv == NULL) {
  502. wps_er_deinit(er);
  503. return NULL;
  504. }
  505. er->http_port = http_server_get_port(er->http_srv);
  506. wpa_printf(MSG_DEBUG, "WPS ER: Start (ifname=%s ip_addr=%s "
  507. "mac_addr=%s)",
  508. er->ifname, er->ip_addr_text, er->mac_addr_text);
  509. wps_er_send_ssdp_msearch(er);
  510. return er;
  511. }
  512. void wps_er_deinit(struct wps_er *er)
  513. {
  514. if (er == NULL)
  515. return;
  516. http_server_deinit(er->http_srv);
  517. wps_er_ap_remove_all(er);
  518. if (er->multicast_sd >= 0) {
  519. eloop_unregister_sock(er->multicast_sd, EVENT_TYPE_READ);
  520. close(er->multicast_sd);
  521. }
  522. if (er->ssdp_sd >= 0) {
  523. eloop_unregister_sock(er->ssdp_sd, EVENT_TYPE_READ);
  524. close(er->ssdp_sd);
  525. }
  526. wps_registrar_deinit(er->reg);
  527. os_free(er->ip_addr_text);
  528. os_free(er->mac_addr_text);
  529. os_free(er);
  530. }