ctrl_iface.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  1. /*
  2. * hostapd / UNIX domain socket -based control interface
  3. * Copyright (c) 2004-2014, 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. #include "utils/includes.h"
  9. #ifndef CONFIG_NATIVE_WINDOWS
  10. #include <sys/un.h>
  11. #include <sys/stat.h>
  12. #include <stddef.h>
  13. #include "utils/common.h"
  14. #include "utils/eloop.h"
  15. #include "common/version.h"
  16. #include "common/ieee802_11_defs.h"
  17. #include "drivers/driver.h"
  18. #include "radius/radius_client.h"
  19. #include "radius/radius_server.h"
  20. #include "ap/hostapd.h"
  21. #include "ap/ap_config.h"
  22. #include "ap/ieee802_1x.h"
  23. #include "ap/wpa_auth.h"
  24. #include "ap/ieee802_11.h"
  25. #include "ap/sta_info.h"
  26. #include "ap/wps_hostapd.h"
  27. #include "ap/ctrl_iface_ap.h"
  28. #include "ap/ap_drv_ops.h"
  29. #include "ap/wnm_ap.h"
  30. #include "ap/wpa_auth.h"
  31. #include "wps/wps_defs.h"
  32. #include "wps/wps.h"
  33. #include "config_file.h"
  34. #include "ctrl_iface.h"
  35. struct wpa_ctrl_dst {
  36. struct wpa_ctrl_dst *next;
  37. struct sockaddr_un addr;
  38. socklen_t addrlen;
  39. int debug_level;
  40. int errors;
  41. };
  42. static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
  43. const char *buf, size_t len);
  44. static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
  45. struct sockaddr_un *from,
  46. socklen_t fromlen)
  47. {
  48. struct wpa_ctrl_dst *dst;
  49. dst = os_zalloc(sizeof(*dst));
  50. if (dst == NULL)
  51. return -1;
  52. os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
  53. dst->addrlen = fromlen;
  54. dst->debug_level = MSG_INFO;
  55. dst->next = hapd->ctrl_dst;
  56. hapd->ctrl_dst = dst;
  57. wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
  58. (u8 *) from->sun_path,
  59. fromlen - offsetof(struct sockaddr_un, sun_path));
  60. return 0;
  61. }
  62. static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
  63. struct sockaddr_un *from,
  64. socklen_t fromlen)
  65. {
  66. struct wpa_ctrl_dst *dst, *prev = NULL;
  67. dst = hapd->ctrl_dst;
  68. while (dst) {
  69. if (fromlen == dst->addrlen &&
  70. os_memcmp(from->sun_path, dst->addr.sun_path,
  71. fromlen - offsetof(struct sockaddr_un, sun_path))
  72. == 0) {
  73. wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
  74. (u8 *) from->sun_path,
  75. fromlen -
  76. offsetof(struct sockaddr_un, sun_path));
  77. if (prev == NULL)
  78. hapd->ctrl_dst = dst->next;
  79. else
  80. prev->next = dst->next;
  81. os_free(dst);
  82. return 0;
  83. }
  84. prev = dst;
  85. dst = dst->next;
  86. }
  87. return -1;
  88. }
  89. static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
  90. struct sockaddr_un *from,
  91. socklen_t fromlen,
  92. char *level)
  93. {
  94. struct wpa_ctrl_dst *dst;
  95. wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
  96. dst = hapd->ctrl_dst;
  97. while (dst) {
  98. if (fromlen == dst->addrlen &&
  99. os_memcmp(from->sun_path, dst->addr.sun_path,
  100. fromlen - offsetof(struct sockaddr_un, sun_path))
  101. == 0) {
  102. wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
  103. "level", (u8 *) from->sun_path, fromlen -
  104. offsetof(struct sockaddr_un, sun_path));
  105. dst->debug_level = atoi(level);
  106. return 0;
  107. }
  108. dst = dst->next;
  109. }
  110. return -1;
  111. }
  112. static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
  113. const char *txtaddr)
  114. {
  115. u8 addr[ETH_ALEN];
  116. struct sta_info *sta;
  117. wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
  118. if (hwaddr_aton(txtaddr, addr))
  119. return -1;
  120. sta = ap_get_sta(hapd, addr);
  121. if (sta)
  122. return 0;
  123. wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
  124. "notification", MAC2STR(addr));
  125. sta = ap_sta_add(hapd, addr);
  126. if (sta == NULL)
  127. return -1;
  128. hostapd_new_assoc_sta(hapd, sta, 0);
  129. return 0;
  130. }
  131. #ifdef CONFIG_IEEE80211W
  132. #ifdef NEED_AP_MLME
  133. static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
  134. const char *txtaddr)
  135. {
  136. u8 addr[ETH_ALEN];
  137. u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
  138. wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
  139. if (hwaddr_aton(txtaddr, addr) ||
  140. os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
  141. return -1;
  142. ieee802_11_send_sa_query_req(hapd, addr, trans_id);
  143. return 0;
  144. }
  145. #endif /* NEED_AP_MLME */
  146. #endif /* CONFIG_IEEE80211W */
  147. #ifdef CONFIG_WPS
  148. static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
  149. {
  150. char *pin = os_strchr(txt, ' ');
  151. char *timeout_txt;
  152. int timeout;
  153. u8 addr_buf[ETH_ALEN], *addr = NULL;
  154. char *pos;
  155. if (pin == NULL)
  156. return -1;
  157. *pin++ = '\0';
  158. timeout_txt = os_strchr(pin, ' ');
  159. if (timeout_txt) {
  160. *timeout_txt++ = '\0';
  161. timeout = atoi(timeout_txt);
  162. pos = os_strchr(timeout_txt, ' ');
  163. if (pos) {
  164. *pos++ = '\0';
  165. if (hwaddr_aton(pos, addr_buf) == 0)
  166. addr = addr_buf;
  167. }
  168. } else
  169. timeout = 0;
  170. return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
  171. }
  172. static int hostapd_ctrl_iface_wps_check_pin(
  173. struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
  174. {
  175. char pin[9];
  176. size_t len;
  177. char *pos;
  178. int ret;
  179. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  180. (u8 *) cmd, os_strlen(cmd));
  181. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  182. if (*pos < '0' || *pos > '9')
  183. continue;
  184. pin[len++] = *pos;
  185. if (len == 9) {
  186. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  187. return -1;
  188. }
  189. }
  190. if (len != 4 && len != 8) {
  191. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  192. return -1;
  193. }
  194. pin[len] = '\0';
  195. if (len == 8) {
  196. unsigned int pin_val;
  197. pin_val = atoi(pin);
  198. if (!wps_pin_valid(pin_val)) {
  199. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  200. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  201. if (ret < 0 || (size_t) ret >= buflen)
  202. return -1;
  203. return ret;
  204. }
  205. }
  206. ret = os_snprintf(buf, buflen, "%s", pin);
  207. if (ret < 0 || (size_t) ret >= buflen)
  208. return -1;
  209. return ret;
  210. }
  211. #ifdef CONFIG_WPS_NFC
  212. static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
  213. char *pos)
  214. {
  215. size_t len;
  216. struct wpabuf *buf;
  217. int ret;
  218. len = os_strlen(pos);
  219. if (len & 0x01)
  220. return -1;
  221. len /= 2;
  222. buf = wpabuf_alloc(len);
  223. if (buf == NULL)
  224. return -1;
  225. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  226. wpabuf_free(buf);
  227. return -1;
  228. }
  229. ret = hostapd_wps_nfc_tag_read(hapd, buf);
  230. wpabuf_free(buf);
  231. return ret;
  232. }
  233. static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
  234. char *cmd, char *reply,
  235. size_t max_len)
  236. {
  237. int ndef;
  238. struct wpabuf *buf;
  239. int res;
  240. if (os_strcmp(cmd, "WPS") == 0)
  241. ndef = 0;
  242. else if (os_strcmp(cmd, "NDEF") == 0)
  243. ndef = 1;
  244. else
  245. return -1;
  246. buf = hostapd_wps_nfc_config_token(hapd, ndef);
  247. if (buf == NULL)
  248. return -1;
  249. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  250. wpabuf_len(buf));
  251. reply[res++] = '\n';
  252. reply[res] = '\0';
  253. wpabuf_free(buf);
  254. return res;
  255. }
  256. static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
  257. char *reply, size_t max_len,
  258. int ndef)
  259. {
  260. struct wpabuf *buf;
  261. int res;
  262. buf = hostapd_wps_nfc_token_gen(hapd, ndef);
  263. if (buf == NULL)
  264. return -1;
  265. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  266. wpabuf_len(buf));
  267. reply[res++] = '\n';
  268. reply[res] = '\0';
  269. wpabuf_free(buf);
  270. return res;
  271. }
  272. static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
  273. char *cmd, char *reply,
  274. size_t max_len)
  275. {
  276. if (os_strcmp(cmd, "WPS") == 0)
  277. return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
  278. max_len, 0);
  279. if (os_strcmp(cmd, "NDEF") == 0)
  280. return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
  281. max_len, 1);
  282. if (os_strcmp(cmd, "enable") == 0)
  283. return hostapd_wps_nfc_token_enable(hapd);
  284. if (os_strcmp(cmd, "disable") == 0) {
  285. hostapd_wps_nfc_token_disable(hapd);
  286. return 0;
  287. }
  288. return -1;
  289. }
  290. static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
  291. char *cmd, char *reply,
  292. size_t max_len)
  293. {
  294. struct wpabuf *buf;
  295. int res;
  296. char *pos;
  297. int ndef;
  298. pos = os_strchr(cmd, ' ');
  299. if (pos == NULL)
  300. return -1;
  301. *pos++ = '\0';
  302. if (os_strcmp(cmd, "WPS") == 0)
  303. ndef = 0;
  304. else if (os_strcmp(cmd, "NDEF") == 0)
  305. ndef = 1;
  306. else
  307. return -1;
  308. if (os_strcmp(pos, "WPS-CR") == 0)
  309. buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
  310. else
  311. buf = NULL;
  312. if (buf == NULL)
  313. return -1;
  314. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  315. wpabuf_len(buf));
  316. reply[res++] = '\n';
  317. reply[res] = '\0';
  318. wpabuf_free(buf);
  319. return res;
  320. }
  321. static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
  322. char *cmd)
  323. {
  324. size_t len;
  325. struct wpabuf *req, *sel;
  326. int ret;
  327. char *pos, *role, *type, *pos2;
  328. role = cmd;
  329. pos = os_strchr(role, ' ');
  330. if (pos == NULL)
  331. return -1;
  332. *pos++ = '\0';
  333. type = pos;
  334. pos = os_strchr(type, ' ');
  335. if (pos == NULL)
  336. return -1;
  337. *pos++ = '\0';
  338. pos2 = os_strchr(pos, ' ');
  339. if (pos2 == NULL)
  340. return -1;
  341. *pos2++ = '\0';
  342. len = os_strlen(pos);
  343. if (len & 0x01)
  344. return -1;
  345. len /= 2;
  346. req = wpabuf_alloc(len);
  347. if (req == NULL)
  348. return -1;
  349. if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
  350. wpabuf_free(req);
  351. return -1;
  352. }
  353. len = os_strlen(pos2);
  354. if (len & 0x01) {
  355. wpabuf_free(req);
  356. return -1;
  357. }
  358. len /= 2;
  359. sel = wpabuf_alloc(len);
  360. if (sel == NULL) {
  361. wpabuf_free(req);
  362. return -1;
  363. }
  364. if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
  365. wpabuf_free(req);
  366. wpabuf_free(sel);
  367. return -1;
  368. }
  369. if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
  370. ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
  371. } else {
  372. wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
  373. "reported: role=%s type=%s", role, type);
  374. ret = -1;
  375. }
  376. wpabuf_free(req);
  377. wpabuf_free(sel);
  378. return ret;
  379. }
  380. #endif /* CONFIG_WPS_NFC */
  381. static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
  382. char *buf, size_t buflen)
  383. {
  384. int timeout = 300;
  385. char *pos;
  386. const char *pin_txt;
  387. pos = os_strchr(txt, ' ');
  388. if (pos)
  389. *pos++ = '\0';
  390. if (os_strcmp(txt, "disable") == 0) {
  391. hostapd_wps_ap_pin_disable(hapd);
  392. return os_snprintf(buf, buflen, "OK\n");
  393. }
  394. if (os_strcmp(txt, "random") == 0) {
  395. if (pos)
  396. timeout = atoi(pos);
  397. pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
  398. if (pin_txt == NULL)
  399. return -1;
  400. return os_snprintf(buf, buflen, "%s", pin_txt);
  401. }
  402. if (os_strcmp(txt, "get") == 0) {
  403. pin_txt = hostapd_wps_ap_pin_get(hapd);
  404. if (pin_txt == NULL)
  405. return -1;
  406. return os_snprintf(buf, buflen, "%s", pin_txt);
  407. }
  408. if (os_strcmp(txt, "set") == 0) {
  409. char *pin;
  410. if (pos == NULL)
  411. return -1;
  412. pin = pos;
  413. pos = os_strchr(pos, ' ');
  414. if (pos) {
  415. *pos++ = '\0';
  416. timeout = atoi(pos);
  417. }
  418. if (os_strlen(pin) > buflen)
  419. return -1;
  420. if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
  421. return -1;
  422. return os_snprintf(buf, buflen, "%s", pin);
  423. }
  424. return -1;
  425. }
  426. static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
  427. {
  428. char *pos;
  429. char *ssid, *auth, *encr = NULL, *key = NULL;
  430. ssid = txt;
  431. pos = os_strchr(txt, ' ');
  432. if (!pos)
  433. return -1;
  434. *pos++ = '\0';
  435. auth = pos;
  436. pos = os_strchr(pos, ' ');
  437. if (pos) {
  438. *pos++ = '\0';
  439. encr = pos;
  440. pos = os_strchr(pos, ' ');
  441. if (pos) {
  442. *pos++ = '\0';
  443. key = pos;
  444. }
  445. }
  446. return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
  447. }
  448. static const char * pbc_status_str(enum pbc_status status)
  449. {
  450. switch (status) {
  451. case WPS_PBC_STATUS_DISABLE:
  452. return "Disabled";
  453. case WPS_PBC_STATUS_ACTIVE:
  454. return "Active";
  455. case WPS_PBC_STATUS_TIMEOUT:
  456. return "Timed-out";
  457. case WPS_PBC_STATUS_OVERLAP:
  458. return "Overlap";
  459. default:
  460. return "Unknown";
  461. }
  462. }
  463. static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
  464. char *buf, size_t buflen)
  465. {
  466. int ret;
  467. char *pos, *end;
  468. pos = buf;
  469. end = buf + buflen;
  470. ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
  471. pbc_status_str(hapd->wps_stats.pbc_status));
  472. if (ret < 0 || ret >= end - pos)
  473. return pos - buf;
  474. pos += ret;
  475. ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
  476. (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
  477. "Success":
  478. (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
  479. "Failed" : "None")));
  480. if (ret < 0 || ret >= end - pos)
  481. return pos - buf;
  482. pos += ret;
  483. /* If status == Failure - Add possible Reasons */
  484. if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
  485. hapd->wps_stats.failure_reason > 0) {
  486. ret = os_snprintf(pos, end - pos,
  487. "Failure Reason: %s\n",
  488. wps_ei_str(hapd->wps_stats.failure_reason));
  489. if (ret < 0 || ret >= end - pos)
  490. return pos - buf;
  491. pos += ret;
  492. }
  493. if (hapd->wps_stats.status) {
  494. ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
  495. MAC2STR(hapd->wps_stats.peer_addr));
  496. if (ret < 0 || ret >= end - pos)
  497. return pos - buf;
  498. pos += ret;
  499. }
  500. return pos - buf;
  501. }
  502. #endif /* CONFIG_WPS */
  503. #ifdef CONFIG_INTERWORKING
  504. static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
  505. const char *cmd)
  506. {
  507. u8 qos_map_set[16 + 2 * 21], count = 0;
  508. const char *pos = cmd;
  509. int val, ret;
  510. for (;;) {
  511. if (count == sizeof(qos_map_set)) {
  512. wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
  513. return -1;
  514. }
  515. val = atoi(pos);
  516. if (val < 0 || val > 255) {
  517. wpa_printf(MSG_INFO, "Invalid QoS Map Set");
  518. return -1;
  519. }
  520. qos_map_set[count++] = val;
  521. pos = os_strchr(pos, ',');
  522. if (!pos)
  523. break;
  524. pos++;
  525. }
  526. if (count < 16 || count & 1) {
  527. wpa_printf(MSG_INFO, "Invalid QoS Map Set");
  528. return -1;
  529. }
  530. ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
  531. if (ret) {
  532. wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
  533. return -1;
  534. }
  535. os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
  536. hapd->conf->qos_map_set_len = count;
  537. return 0;
  538. }
  539. static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
  540. const char *cmd)
  541. {
  542. u8 addr[ETH_ALEN];
  543. struct sta_info *sta;
  544. struct wpabuf *buf;
  545. u8 *qos_map_set = hapd->conf->qos_map_set;
  546. u8 qos_map_set_len = hapd->conf->qos_map_set_len;
  547. int ret;
  548. if (!qos_map_set_len) {
  549. wpa_printf(MSG_INFO, "QoS Map Set is not set");
  550. return -1;
  551. }
  552. if (hwaddr_aton(cmd, addr))
  553. return -1;
  554. sta = ap_get_sta(hapd, addr);
  555. if (sta == NULL) {
  556. wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
  557. "for QoS Map Configuration message",
  558. MAC2STR(addr));
  559. return -1;
  560. }
  561. if (!sta->qos_map_enabled) {
  562. wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
  563. "support for QoS Map", MAC2STR(addr));
  564. return -1;
  565. }
  566. buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
  567. if (buf == NULL)
  568. return -1;
  569. wpabuf_put_u8(buf, WLAN_ACTION_QOS);
  570. wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
  571. /* QoS Map Set Element */
  572. wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
  573. wpabuf_put_u8(buf, qos_map_set_len);
  574. wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
  575. ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
  576. wpabuf_head(buf), wpabuf_len(buf));
  577. wpabuf_free(buf);
  578. return ret;
  579. }
  580. #endif /* CONFIG_INTERWORKING */
  581. #ifdef CONFIG_WNM
  582. static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
  583. const char *cmd)
  584. {
  585. u8 addr[ETH_ALEN];
  586. int disassoc_timer;
  587. struct sta_info *sta;
  588. if (hwaddr_aton(cmd, addr))
  589. return -1;
  590. if (cmd[17] != ' ')
  591. return -1;
  592. disassoc_timer = atoi(cmd + 17);
  593. sta = ap_get_sta(hapd, addr);
  594. if (sta == NULL) {
  595. wpa_printf(MSG_DEBUG, "Station " MACSTR
  596. " not found for disassociation imminent message",
  597. MAC2STR(addr));
  598. return -1;
  599. }
  600. return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
  601. }
  602. static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
  603. const char *cmd)
  604. {
  605. u8 addr[ETH_ALEN];
  606. const char *url, *timerstr;
  607. int disassoc_timer;
  608. struct sta_info *sta;
  609. if (hwaddr_aton(cmd, addr))
  610. return -1;
  611. sta = ap_get_sta(hapd, addr);
  612. if (sta == NULL) {
  613. wpa_printf(MSG_DEBUG, "Station " MACSTR
  614. " not found for ESS disassociation imminent message",
  615. MAC2STR(addr));
  616. return -1;
  617. }
  618. timerstr = cmd + 17;
  619. if (*timerstr != ' ')
  620. return -1;
  621. timerstr++;
  622. disassoc_timer = atoi(timerstr);
  623. if (disassoc_timer < 0 || disassoc_timer > 65535)
  624. return -1;
  625. url = os_strchr(timerstr, ' ');
  626. if (url == NULL)
  627. return -1;
  628. url++;
  629. return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
  630. }
  631. #endif /* CONFIG_WNM */
  632. static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
  633. char *buf, size_t buflen)
  634. {
  635. int ret;
  636. char *pos, *end;
  637. pos = buf;
  638. end = buf + buflen;
  639. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
  640. "ssid=%s\n",
  641. MAC2STR(hapd->own_addr),
  642. wpa_ssid_txt(hapd->conf->ssid.ssid,
  643. hapd->conf->ssid.ssid_len));
  644. if (ret < 0 || ret >= end - pos)
  645. return pos - buf;
  646. pos += ret;
  647. #ifdef CONFIG_WPS
  648. ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
  649. hapd->conf->wps_state == 0 ? "disabled" :
  650. (hapd->conf->wps_state == 1 ? "not configured" :
  651. "configured"));
  652. if (ret < 0 || ret >= end - pos)
  653. return pos - buf;
  654. pos += ret;
  655. if (hapd->conf->wps_state && hapd->conf->wpa &&
  656. hapd->conf->ssid.wpa_passphrase) {
  657. ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
  658. hapd->conf->ssid.wpa_passphrase);
  659. if (ret < 0 || ret >= end - pos)
  660. return pos - buf;
  661. pos += ret;
  662. }
  663. if (hapd->conf->wps_state && hapd->conf->wpa &&
  664. hapd->conf->ssid.wpa_psk &&
  665. hapd->conf->ssid.wpa_psk->group) {
  666. char hex[PMK_LEN * 2 + 1];
  667. wpa_snprintf_hex(hex, sizeof(hex),
  668. hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
  669. ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
  670. if (ret < 0 || ret >= end - pos)
  671. return pos - buf;
  672. pos += ret;
  673. }
  674. #endif /* CONFIG_WPS */
  675. if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
  676. ret = os_snprintf(pos, end - pos, "key_mgmt=");
  677. if (ret < 0 || ret >= end - pos)
  678. return pos - buf;
  679. pos += ret;
  680. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
  681. ret = os_snprintf(pos, end - pos, "WPA-PSK ");
  682. if (ret < 0 || ret >= end - pos)
  683. return pos - buf;
  684. pos += ret;
  685. }
  686. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  687. ret = os_snprintf(pos, end - pos, "WPA-EAP ");
  688. if (ret < 0 || ret >= end - pos)
  689. return pos - buf;
  690. pos += ret;
  691. }
  692. #ifdef CONFIG_IEEE80211R
  693. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  694. ret = os_snprintf(pos, end - pos, "FT-PSK ");
  695. if (ret < 0 || ret >= end - pos)
  696. return pos - buf;
  697. pos += ret;
  698. }
  699. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  700. ret = os_snprintf(pos, end - pos, "FT-EAP ");
  701. if (ret < 0 || ret >= end - pos)
  702. return pos - buf;
  703. pos += ret;
  704. }
  705. #endif /* CONFIG_IEEE80211R */
  706. #ifdef CONFIG_IEEE80211W
  707. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  708. ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
  709. if (ret < 0 || ret >= end - pos)
  710. return pos - buf;
  711. pos += ret;
  712. }
  713. if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  714. ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
  715. if (ret < 0 || ret >= end - pos)
  716. return pos - buf;
  717. pos += ret;
  718. }
  719. #endif /* CONFIG_IEEE80211W */
  720. ret = os_snprintf(pos, end - pos, "\n");
  721. if (ret < 0 || ret >= end - pos)
  722. return pos - buf;
  723. pos += ret;
  724. }
  725. if (hapd->conf->wpa) {
  726. ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
  727. wpa_cipher_txt(hapd->conf->wpa_group));
  728. if (ret < 0 || ret >= end - pos)
  729. return pos - buf;
  730. pos += ret;
  731. }
  732. if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
  733. ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
  734. if (ret < 0 || ret >= end - pos)
  735. return pos - buf;
  736. pos += ret;
  737. ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
  738. " ");
  739. if (ret < 0)
  740. return pos - buf;
  741. pos += ret;
  742. ret = os_snprintf(pos, end - pos, "\n");
  743. if (ret < 0 || ret >= end - pos)
  744. return pos - buf;
  745. pos += ret;
  746. }
  747. if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
  748. ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
  749. if (ret < 0 || ret >= end - pos)
  750. return pos - buf;
  751. pos += ret;
  752. ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
  753. " ");
  754. if (ret < 0)
  755. return pos - buf;
  756. pos += ret;
  757. ret = os_snprintf(pos, end - pos, "\n");
  758. if (ret < 0 || ret >= end - pos)
  759. return pos - buf;
  760. pos += ret;
  761. }
  762. return pos - buf;
  763. }
  764. static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
  765. {
  766. char *value;
  767. int ret = 0;
  768. value = os_strchr(cmd, ' ');
  769. if (value == NULL)
  770. return -1;
  771. *value++ = '\0';
  772. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  773. if (0) {
  774. #ifdef CONFIG_WPS_TESTING
  775. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  776. long int val;
  777. val = strtol(value, NULL, 0);
  778. if (val < 0 || val > 0xff) {
  779. ret = -1;
  780. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  781. "wps_version_number %ld", val);
  782. } else {
  783. wps_version_number = val;
  784. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  785. "version %u.%u",
  786. (wps_version_number & 0xf0) >> 4,
  787. wps_version_number & 0x0f);
  788. hostapd_wps_update_ie(hapd);
  789. }
  790. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  791. wps_testing_dummy_cred = atoi(value);
  792. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  793. wps_testing_dummy_cred);
  794. #endif /* CONFIG_WPS_TESTING */
  795. #ifdef CONFIG_INTERWORKING
  796. } else if (os_strcasecmp(cmd, "gas_frag_limit") == 0) {
  797. int val = atoi(value);
  798. if (val <= 0)
  799. ret = -1;
  800. else
  801. hapd->gas_frag_limit = val;
  802. #endif /* CONFIG_INTERWORKING */
  803. #ifdef CONFIG_TESTING_OPTIONS
  804. } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
  805. hapd->ext_mgmt_frame_handling = atoi(value);
  806. #endif /* CONFIG_TESTING_OPTIONS */
  807. } else {
  808. ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
  809. }
  810. return ret;
  811. }
  812. static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
  813. char *buf, size_t buflen)
  814. {
  815. int res;
  816. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  817. if (os_strcmp(cmd, "version") == 0) {
  818. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  819. if (res < 0 || (unsigned int) res >= buflen)
  820. return -1;
  821. return res;
  822. }
  823. return -1;
  824. }
  825. static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
  826. {
  827. if (hostapd_enable_iface(iface) < 0) {
  828. wpa_printf(MSG_ERROR, "Enabling of interface failed");
  829. return -1;
  830. }
  831. return 0;
  832. }
  833. static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
  834. {
  835. if (hostapd_reload_iface(iface) < 0) {
  836. wpa_printf(MSG_ERROR, "Reloading of interface failed");
  837. return -1;
  838. }
  839. return 0;
  840. }
  841. static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
  842. {
  843. if (hostapd_disable_iface(iface) < 0) {
  844. wpa_printf(MSG_ERROR, "Disabling of interface failed");
  845. return -1;
  846. }
  847. return 0;
  848. }
  849. #ifdef CONFIG_TESTING_OPTIONS
  850. static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
  851. {
  852. union wpa_event_data data;
  853. char *pos, *param;
  854. enum wpa_event_type event;
  855. wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
  856. os_memset(&data, 0, sizeof(data));
  857. param = os_strchr(cmd, ' ');
  858. if (param == NULL)
  859. return -1;
  860. *param++ = '\0';
  861. if (os_strcmp(cmd, "DETECTED") == 0)
  862. event = EVENT_DFS_RADAR_DETECTED;
  863. else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
  864. event = EVENT_DFS_CAC_FINISHED;
  865. else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
  866. event = EVENT_DFS_CAC_ABORTED;
  867. else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
  868. event = EVENT_DFS_NOP_FINISHED;
  869. else {
  870. wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
  871. cmd);
  872. return -1;
  873. }
  874. pos = os_strstr(param, "freq=");
  875. if (pos)
  876. data.dfs_event.freq = atoi(pos + 5);
  877. pos = os_strstr(param, "ht_enabled=1");
  878. if (pos)
  879. data.dfs_event.ht_enabled = 1;
  880. pos = os_strstr(param, "chan_offset=");
  881. if (pos)
  882. data.dfs_event.chan_offset = atoi(pos + 12);
  883. pos = os_strstr(param, "chan_width=");
  884. if (pos)
  885. data.dfs_event.chan_width = atoi(pos + 11);
  886. pos = os_strstr(param, "cf1=");
  887. if (pos)
  888. data.dfs_event.cf1 = atoi(pos + 4);
  889. pos = os_strstr(param, "cf2=");
  890. if (pos)
  891. data.dfs_event.cf2 = atoi(pos + 4);
  892. wpa_supplicant_event(hapd, event, &data);
  893. return 0;
  894. }
  895. static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
  896. {
  897. size_t len;
  898. u8 *buf;
  899. int res;
  900. wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
  901. len = os_strlen(cmd);
  902. if (len & 1)
  903. return -1;
  904. len /= 2;
  905. buf = os_malloc(len);
  906. if (buf == NULL)
  907. return -1;
  908. if (hexstr2bin(cmd, buf, len) < 0) {
  909. os_free(buf);
  910. return -1;
  911. }
  912. res = hostapd_drv_send_mlme(hapd, buf, len, 0);
  913. os_free(buf);
  914. return res;
  915. }
  916. #endif /* CONFIG_TESTING_OPTIONS */
  917. static int hostapd_ctrl_iface_chan_switch(struct hostapd_data *hapd, char *pos)
  918. {
  919. #ifdef NEED_AP_MLME
  920. struct csa_settings settings;
  921. int ret = hostapd_parse_csa_settings(pos, &settings);
  922. if (ret)
  923. return ret;
  924. return hostapd_switch_channel(hapd, &settings);
  925. #else /* NEED_AP_MLME */
  926. return -1;
  927. #endif /* NEED_AP_MLME */
  928. }
  929. static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
  930. int reply_size, const char *param)
  931. {
  932. #ifdef RADIUS_SERVER
  933. if (os_strcmp(param, "radius_server") == 0) {
  934. return radius_server_get_mib(hapd->radius_srv, reply,
  935. reply_size);
  936. }
  937. #endif /* RADIUS_SERVER */
  938. return -1;
  939. }
  940. static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
  941. void *sock_ctx)
  942. {
  943. struct hostapd_data *hapd = eloop_ctx;
  944. char buf[4096];
  945. int res;
  946. struct sockaddr_un from;
  947. socklen_t fromlen = sizeof(from);
  948. char *reply;
  949. const int reply_size = 4096;
  950. int reply_len;
  951. int level = MSG_DEBUG;
  952. res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
  953. (struct sockaddr *) &from, &fromlen);
  954. if (res < 0) {
  955. perror("recvfrom(ctrl_iface)");
  956. return;
  957. }
  958. buf[res] = '\0';
  959. if (os_strcmp(buf, "PING") == 0)
  960. level = MSG_EXCESSIVE;
  961. wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
  962. reply = os_malloc(reply_size);
  963. if (reply == NULL) {
  964. sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
  965. fromlen);
  966. return;
  967. }
  968. os_memcpy(reply, "OK\n", 3);
  969. reply_len = 3;
  970. if (os_strcmp(buf, "PING") == 0) {
  971. os_memcpy(reply, "PONG\n", 5);
  972. reply_len = 5;
  973. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  974. if (wpa_debug_reopen_file() < 0)
  975. reply_len = -1;
  976. } else if (os_strcmp(buf, "STATUS") == 0) {
  977. reply_len = hostapd_ctrl_iface_status(hapd, reply,
  978. reply_size);
  979. } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
  980. reply_len = hostapd_drv_status(hapd, reply, reply_size);
  981. } else if (os_strcmp(buf, "MIB") == 0) {
  982. reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
  983. if (reply_len >= 0) {
  984. res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
  985. reply_size - reply_len);
  986. if (res < 0)
  987. reply_len = -1;
  988. else
  989. reply_len += res;
  990. }
  991. if (reply_len >= 0) {
  992. res = ieee802_1x_get_mib(hapd, reply + reply_len,
  993. reply_size - reply_len);
  994. if (res < 0)
  995. reply_len = -1;
  996. else
  997. reply_len += res;
  998. }
  999. #ifndef CONFIG_NO_RADIUS
  1000. if (reply_len >= 0) {
  1001. res = radius_client_get_mib(hapd->radius,
  1002. reply + reply_len,
  1003. reply_size - reply_len);
  1004. if (res < 0)
  1005. reply_len = -1;
  1006. else
  1007. reply_len += res;
  1008. }
  1009. #endif /* CONFIG_NO_RADIUS */
  1010. } else if (os_strncmp(buf, "MIB ", 4) == 0) {
  1011. reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
  1012. buf + 4);
  1013. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  1014. reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
  1015. reply_size);
  1016. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  1017. reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
  1018. reply_size);
  1019. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  1020. reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
  1021. reply_size);
  1022. } else if (os_strcmp(buf, "ATTACH") == 0) {
  1023. if (hostapd_ctrl_iface_attach(hapd, &from, fromlen))
  1024. reply_len = -1;
  1025. } else if (os_strcmp(buf, "DETACH") == 0) {
  1026. if (hostapd_ctrl_iface_detach(hapd, &from, fromlen))
  1027. reply_len = -1;
  1028. } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
  1029. if (hostapd_ctrl_iface_level(hapd, &from, fromlen,
  1030. buf + 6))
  1031. reply_len = -1;
  1032. } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
  1033. if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
  1034. reply_len = -1;
  1035. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  1036. if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
  1037. reply_len = -1;
  1038. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  1039. if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
  1040. reply_len = -1;
  1041. #ifdef CONFIG_IEEE80211W
  1042. #ifdef NEED_AP_MLME
  1043. } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
  1044. if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
  1045. reply_len = -1;
  1046. #endif /* NEED_AP_MLME */
  1047. #endif /* CONFIG_IEEE80211W */
  1048. #ifdef CONFIG_WPS
  1049. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  1050. if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
  1051. reply_len = -1;
  1052. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  1053. reply_len = hostapd_ctrl_iface_wps_check_pin(
  1054. hapd, buf + 14, reply, reply_size);
  1055. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  1056. if (hostapd_wps_button_pushed(hapd, NULL))
  1057. reply_len = -1;
  1058. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  1059. if (hostapd_wps_cancel(hapd))
  1060. reply_len = -1;
  1061. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  1062. reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
  1063. reply, reply_size);
  1064. } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
  1065. if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
  1066. reply_len = -1;
  1067. } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
  1068. reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
  1069. reply_size);
  1070. #ifdef CONFIG_WPS_NFC
  1071. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
  1072. if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
  1073. reply_len = -1;
  1074. } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
  1075. reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
  1076. hapd, buf + 21, reply, reply_size);
  1077. } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
  1078. reply_len = hostapd_ctrl_iface_wps_nfc_token(
  1079. hapd, buf + 14, reply, reply_size);
  1080. } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
  1081. reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
  1082. hapd, buf + 21, reply, reply_size);
  1083. } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
  1084. if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
  1085. reply_len = -1;
  1086. #endif /* CONFIG_WPS_NFC */
  1087. #endif /* CONFIG_WPS */
  1088. #ifdef CONFIG_INTERWORKING
  1089. } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
  1090. if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
  1091. reply_len = -1;
  1092. } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
  1093. if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
  1094. reply_len = -1;
  1095. #endif /* CONFIG_INTERWORKING */
  1096. #ifdef CONFIG_WNM
  1097. } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
  1098. if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
  1099. reply_len = -1;
  1100. } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
  1101. if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
  1102. reply_len = -1;
  1103. #endif /* CONFIG_WNM */
  1104. } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
  1105. reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
  1106. reply_size);
  1107. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  1108. if (hostapd_ctrl_iface_set(hapd, buf + 4))
  1109. reply_len = -1;
  1110. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  1111. reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
  1112. reply_size);
  1113. } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
  1114. if (hostapd_ctrl_iface_enable(hapd->iface))
  1115. reply_len = -1;
  1116. } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
  1117. if (hostapd_ctrl_iface_reload(hapd->iface))
  1118. reply_len = -1;
  1119. } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
  1120. if (hostapd_ctrl_iface_disable(hapd->iface))
  1121. reply_len = -1;
  1122. #ifdef CONFIG_TESTING_OPTIONS
  1123. } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
  1124. if (hostapd_ctrl_iface_radar(hapd, buf + 6))
  1125. reply_len = -1;
  1126. } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
  1127. if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
  1128. reply_len = -1;
  1129. #endif /* CONFIG_TESTING_OPTIONS */
  1130. } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
  1131. if (hostapd_ctrl_iface_chan_switch(hapd, buf + 12))
  1132. reply_len = -1;
  1133. } else {
  1134. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  1135. reply_len = 16;
  1136. }
  1137. if (reply_len < 0) {
  1138. os_memcpy(reply, "FAIL\n", 5);
  1139. reply_len = 5;
  1140. }
  1141. sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
  1142. os_free(reply);
  1143. }
  1144. static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
  1145. {
  1146. char *buf;
  1147. size_t len;
  1148. if (hapd->conf->ctrl_interface == NULL)
  1149. return NULL;
  1150. len = os_strlen(hapd->conf->ctrl_interface) +
  1151. os_strlen(hapd->conf->iface) + 2;
  1152. buf = os_malloc(len);
  1153. if (buf == NULL)
  1154. return NULL;
  1155. os_snprintf(buf, len, "%s/%s",
  1156. hapd->conf->ctrl_interface, hapd->conf->iface);
  1157. buf[len - 1] = '\0';
  1158. return buf;
  1159. }
  1160. static void hostapd_ctrl_iface_msg_cb(void *ctx, int level, int global,
  1161. const char *txt, size_t len)
  1162. {
  1163. struct hostapd_data *hapd = ctx;
  1164. if (hapd == NULL)
  1165. return;
  1166. hostapd_ctrl_iface_send(hapd, level, txt, len);
  1167. }
  1168. int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
  1169. {
  1170. struct sockaddr_un addr;
  1171. int s = -1;
  1172. char *fname = NULL;
  1173. if (hapd->ctrl_sock > -1) {
  1174. wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
  1175. return 0;
  1176. }
  1177. if (hapd->conf->ctrl_interface == NULL)
  1178. return 0;
  1179. if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
  1180. if (errno == EEXIST) {
  1181. wpa_printf(MSG_DEBUG, "Using existing control "
  1182. "interface directory.");
  1183. } else {
  1184. perror("mkdir[ctrl_interface]");
  1185. goto fail;
  1186. }
  1187. }
  1188. if (hapd->conf->ctrl_interface_gid_set &&
  1189. chown(hapd->conf->ctrl_interface, -1,
  1190. hapd->conf->ctrl_interface_gid) < 0) {
  1191. perror("chown[ctrl_interface]");
  1192. return -1;
  1193. }
  1194. if (!hapd->conf->ctrl_interface_gid_set &&
  1195. hapd->iface->interfaces->ctrl_iface_group &&
  1196. chown(hapd->conf->ctrl_interface, -1,
  1197. hapd->iface->interfaces->ctrl_iface_group) < 0) {
  1198. perror("chown[ctrl_interface]");
  1199. return -1;
  1200. }
  1201. #ifdef ANDROID
  1202. /*
  1203. * Android is using umask 0077 which would leave the control interface
  1204. * directory without group access. This breaks things since Wi-Fi
  1205. * framework assumes that this directory can be accessed by other
  1206. * applications in the wifi group. Fix this by adding group access even
  1207. * if umask value would prevent this.
  1208. */
  1209. if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
  1210. wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
  1211. strerror(errno));
  1212. /* Try to continue anyway */
  1213. }
  1214. #endif /* ANDROID */
  1215. if (os_strlen(hapd->conf->ctrl_interface) + 1 +
  1216. os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
  1217. goto fail;
  1218. s = socket(PF_UNIX, SOCK_DGRAM, 0);
  1219. if (s < 0) {
  1220. perror("socket(PF_UNIX)");
  1221. goto fail;
  1222. }
  1223. os_memset(&addr, 0, sizeof(addr));
  1224. #ifdef __FreeBSD__
  1225. addr.sun_len = sizeof(addr);
  1226. #endif /* __FreeBSD__ */
  1227. addr.sun_family = AF_UNIX;
  1228. fname = hostapd_ctrl_iface_path(hapd);
  1229. if (fname == NULL)
  1230. goto fail;
  1231. os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
  1232. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  1233. wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
  1234. strerror(errno));
  1235. if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  1236. wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
  1237. " allow connections - assuming it was left"
  1238. "over from forced program termination");
  1239. if (unlink(fname) < 0) {
  1240. perror("unlink[ctrl_iface]");
  1241. wpa_printf(MSG_ERROR, "Could not unlink "
  1242. "existing ctrl_iface socket '%s'",
  1243. fname);
  1244. goto fail;
  1245. }
  1246. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
  1247. 0) {
  1248. perror("hostapd-ctrl-iface: bind(PF_UNIX)");
  1249. goto fail;
  1250. }
  1251. wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
  1252. "ctrl_iface socket '%s'", fname);
  1253. } else {
  1254. wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
  1255. "be in use - cannot override it");
  1256. wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
  1257. "not used anymore", fname);
  1258. os_free(fname);
  1259. fname = NULL;
  1260. goto fail;
  1261. }
  1262. }
  1263. if (hapd->conf->ctrl_interface_gid_set &&
  1264. chown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
  1265. perror("chown[ctrl_interface/ifname]");
  1266. goto fail;
  1267. }
  1268. if (!hapd->conf->ctrl_interface_gid_set &&
  1269. hapd->iface->interfaces->ctrl_iface_group &&
  1270. chown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
  1271. perror("chown[ctrl_interface/ifname]");
  1272. goto fail;
  1273. }
  1274. if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
  1275. perror("chmod[ctrl_interface/ifname]");
  1276. goto fail;
  1277. }
  1278. os_free(fname);
  1279. hapd->ctrl_sock = s;
  1280. eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
  1281. NULL);
  1282. hapd->msg_ctx = hapd;
  1283. wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
  1284. return 0;
  1285. fail:
  1286. if (s >= 0)
  1287. close(s);
  1288. if (fname) {
  1289. unlink(fname);
  1290. os_free(fname);
  1291. }
  1292. return -1;
  1293. }
  1294. void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
  1295. {
  1296. struct wpa_ctrl_dst *dst, *prev;
  1297. if (hapd->ctrl_sock > -1) {
  1298. char *fname;
  1299. eloop_unregister_read_sock(hapd->ctrl_sock);
  1300. close(hapd->ctrl_sock);
  1301. hapd->ctrl_sock = -1;
  1302. fname = hostapd_ctrl_iface_path(hapd);
  1303. if (fname)
  1304. unlink(fname);
  1305. os_free(fname);
  1306. if (hapd->conf->ctrl_interface &&
  1307. rmdir(hapd->conf->ctrl_interface) < 0) {
  1308. if (errno == ENOTEMPTY) {
  1309. wpa_printf(MSG_DEBUG, "Control interface "
  1310. "directory not empty - leaving it "
  1311. "behind");
  1312. } else {
  1313. wpa_printf(MSG_ERROR,
  1314. "rmdir[ctrl_interface=%s]: %s",
  1315. hapd->conf->ctrl_interface,
  1316. strerror(errno));
  1317. }
  1318. }
  1319. }
  1320. dst = hapd->ctrl_dst;
  1321. while (dst) {
  1322. prev = dst;
  1323. dst = dst->next;
  1324. os_free(prev);
  1325. }
  1326. }
  1327. static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
  1328. char *buf)
  1329. {
  1330. if (hostapd_add_iface(interfaces, buf) < 0) {
  1331. wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
  1332. return -1;
  1333. }
  1334. return 0;
  1335. }
  1336. static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
  1337. char *buf)
  1338. {
  1339. if (hostapd_remove_iface(interfaces, buf) < 0) {
  1340. wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
  1341. return -1;
  1342. }
  1343. return 0;
  1344. }
  1345. static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
  1346. void *sock_ctx)
  1347. {
  1348. void *interfaces = eloop_ctx;
  1349. char buf[256];
  1350. int res;
  1351. struct sockaddr_un from;
  1352. socklen_t fromlen = sizeof(from);
  1353. char reply[24];
  1354. int reply_len;
  1355. res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
  1356. (struct sockaddr *) &from, &fromlen);
  1357. if (res < 0) {
  1358. perror("recvfrom(ctrl_iface)");
  1359. return;
  1360. }
  1361. buf[res] = '\0';
  1362. wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
  1363. os_memcpy(reply, "OK\n", 3);
  1364. reply_len = 3;
  1365. if (os_strcmp(buf, "PING") == 0) {
  1366. os_memcpy(reply, "PONG\n", 5);
  1367. reply_len = 5;
  1368. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  1369. if (wpa_debug_reopen_file() < 0)
  1370. reply_len = -1;
  1371. } else if (os_strncmp(buf, "ADD ", 4) == 0) {
  1372. if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
  1373. reply_len = -1;
  1374. } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
  1375. if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
  1376. reply_len = -1;
  1377. } else {
  1378. wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
  1379. "ignored");
  1380. reply_len = -1;
  1381. }
  1382. if (reply_len < 0) {
  1383. os_memcpy(reply, "FAIL\n", 5);
  1384. reply_len = 5;
  1385. }
  1386. sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
  1387. }
  1388. static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
  1389. {
  1390. char *buf;
  1391. size_t len;
  1392. if (interface->global_iface_path == NULL)
  1393. return NULL;
  1394. len = os_strlen(interface->global_iface_path) +
  1395. os_strlen(interface->global_iface_name) + 2;
  1396. buf = os_malloc(len);
  1397. if (buf == NULL)
  1398. return NULL;
  1399. os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
  1400. interface->global_iface_name);
  1401. buf[len - 1] = '\0';
  1402. return buf;
  1403. }
  1404. int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
  1405. {
  1406. struct sockaddr_un addr;
  1407. int s = -1;
  1408. char *fname = NULL;
  1409. if (interface->global_iface_path == NULL) {
  1410. wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
  1411. return 0;
  1412. }
  1413. if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
  1414. if (errno == EEXIST) {
  1415. wpa_printf(MSG_DEBUG, "Using existing control "
  1416. "interface directory.");
  1417. } else {
  1418. perror("mkdir[ctrl_interface]");
  1419. goto fail;
  1420. }
  1421. } else if (interface->ctrl_iface_group &&
  1422. chown(interface->global_iface_path, -1,
  1423. interface->ctrl_iface_group) < 0) {
  1424. perror("chown[ctrl_interface]");
  1425. goto fail;
  1426. }
  1427. if (os_strlen(interface->global_iface_path) + 1 +
  1428. os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
  1429. goto fail;
  1430. s = socket(PF_UNIX, SOCK_DGRAM, 0);
  1431. if (s < 0) {
  1432. perror("socket(PF_UNIX)");
  1433. goto fail;
  1434. }
  1435. os_memset(&addr, 0, sizeof(addr));
  1436. #ifdef __FreeBSD__
  1437. addr.sun_len = sizeof(addr);
  1438. #endif /* __FreeBSD__ */
  1439. addr.sun_family = AF_UNIX;
  1440. fname = hostapd_global_ctrl_iface_path(interface);
  1441. if (fname == NULL)
  1442. goto fail;
  1443. os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
  1444. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  1445. wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
  1446. strerror(errno));
  1447. if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  1448. wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
  1449. " allow connections - assuming it was left"
  1450. "over from forced program termination");
  1451. if (unlink(fname) < 0) {
  1452. perror("unlink[ctrl_iface]");
  1453. wpa_printf(MSG_ERROR, "Could not unlink "
  1454. "existing ctrl_iface socket '%s'",
  1455. fname);
  1456. goto fail;
  1457. }
  1458. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
  1459. 0) {
  1460. perror("bind(PF_UNIX)");
  1461. goto fail;
  1462. }
  1463. wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
  1464. "ctrl_iface socket '%s'", fname);
  1465. } else {
  1466. wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
  1467. "be in use - cannot override it");
  1468. wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
  1469. "not used anymore", fname);
  1470. os_free(fname);
  1471. fname = NULL;
  1472. goto fail;
  1473. }
  1474. }
  1475. if (interface->ctrl_iface_group &&
  1476. chown(fname, -1, interface->ctrl_iface_group) < 0) {
  1477. perror("chown[ctrl_interface]");
  1478. goto fail;
  1479. }
  1480. if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
  1481. perror("chmod[ctrl_interface/ifname]");
  1482. goto fail;
  1483. }
  1484. os_free(fname);
  1485. interface->global_ctrl_sock = s;
  1486. eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
  1487. interface, NULL);
  1488. return 0;
  1489. fail:
  1490. if (s >= 0)
  1491. close(s);
  1492. if (fname) {
  1493. unlink(fname);
  1494. os_free(fname);
  1495. }
  1496. return -1;
  1497. }
  1498. void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
  1499. {
  1500. char *fname = NULL;
  1501. if (interfaces->global_ctrl_sock > -1) {
  1502. eloop_unregister_read_sock(interfaces->global_ctrl_sock);
  1503. close(interfaces->global_ctrl_sock);
  1504. interfaces->global_ctrl_sock = -1;
  1505. fname = hostapd_global_ctrl_iface_path(interfaces);
  1506. if (fname) {
  1507. unlink(fname);
  1508. os_free(fname);
  1509. }
  1510. if (interfaces->global_iface_path &&
  1511. rmdir(interfaces->global_iface_path) < 0) {
  1512. if (errno == ENOTEMPTY) {
  1513. wpa_printf(MSG_DEBUG, "Control interface "
  1514. "directory not empty - leaving it "
  1515. "behind");
  1516. } else {
  1517. wpa_printf(MSG_ERROR,
  1518. "rmdir[ctrl_interface=%s]: %s",
  1519. interfaces->global_iface_path,
  1520. strerror(errno));
  1521. }
  1522. }
  1523. os_free(interfaces->global_iface_path);
  1524. interfaces->global_iface_path = NULL;
  1525. }
  1526. }
  1527. static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
  1528. const char *buf, size_t len)
  1529. {
  1530. struct wpa_ctrl_dst *dst, *next;
  1531. struct msghdr msg;
  1532. int idx;
  1533. struct iovec io[2];
  1534. char levelstr[10];
  1535. dst = hapd->ctrl_dst;
  1536. if (hapd->ctrl_sock < 0 || dst == NULL)
  1537. return;
  1538. os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
  1539. io[0].iov_base = levelstr;
  1540. io[0].iov_len = os_strlen(levelstr);
  1541. io[1].iov_base = (char *) buf;
  1542. io[1].iov_len = len;
  1543. os_memset(&msg, 0, sizeof(msg));
  1544. msg.msg_iov = io;
  1545. msg.msg_iovlen = 2;
  1546. idx = 0;
  1547. while (dst) {
  1548. next = dst->next;
  1549. if (level >= dst->debug_level) {
  1550. wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
  1551. (u8 *) dst->addr.sun_path, dst->addrlen -
  1552. offsetof(struct sockaddr_un, sun_path));
  1553. msg.msg_name = &dst->addr;
  1554. msg.msg_namelen = dst->addrlen;
  1555. if (sendmsg(hapd->ctrl_sock, &msg, 0) < 0) {
  1556. int _errno = errno;
  1557. wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
  1558. "%d - %s",
  1559. idx, errno, strerror(errno));
  1560. dst->errors++;
  1561. if (dst->errors > 10 || _errno == ENOENT) {
  1562. hostapd_ctrl_iface_detach(
  1563. hapd, &dst->addr,
  1564. dst->addrlen);
  1565. }
  1566. } else
  1567. dst->errors = 0;
  1568. }
  1569. idx++;
  1570. dst = next;
  1571. }
  1572. }
  1573. #endif /* CONFIG_NATIVE_WINDOWS */