static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s, char *rsp) { #ifdef IEEE8021X_EAPOL char *pos, *id_pos; int id; struct wpa_ssid *ssid; pos = os_strchr(rsp, '-'); if (pos == NULL) return -1; *pos++ = '\0'; id_pos = pos; pos = os_strchr(pos, ':'); if (pos == NULL) return -1; *pos++ = '\0'; id = atoi(id_pos); wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id); wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", (u8 *) pos, os_strlen(pos)); ssid = wpa_config_get_network(wpa_s->conf, id); if (ssid == NULL) { wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d " "to update", id); return -1; } if (os_strcmp(rsp, "IDENTITY") == 0) { os_free(ssid->identity); ssid->identity = (u8 *) os_strdup(pos); ssid->identity_len = os_strlen(pos); ssid->pending_req_identity = 0; if (ssid == wpa_s->current_ssid) wpa_s->reassociate = 1; } else if (os_strcmp(rsp, "PASSWORD") == 0) { os_free(ssid->password); ssid->password = (u8 *) os_strdup(pos); ssid->password_len = os_strlen(pos); ssid->pending_req_password = 0; if (ssid == wpa_s->current_ssid) wpa_s->reassociate = 1; } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) { os_free(ssid->new_password); ssid->new_password = (u8 *) os_strdup(pos); ssid->new_password_len = os_strlen(pos); ssid->pending_req_new_password = 0; if (ssid == wpa_s->current_ssid) wpa_s->reassociate = 1; } else if (os_strcmp(rsp, "PIN") == 0) { os_free(ssid->pin); ssid->pin = os_strdup(pos); ssid->pending_req_pin = 0; if (ssid == wpa_s->current_ssid) wpa_s->reassociate = 1; } else if (os_strcmp(rsp, "OTP") == 0) { os_free(ssid->otp); ssid->otp = (u8 *) os_strdup(pos); ssid->otp_len = os_strlen(pos); os_free(ssid->pending_req_otp); ssid->pending_req_otp = NULL; ssid->pending_req_otp_len = 0; } else if (os_strcmp(rsp, "PASSPHRASE") == 0) { os_free(ssid->private_key_passwd); ssid->private_key_passwd = (u8 *) os_strdup(pos); ssid->pending_req_passphrase = 0; if (ssid == wpa_s->current_ssid) wpa_s->reassociate = 1; } else { wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp); return -1; } return 0; #else /* IEEE8021X_EAPOL */ wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included"); return -1; #endif /* IEEE8021X_EAPOL */ }
/** * wpas_dbus_iface_set_network - Set options for a configured network * @message: Pointer to incoming dbus message * @wpa_s: wpa_supplicant structure for a network interface * @ssid: wpa_ssid structure for a configured network * Returns: a dbus message containing a UINT32 indicating success (1) or * failure (0) * * Handler function for "set" method call of a configured network. */ DBusMessage * wpas_dbus_iface_set_network(DBusMessage *message, struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) { DBusMessage *reply = NULL; struct wpa_dbus_dict_entry entry = { .type = DBUS_TYPE_STRING }; DBusMessageIter iter, iter_dict; dbus_message_iter_init(message, &iter); if (!wpa_dbus_dict_open_read(&iter, &iter_dict)) { reply = wpas_dbus_new_invalid_opts_error(message, NULL); goto out; } while (wpa_dbus_dict_has_dict_entry(&iter_dict)) { char *value = NULL; size_t size = 50; int ret; if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) { reply = wpas_dbus_new_invalid_opts_error(message, NULL); goto out; } /* Type conversions, since wpa_supplicant wants strings */ if (entry.type == DBUS_TYPE_ARRAY && entry.array_type == DBUS_TYPE_BYTE) { if (entry.array_len <= 0) goto error; size = entry.array_len * 2 + 1; value = os_zalloc(size); if (value == NULL) goto error; ret = wpa_snprintf_hex(value, size, (u8 *) entry.bytearray_value, entry.array_len); if (ret <= 0) goto error; } else if (entry.type == DBUS_TYPE_STRING) { if (should_quote_opt(entry.key)) { size = os_strlen(entry.str_value); /* Zero-length option check */ if (size <= 0) goto error; size += 3; /* For quotes and terminator */ value = os_zalloc(size); if (value == NULL) goto error; ret = os_snprintf(value, size, "\"%s\"", entry.str_value); if (ret < 0 || (size_t) ret != (size - 1)) goto error; } else { value = os_strdup(entry.str_value); if (value == NULL) goto error; } } else if (entry.type == DBUS_TYPE_UINT32) { value = os_zalloc(size); if (value == NULL) goto error; ret = os_snprintf(value, size, "%u", entry.uint32_value); if (ret <= 0) goto error; } else if (entry.type == DBUS_TYPE_INT32) { value = os_zalloc(size); if (value == NULL) goto error; ret = os_snprintf(value, size, "%d", entry.int32_value); if (ret <= 0) goto error; } else goto error; if (wpa_config_set(ssid, entry.key, value, 0) < 0) goto error; if ((os_strcmp(entry.key, "psk") == 0 && value[0] == '"' && ssid->ssid_len) || (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase)) wpa_config_update_psk(ssid); else if (os_strcmp(entry.key, "priority") == 0) wpa_config_update_prio_list(wpa_s->conf); os_free(value); wpa_dbus_dict_entry_clear(&entry); continue; error: os_free(value); reply = wpas_dbus_new_invalid_opts_error(message, entry.key); wpa_dbus_dict_entry_clear(&entry); break; } if (!reply) reply = wpas_dbus_new_success_reply(message); out: return reply; }
static void wpa_config_write_global(FILE *f, struct wpa_config *config) { #ifdef CONFIG_CTRL_IFACE if (config->ctrl_interface) fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface); if (config->ctrl_interface_group) fprintf(f, "ctrl_interface_group=%s\n", config->ctrl_interface_group); #endif /* CONFIG_CTRL_IFACE */ if (config->eapol_version != DEFAULT_EAPOL_VERSION) fprintf(f, "eapol_version=%d\n", config->eapol_version); if (config->ap_scan != DEFAULT_AP_SCAN) fprintf(f, "ap_scan=%d\n", config->ap_scan); if (config->disable_scan_offload) fprintf(f, "disable_scan_offload=%d\n", config->disable_scan_offload); if (config->fast_reauth != DEFAULT_FAST_REAUTH) fprintf(f, "fast_reauth=%d\n", config->fast_reauth); if (config->opensc_engine_path) fprintf(f, "opensc_engine_path=%s\n", config->opensc_engine_path); if (config->pkcs11_engine_path) fprintf(f, "pkcs11_engine_path=%s\n", config->pkcs11_engine_path); if (config->pkcs11_module_path) fprintf(f, "pkcs11_module_path=%s\n", config->pkcs11_module_path); if (config->pcsc_reader) fprintf(f, "pcsc_reader=%s\n", config->pcsc_reader); if (config->pcsc_pin) fprintf(f, "pcsc_pin=%s\n", config->pcsc_pin); if (config->driver_param) fprintf(f, "driver_param=%s\n", config->driver_param); if (config->dot11RSNAConfigPMKLifetime) fprintf(f, "dot11RSNAConfigPMKLifetime=%d\n", config->dot11RSNAConfigPMKLifetime); if (config->dot11RSNAConfigPMKReauthThreshold) fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%d\n", config->dot11RSNAConfigPMKReauthThreshold); if (config->dot11RSNAConfigSATimeout) fprintf(f, "dot11RSNAConfigSATimeout=%d\n", config->dot11RSNAConfigSATimeout); if (config->update_config) fprintf(f, "update_config=%d\n", config->update_config); #ifdef CONFIG_WPS if (!is_nil_uuid(config->uuid)) { char buf[40]; uuid_bin2str(config->uuid, buf, sizeof(buf)); fprintf(f, "uuid=%s\n", buf); } if (config->device_name) fprintf(f, "device_name=%s\n", config->device_name); if (config->manufacturer) fprintf(f, "manufacturer=%s\n", config->manufacturer); if (config->model_name) fprintf(f, "model_name=%s\n", config->model_name); if (config->model_number) fprintf(f, "model_number=%s\n", config->model_number); if (config->serial_number) fprintf(f, "serial_number=%s\n", config->serial_number); { char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; buf = wps_dev_type_bin2str(config->device_type, _buf, sizeof(_buf)); if (os_strcmp(buf, "0-00000000-0") != 0) fprintf(f, "device_type=%s\n", buf); } if (WPA_GET_BE32(config->os_version)) fprintf(f, "os_version=%08x\n", WPA_GET_BE32(config->os_version)); if (config->config_methods) fprintf(f, "config_methods=%s\n", config->config_methods); if (config->wps_cred_processing) fprintf(f, "wps_cred_processing=%d\n", config->wps_cred_processing); if (config->wps_vendor_ext_m1) { int i, len = wpabuf_len(config->wps_vendor_ext_m1); const u8 *p = wpabuf_head_u8(config->wps_vendor_ext_m1); if (len > 0) { fprintf(f, "wps_vendor_ext_m1="); for (i = 0; i < len; i++) fprintf(f, "%02x", *p++); fprintf(f, "\n"); } } #endif /* CONFIG_WPS */ #ifdef CONFIG_P2P if (config->p2p_listen_reg_class) fprintf(f, "p2p_listen_reg_class=%u\n", config->p2p_listen_reg_class); if (config->p2p_listen_channel) fprintf(f, "p2p_listen_channel=%u\n", config->p2p_listen_channel); if (config->p2p_oper_reg_class) fprintf(f, "p2p_oper_reg_class=%u\n", config->p2p_oper_reg_class); if (config->p2p_oper_channel) fprintf(f, "p2p_oper_channel=%u\n", config->p2p_oper_channel); if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT) fprintf(f, "p2p_go_intent=%u\n", config->p2p_go_intent); if (config->p2p_ssid_postfix) fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix); if (config->persistent_reconnect) fprintf(f, "persistent_reconnect=%u\n", config->persistent_reconnect); if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS) fprintf(f, "p2p_intra_bss=%u\n", config->p2p_intra_bss); if (config->p2p_group_idle) fprintf(f, "p2p_group_idle=%u\n", config->p2p_group_idle); if (config->p2p_pref_chan) { unsigned int i; fprintf(f, "p2p_pref_chan="); for (i = 0; i < config->num_p2p_pref_chan; i++) { fprintf(f, "%s%u:%u", i > 0 ? "," : "", config->p2p_pref_chan[i].op_class, config->p2p_pref_chan[i].chan); } fprintf(f, "\n"); } if (config->p2p_go_ht40) fprintf(f, "p2p_go_ht40=%u\n", config->p2p_go_ht40); if (config->p2p_disabled) fprintf(f, "p2p_disabled=%u\n", config->p2p_disabled); if (config->p2p_no_group_iface) fprintf(f, "p2p_no_group_iface=%u\n", config->p2p_no_group_iface); if (config->p2p_ignore_shared_freq) fprintf(f, "p2p_ignore_shared_freq=%u\n", config->p2p_ignore_shared_freq); #endif /* CONFIG_P2P */ if (config->country[0] && config->country[1]) { fprintf(f, "country=%c%c\n", config->country[0], config->country[1]); } if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT) fprintf(f, "bss_max_count=%u\n", config->bss_max_count); if (config->bss_expiration_age != DEFAULT_BSS_EXPIRATION_AGE) fprintf(f, "bss_expiration_age=%u\n", config->bss_expiration_age); if (config->bss_expiration_scan_count != DEFAULT_BSS_EXPIRATION_SCAN_COUNT) fprintf(f, "bss_expiration_scan_count=%u\n", config->bss_expiration_scan_count); if (config->filter_ssids) fprintf(f, "filter_ssids=%d\n", config->filter_ssids); if (config->max_num_sta != DEFAULT_MAX_NUM_STA) fprintf(f, "max_num_sta=%u\n", config->max_num_sta); if (config->disassoc_low_ack) fprintf(f, "disassoc_low_ack=%u\n", config->disassoc_low_ack); #ifdef CONFIG_HS20 if (config->hs20) fprintf(f, "hs20=1\n"); #endif /* CONFIG_HS20 */ #ifdef CONFIG_INTERWORKING if (config->interworking) fprintf(f, "interworking=%u\n", config->interworking); if (!is_zero_ether_addr(config->hessid)) fprintf(f, "hessid=" MACSTR "\n", MAC2STR(config->hessid)); if (config->access_network_type != DEFAULT_ACCESS_NETWORK_TYPE) fprintf(f, "access_network_type=%d\n", config->access_network_type); #endif /* CONFIG_INTERWORKING */ if (config->pbc_in_m1) fprintf(f, "pbc_in_m1=%u\n", config->pbc_in_m1); if (config->wps_nfc_pw_from_config) { if (config->wps_nfc_dev_pw_id) fprintf(f, "wps_nfc_dev_pw_id=%d\n", config->wps_nfc_dev_pw_id); write_global_bin(f, "wps_nfc_dh_pubkey", config->wps_nfc_dh_pubkey); write_global_bin(f, "wps_nfc_dh_privkey", config->wps_nfc_dh_privkey); write_global_bin(f, "wps_nfc_dev_pw", config->wps_nfc_dev_pw); } if (config->ext_password_backend) fprintf(f, "ext_password_backend=%s\n", config->ext_password_backend); if (config->p2p_go_max_inactivity != DEFAULT_P2P_GO_MAX_INACTIVITY) fprintf(f, "p2p_go_max_inactivity=%d\n", config->p2p_go_max_inactivity); if (config->auto_interworking) fprintf(f, "auto_interworking=%d\n", config->auto_interworking); if (config->okc) fprintf(f, "okc=%d\n", config->okc); if (config->pmf) fprintf(f, "pmf=%d\n", config->pmf); if (config->dtim_period) fprintf(f, "dtim_period=%d\n", config->dtim_period); if (config->beacon_int) fprintf(f, "beacon_int=%d\n", config->beacon_int); if (config->sae_groups) { int i; fprintf(f, "sae_groups="); for (i = 0; config->sae_groups[i] >= 0; i++) { fprintf(f, "%s%d", i > 0 ? " " : "", config->sae_groups[i]); } fprintf(f, "\n"); } if (config->ap_vendor_elements) { int i, len = wpabuf_len(config->ap_vendor_elements); const u8 *p = wpabuf_head_u8(config->ap_vendor_elements); if (len > 0) { fprintf(f, "ap_vendor_elements="); for (i = 0; i < len; i++) fprintf(f, "%02x", *p++); fprintf(f, "\n"); } } if (config->ignore_old_scan_res) fprintf(f, "ignore_old_scan_res=%d\n", config->ignore_old_scan_res); }
int testing_test_fail(void) { const char *func[WPA_TRACE_LEN]; size_t i, res, len; char *pos, *next; int match; if (!wpa_trace_test_fail_after) return 0; res = wpa_trace_calling_func(func, WPA_TRACE_LEN); i = 0; if (i < res && os_strcmp(func[i], __func__) == 0) i++; pos = wpa_trace_test_fail_func; match = 0; while (i < res) { int allow_skip = 1; int maybe = 0; if (*pos == '=') { allow_skip = 0; pos++; } else if (*pos == '?') { maybe = 1; pos++; } next = os_strchr(pos, ';'); if (next) len = next - pos; else len = os_strlen(pos); if (os_memcmp(pos, func[i], len) != 0) { if (maybe && next) { pos = next + 1; continue; } if (allow_skip) { i++; continue; } return 0; } if (!next) { match = 1; break; } pos = next + 1; i++; } if (!match) return 0; wpa_trace_test_fail_after--; if (wpa_trace_test_fail_after == 0) { wpa_printf(MSG_INFO, "TESTING: fail at %s", wpa_trace_test_fail_func); for (i = 0; i < res; i++) wpa_printf(MSG_INFO, "backtrace[%d] = %s", (int) i, func[i]); return 1; } return 0; }
/** * ap_handle_timer - Per STA timer handler * @eloop_ctx: struct hostapd_data * * @timeout_ctx: struct sta_info * * * This function is called to check station activity and to remove inactive * stations. */ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) { struct hostapd_data *hapd = eloop_ctx; struct sta_info *sta = timeout_ctx; unsigned long next_time = 0; if (sta->timeout_next == STA_REMOVE) { hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "deauthenticated due to " "local deauth request"); ap_free_sta(hapd, sta); return; } if ((sta->flags & WLAN_STA_ASSOC) && (sta->timeout_next == STA_NULLFUNC || sta->timeout_next == STA_DISASSOC)) { int inactive_sec; wpa_printf(MSG_DEBUG, "Checking STA " MACSTR " inactivity:", MAC2STR(sta->addr)); inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); if (inactive_sec == -1) { wpa_printf(MSG_DEBUG, "Could not get station info " "from kernel driver for " MACSTR ".", MAC2STR(sta->addr)); } else if (inactive_sec < hapd->conf->ap_max_inactivity && sta->flags & WLAN_STA_ASSOC) { /* station activity detected; reset timeout state */ wpa_printf(MSG_DEBUG, " Station has been active"); sta->timeout_next = STA_NULLFUNC; next_time = hapd->conf->ap_max_inactivity - inactive_sec; } } if ((sta->flags & WLAN_STA_ASSOC) && sta->timeout_next == STA_DISASSOC && !(sta->flags & WLAN_STA_PENDING_POLL)) { wpa_printf(MSG_DEBUG, " Station has ACKed data poll"); /* data nullfunc frame poll did not produce TX errors; assume * station ACKed it */ sta->timeout_next = STA_NULLFUNC; next_time = hapd->conf->ap_max_inactivity; } if (next_time) { eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, sta); return; } if (sta->timeout_next == STA_NULLFUNC && (sta->flags & WLAN_STA_ASSOC)) { #ifndef CONFIG_NATIVE_WINDOWS /* send data frame to poll STA and check whether this frame * is ACKed */ struct ieee80211_hdr hdr; wpa_printf(MSG_DEBUG, " Polling STA with data frame"); sta->flags |= WLAN_STA_PENDING_POLL; os_memset(&hdr, 0, sizeof(hdr)); if (hapd->driver && os_strcmp(hapd->driver->name, "hostap") == 0) { /* * WLAN_FC_STYPE_NULLFUNC would be more appropriate, * but it is apparently not retried so TX Exc events * are not received for it. */ hdr.frame_control = IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); } else { hdr.frame_control = IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_NULLFUNC); } hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); os_memcpy(hdr.IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN); os_memcpy(hdr.IEEE80211_BSSID_FROMDS, hapd->own_addr, ETH_ALEN); os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN); if (hostapd_drv_send_mlme(hapd, &hdr, sizeof(hdr)) < 0) perror("ap_handle_timer: send"); #endif /* CONFIG_NATIVE_WINDOWS */ } else if (sta->timeout_next != STA_REMOVE) { int deauth = sta->timeout_next == STA_DEAUTH; wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR, deauth ? "deauthentication" : "disassociation", MAC2STR(sta->addr)); if (deauth) { hostapd_drv_sta_deauth( hapd, sta->addr, WLAN_REASON_PREV_AUTH_NOT_VALID); } else { hostapd_drv_sta_disassoc( hapd, sta->addr, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); } } switch (sta->timeout_next) { case STA_NULLFUNC: sta->timeout_next = STA_DISASSOC; eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, hapd, sta); break; case STA_DISASSOC: sta->flags &= ~WLAN_STA_ASSOC; ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); if (!sta->acct_terminate_cause) sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; accounting_sta_stop(hapd, sta); ieee802_1x_free_station(sta); hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "disassociated due to " "inactivity"); sta->timeout_next = STA_DEAUTH; eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, hapd, sta); mlme_disassociate_indication( hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); break; case STA_DEAUTH: case STA_REMOVE: hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_INFO, "deauthenticated due to " "inactivity"); if (!sta->acct_terminate_cause) sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; mlme_deauthenticate_indication( hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID); ap_free_sta(hapd, sta); break; } }
/** * * @param params * @param req_id * @return */ int ICACHE_FLASH_ATTR dispatcher_t::mqttPublish(JVal* params, int32_t req_id) { // {"jsonrpc": "2.0", "method": "mqtt_publish", "params": {"id": 0, "topic": "fabric/esp8266/test1", "payload": "data 1234", "qos": 0, "retain": false}, "id": 3} if(m_Wifi->isConnected() == false) { os()->jsonRpc()->errorReply(EWIFI_NOT_CONNECTED, req_id, "wifi not connected"); return EWIFI_NOT_CONNECTED; } uint16_t flag = 0; /****************************************************************************************************************** * extract data from JSON-RPC request * */ int slot = -1; const char* topic = 0; const char* payload = 0; int qos = 0; BaBool retain = false; m_Err->reset(); JVal* jv = params; // extract all data while(jv != 0) { const char* name = jv->getName(); if(os_strcmp("id", name) == 0) { slot = jv->getInt(m_Err); flag |= _PUB_SLOT; DTXT("%lu dispatcher_t::mqttPublish(): slot = %d\n", millis(), slot); } else if(os_strcmp("topic", name) == 0) { topic = jv->getString(m_Err); flag |= _PUB_TOPIC; DTXT("%lu dispatcher_t::mqttPublish(): topic = %s\n", millis(), topic); } else if(os_strcmp("payload", name) == 0) { payload = jv->getString(m_Err); flag |= _PUB_PAYLOAD; DTXT("%lu dispatcher_t::mqttPublisht(): payload = %s\n", millis(), payload); } else if(os_strcmp("qos", name) == 0) { qos = jv->getInt(m_Err); flag |= _PUB_QOS; DTXT("%lu dispatcher_t::mqttPublish(): qos = %d\n", millis(), qos); } else if(os_strcmp("retain", name) == 0) { retain = jv->getBoolean(m_Err); flag |= _PUB_RETAIN; DTXT("%lu dispatcher_t::mqttPublish(): retain = %s\n", millis(), retain ? "True" : "False"); } else { DTXT("%lu dispatcher_t::mqttPublish(): unknown = %s\n", millis(), name); } // check for errors if(m_Err->isError()) { os()->jsonRpc()->errorReply(EJSON_DECODER, req_id, "JSON decoder error; %s", m_Err->msg); return EJSON_DECODER; } jv = jv->getNextElem(); } /****************************************************************************************************************** * start publish * */ int ret = EOK; if(((flag & _PUB_SLOT) == _PUB_SLOT) && ((flag & _PUB_TOPIC) == _PUB_TOPIC) && ((flag & _PUB_PAYLOAD) == _PUB_PAYLOAD)) { if(slot >= 0 && slot < m_MqttClient.getMaxConnections()) { ret = m_MqttClient.publish(slot, topic, payload, os_strlen(payload), qos, retain); if(ret == EOK) { os()->jsonRpc()->successReply(req_id, "%d", slot); } else { os()->jsonRpc()->errorReply(ret, req_id, "publish error"); } } else { ret = EID; os()->jsonRpc()->errorReply(ret, req_id, "invalid id"); } } else { ret = EMISSING_PARAMETER; os()->jsonRpc()->errorReply(ret, req_id, "no id and/or topic and/or payload specified"); } return ret; }
int main(int argc, char *argv[]) { struct wpa_supplicant wpa_s; int c, ret = 1, wait_for_monitor = 0, save_config = 0; char *as_addr = "127.0.0.1"; int as_port = 1812; char *as_secret = "radius"; char *cli_addr = NULL; char *conf = NULL; int timeout = 30; char *pos; struct extra_radius_attr *p = NULL, *p1; if (os_program_init()) return -1; hostapd_logger_register_cb(hostapd_logger_cb); os_memset(&eapol_test, 0, sizeof(eapol_test)); eapol_test.connect_info = "CONNECT 11Mbps 802.11b"; os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN); wpa_debug_level = 0; wpa_debug_show_keys = 1; for (;;) { c = getopt(argc, argv, "a:A:c:C:M:nN:p:r:s:St:W"); if (c < 0) break; switch (c) { case 'a': as_addr = optarg; break; case 'A': cli_addr = optarg; break; case 'c': conf = optarg; break; case 'C': eapol_test.connect_info = optarg; break; case 'M': if (hwaddr_aton(optarg, eapol_test.own_addr)) { usage(); return -1; } break; case 'n': eapol_test.no_mppe_keys++; break; case 'p': as_port = atoi(optarg); break; case 'r': eapol_test.eapol_test_num_reauths = atoi(optarg); break; case 's': as_secret = optarg; break; case 'S': save_config++; break; case 't': timeout = atoi(optarg); break; case 'W': wait_for_monitor++; break; case 'N': p1 = os_zalloc(sizeof(p1)); if (p1 == NULL) break; if (!p) eapol_test.extra_attrs = p1; else p->next = p1; p = p1; p->type = atoi(optarg); pos = os_strchr(optarg, ':'); if (pos == NULL) { p->syntax = 'n'; p->data = NULL; break; } pos++; if (pos[0] == '\0' || pos[1] != ':') { printf("Incorrect format of attribute " "specification\n"); break; } p->syntax = pos[0]; p->data = pos + 2; break; default: usage(); return -1; } } if (argc > optind && os_strcmp(argv[optind], "scard") == 0) { return scard_test(); } if (argc > optind && os_strcmp(argv[optind], "sim") == 0) { return scard_get_triplets(argc - optind - 1, &argv[optind + 1]); } if (conf == NULL) { usage(); printf("Configuration file is required.\n"); return -1; } if (eap_peer_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } if (eloop_init(&wpa_s)) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } os_memset(&wpa_s, 0, sizeof(wpa_s)); eapol_test.wpa_s = &wpa_s; wpa_s.conf = wpa_config_read(conf); if (wpa_s.conf == NULL) { printf("Failed to parse configuration file '%s'.\n", conf); return -1; } if (wpa_s.conf->ssid == NULL) { printf("No networks defined.\n"); return -1; } wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret, cli_addr); wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s); if (wpa_s.ctrl_iface == NULL) { printf("Failed to initialize control interface '%s'.\n" "You may have another eapol_test process already " "running or the file was\n" "left by an unclean termination of eapol_test in " "which case you will need\n" "to manually remove this file before starting " "eapol_test again.\n", wpa_s.conf->ctrl_interface); return -1; } if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid)) return -1; if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid)) return -1; if (wait_for_monitor) wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface); eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test, NULL); eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL); eloop_register_signal_terminate(eapol_test_terminate, NULL); eloop_register_signal_reconfig(eapol_test_terminate, NULL); eloop_run(); eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL); eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL); if (eapol_test_compare_pmk(&eapol_test) == 0 || eapol_test.no_mppe_keys) ret = 0; if (eapol_test.auth_timed_out) ret = -2; if (eapol_test.radius_access_reject_received) ret = -3; if (save_config) wpa_config_write(conf, wpa_s.conf); test_eapol_clean(&eapol_test, &wpa_s); eap_peer_unregister_methods(); eloop_destroy(); printf("MPPE keys OK: %d mismatch: %d\n", eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch); if (eapol_test.num_mppe_mismatch) ret = -4; if (ret) printf("FAILURE\n"); else printf("SUCCESS\n"); os_program_deinit(); return ret; }
/*! *@brief NativeMethodBind接口回调函数 *@author zhaohm3 *@param[in] jvmti_env *@param[in] jni_env *@param[in] thread *@param[in] method *@param[in] address *@param[in] new_address_ptr *@retval *@note * *@since 2014-9-15 17:59 *@attention * */ GPrivate void JNICALL JVMNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, jmethodID method, void* address, void** new_address_ptr) { GCMON_PRINT_FUNC(); //! 获取Perf_Attach的地址 if (NULL == gfnPerf_Attach) { String_t szName = NULL; String_t szSig = NULL; String_t szGsig = NULL; jvmtiError error = JVMTI_ERROR_NONE; GASSERT(gpJvmtiEnv == jvmti_env); error = gcmon_monitor_enter(); if (JVMTI_ERROR_NONE == error && NULL == gfnPerf_Attach) { error = gJvmtiEnv->GetMethodName(gpJvmtiEnv, method, &szName, &szSig, &szGsig); if (JVMTI_ERROR_NONE == error && address != NULL && new_address_ptr != NULL && address == *new_address_ptr && szName != NULL && szSig != NULL && NULL == szGsig && 0 == os_strcmp(szName, "attach") && 0 == os_strcmp(szSig, "(Ljava/lang/String;II)Ljava/nio/ByteBuffer;")) { gfnPerf_Attach = (Perf_Attach_t)address; //! 通过Perf_Attach接口,Attach到JVM,获取PerfMemory地址 gcmon_get_perf_address(jvmti_env, jni_env); } /* gcmon_debug_msg("%s --> method = 0x%p " "\t address = 0x%p " "\t new_address_ptr = 0x%p " "\t *new_address_ptr = 0x%p " "\t name = %s " "\t sig = %s " "\t gsig = %s \n", __FUNCTION__, method, address, new_address_ptr, *new_address_ptr, szName, szSig, szGsig); */ gJvmtiEnv->Deallocate(gpJvmtiEnv, szName); gJvmtiEnv->Deallocate(gpJvmtiEnv, szSig); gJvmtiEnv->Deallocate(gpJvmtiEnv, szGsig); } error = gcmon_monitor_exit(); } }
int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[], const char *name, const char *val) { int num, v; const char *pos; struct hostapd_wmm_ac_params *ac; /* skip 'wme_ac_' or 'wmm_ac_' prefix */ pos = name + 7; if (os_strncmp(pos, "be_", 3) == 0) { num = 0; pos += 3; } else if (os_strncmp(pos, "bk_", 3) == 0) { num = 1; pos += 3; } else if (os_strncmp(pos, "vi_", 3) == 0) { num = 2; pos += 3; } else if (os_strncmp(pos, "vo_", 3) == 0) { num = 3; pos += 3; } else { wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos); return -1; } ac = &wmm_ac_params[num]; if (os_strcmp(pos, "aifs") == 0) { v = atoi(val); if (v < 1 || v > 255) { wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v); return -1; } ac->aifs = v; } else if (os_strcmp(pos, "cwmin") == 0) { v = atoi(val); if (v < 0 || v > 12) { wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v); return -1; } ac->cwmin = v; } else if (os_strcmp(pos, "cwmax") == 0) { v = atoi(val); if (v < 0 || v > 12) { wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v); return -1; } ac->cwmax = v; } else if (os_strcmp(pos, "txop_limit") == 0) { v = atoi(val); if (v < 0 || v > 0xffff) { wpa_printf(MSG_ERROR, "Invalid txop value %d", v); return -1; } ac->txop_limit = v; } else if (os_strcmp(pos, "acm") == 0) { v = atoi(val); if (v < 0 || v > 1) { wpa_printf(MSG_ERROR, "Invalid acm value %d", v); return -1; } ac->admission_control_mandatory = v; } else { wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos); return -1; } return 0; }
static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx, void *sock_ctx) { struct wpa_supplicant *wpa_s = eloop_ctx; struct ctrl_iface_priv *priv = sock_ctx; char buf[256], *pos; int res; struct sockaddr_in from; socklen_t fromlen = sizeof(from); char *reply = NULL; size_t reply_len = 0; int new_attached = 0; u8 cookie[COOKIE_LEN]; res = recvfrom(sock, buf, sizeof(buf) - 1, 0, (struct sockaddr *) &from, &fromlen); if (res < 0) { perror("recvfrom(ctrl_iface)"); return; } #ifndef CONFIG_CTRL_IFACE_UDP_REMOTE if (from.sin_addr.s_addr != htonl((127 << 24) | 1)) { /* * The OS networking stack is expected to drop this kind of * frames since the socket is bound to only localhost address. * Just in case, drop the frame if it is coming from any other * address. */ wpa_printf(MSG_DEBUG, "CTRL: Drop packet from unexpected " "source %s", inet_ntoa(from.sin_addr)); return; } #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */ buf[res] = '\0'; if (os_strcmp(buf, "GET_COOKIE") == 0) { reply = wpa_supplicant_ctrl_iface_get_cookie(priv, &reply_len); goto done; } /* * Require that the client includes a prefix with the 'cookie' value * fetched with GET_COOKIE command. This is used to verify that the * client has access to a bidirectional link over UDP in order to * avoid attacks using forged localhost IP address even if the OS does * not block such frames from remote destinations. */ if (os_strncmp(buf, "COOKIE=", 7) != 0) { wpa_printf(MSG_DEBUG, "CTLR: No cookie in the request - " "drop request"); return; } if (hexstr2bin(buf + 7, cookie, COOKIE_LEN) < 0) { wpa_printf(MSG_DEBUG, "CTLR: Invalid cookie format in the " "request - drop request"); return; } if (os_memcmp(cookie, priv->cookie, COOKIE_LEN) != 0) { wpa_printf(MSG_DEBUG, "CTLR: Invalid cookie in the request - " "drop request"); return; } pos = buf + 7 + 2 * COOKIE_LEN; while (*pos == ' ') pos++; if (os_strcmp(pos, "ATTACH") == 0) { if (wpa_supplicant_ctrl_iface_attach(priv, &from, fromlen)) reply_len = 1; else { new_attached = 1; reply_len = 2; } } else if (os_strcmp(pos, "DETACH") == 0) { if (wpa_supplicant_ctrl_iface_detach(priv, &from, fromlen)) reply_len = 1; else reply_len = 2; } else if (os_strncmp(pos, "LEVEL ", 6) == 0) { if (wpa_supplicant_ctrl_iface_level(priv, &from, fromlen, pos + 6)) reply_len = 1; else reply_len = 2; } else { reply = wpa_supplicant_ctrl_iface_process(wpa_s, pos, &reply_len); } done: if (reply) { sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen); os_free(reply); } else if (reply_len == 1) { sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from, fromlen); } else if (reply_len == 2) { sendto(sock, "OK\n", 3, 0, (struct sockaddr *) &from, fromlen); } if (new_attached) eapol_sm_notify_ctrl_attached(wpa_s->eapol); }
static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx, void *sock_ctx) { struct wpa_global *global = eloop_ctx; struct ctrl_iface_global_priv *priv = sock_ctx; char buf[256], *pos; int res; struct sockaddr_in from; socklen_t fromlen = sizeof(from); char *reply; size_t reply_len; u8 cookie[COOKIE_LEN]; res = recvfrom(sock, buf, sizeof(buf) - 1, 0, (struct sockaddr *) &from, &fromlen); if (res < 0) { perror("recvfrom(ctrl_iface)"); return; } #ifndef CONFIG_CTRL_IFACE_UDP_REMOTE if (from.sin_addr.s_addr != htonl((127 << 24) | 1)) { /* * The OS networking stack is expected to drop this kind of * frames since the socket is bound to only localhost address. * Just in case, drop the frame if it is coming from any other * address. */ wpa_printf(MSG_DEBUG, "CTRL: Drop packet from unexpected " "source %s", inet_ntoa(from.sin_addr)); return; } #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */ buf[res] = '\0'; if (os_strcmp(buf, "GET_COOKIE") == 0) { reply = wpa_supplicant_global_get_cookie(priv, &reply_len); goto done; } if (os_strncmp(buf, "COOKIE=", 7) != 0) { wpa_printf(MSG_DEBUG, "CTLR: No cookie in the request - " "drop request"); return; } if (hexstr2bin(buf + 7, cookie, COOKIE_LEN) < 0) { wpa_printf(MSG_DEBUG, "CTLR: Invalid cookie format in the " "request - drop request"); return; } if (os_memcmp(cookie, priv->cookie, COOKIE_LEN) != 0) { wpa_printf(MSG_DEBUG, "CTLR: Invalid cookie in the request - " "drop request"); return; } pos = buf + 7 + 2 * COOKIE_LEN; while (*pos == ' ') pos++; reply = wpa_supplicant_global_ctrl_iface_process(global, pos, &reply_len); done: if (reply) { sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen); os_free(reply); } else if (reply_len) { sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from, fromlen); } }
static int wpa_supplicant_ctrl_iface_get_capability( struct wpa_supplicant *wpa_s, const char *_field, char *buf, size_t buflen) { struct wpa_driver_capa capa; int res, first = 1, ret; char *pos, *end, *strict; char field[30]; /* Determine whether or not strict checking was requested */ os_snprintf(field, sizeof(field), "%s", _field); field[sizeof(field) - 1] = '\0'; strict = os_strchr(field, ' '); if (strict != NULL) { *strict++ = '\0'; if (os_strcmp(strict, "strict") != 0) return -1; } wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s", field, strict ? strict : ""); if (os_strcmp(field, "eap") == 0) { return eap_get_names(buf, buflen); } res = wpa_drv_get_capa(wpa_s, &capa); pos = buf; end = pos + buflen; if (os_strcmp(field, "pairwise") == 0) { if (res < 0) { if (strict) return 0; ret = os_snprintf(buf, buflen, "CCMP TKIP NONE"); if (ret < 0 || (size_t) ret >= buflen) return -1; return ret; } if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) { ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) { ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } return pos - buf; } if (os_strcmp(field, "group") == 0) { if (res < 0) { if (strict) return 0; ret = os_snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40"); if (ret < 0 || (size_t) ret >= buflen) return -1; return ret; } if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) { ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) { ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) { ret = os_snprintf(pos, end - pos, "%sWEP104", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) { ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } return pos - buf; } if (os_strcmp(field, "key_mgmt") == 0) { if (res < 0) { if (strict) return 0; ret = os_snprintf(buf, buflen, "WPA-PSK WPA-EAP " "IEEE8021X WPA-NONE NONE"); if (ret < 0 || (size_t) ret >= buflen) return -1; return ret; } ret = os_snprintf(pos, end - pos, "NONE IEEE8021X"); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) { ret = os_snprintf(pos, end - pos, " WPA-EAP"); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { ret = os_snprintf(pos, end - pos, " WPA-PSK"); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) { ret = os_snprintf(pos, end - pos, " WPA-NONE"); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } return pos - buf; } if (os_strcmp(field, "proto") == 0) { if (res < 0) { if (strict) return 0; ret = os_snprintf(buf, buflen, "RSN WPA"); if (ret < 0 || (size_t) ret >= buflen) return -1; return ret; } if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) { ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } return pos - buf; } if (os_strcmp(field, "auth_alg") == 0) { if (res < 0) { if (strict) return 0; ret = os_snprintf(buf, buflen, "OPEN SHARED LEAP"); if (ret < 0 || (size_t) ret >= buflen) return -1; return ret; } if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) { ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) { ret = os_snprintf(pos, end - pos, "%sSHARED", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) { ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " "); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; first = 0; } return pos - buf; } wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'", field); return -1; }
static int wpa_supplicant_ctrl_iface_set_network( struct wpa_supplicant *wpa_s, char *cmd) { int id; struct wpa_ssid *ssid; char *name, *value; /* cmd: "<network id> <variable name> <value>" */ name = os_strchr(cmd, ' '); if (name == NULL) return -1; *name++ = '\0'; value = os_strchr(name, ' '); if (value == NULL) return -1; *value++ = '\0'; id = atoi(cmd); wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'", id, name); wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value", (u8 *) value, os_strlen(value)); ssid = wpa_config_get_network(wpa_s->conf, id); if (ssid == NULL) { wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network " "id=%d", id); return -1; } #ifdef ANDROID_IBSS_HACK if (os_strcmp(name, "ssid") == 0) { // check prefix if ((value[0] == '"') && (os_strncmp(value+1, ANDROID_IBSS_PREFIX, ANDROID_IBSS_PREFIX_LEN) == 0)) { if (wpa_config_set(ssid, "mode", "1", 0) < 0) { wpa_printf(MSG_DEBUG, "CTRL_IFACE: failed to set IBSS on '%s'", value); return -1; } value += ANDROID_IBSS_PREFIX_LEN; value[0] = '"'; } } #endif if (wpa_config_set(ssid, name, value, 0) < 0) { wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network " "variable '%s'", name); return -1; } else { if (os_strcmp(name, "priority") == 0) { wpa_config_update_prio_list(wpa_s->conf); } } if (wpa_s->current_ssid == ssid) { /* * Invalidate the EAP session cache if anything in the current * configuration changes. */ eapol_sm_invalidate_cached_session(wpa_s->eapol); } if ((os_strcmp(name, "psk") == 0 && value[0] == '"' && ssid->ssid_len) || (os_strcmp(name, "ssid") == 0 && ssid->passphrase)) wpa_config_update_psk(ssid); return 0; }
static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s, const char *params, char *buf, size_t buflen) { char *pos, *end, tmp[30]; int res, verbose, ret; verbose = os_strcmp(params, "-VERBOSE") == 0; pos = buf; end = buf + buflen; if (wpa_s->wpa_state >= WPA_ASSOCIATED) { struct wpa_ssid *ssid = wpa_s->current_ssid; ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n", MAC2STR(wpa_s->bssid)); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; if (ssid) { u8 *_ssid = ssid->ssid; size_t ssid_len = ssid->ssid_len; u8 ssid_buf[MAX_SSID_LEN]; if (ssid_len == 0) { int _res = wpa_drv_get_ssid(wpa_s, ssid_buf); if (_res < 0) ssid_len = 0; else ssid_len = _res; _ssid = ssid_buf; } #ifdef ANDROID_IBSS_HACK if (ssid->mode == IEEE80211_MODE_IBSS) ret = os_snprintf(pos, end - pos, "ssid=%s%s\nid=%d\n", ANDROID_IBSS_PREFIX, wpa_ssid_txt(_ssid, ssid_len), ssid->id); else #endif ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n", wpa_ssid_txt(_ssid, ssid_len), ssid->id); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; if (ssid->id_str) { ret = os_snprintf(pos, end - pos, "id_str=%s\n", ssid->id_str); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } } pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose); } ret = os_snprintf(pos, end - pos, "wpa_state=%s\n", wpa_supplicant_state_txt(wpa_s->wpa_state)); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; if (wpa_s->l2 && l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) { ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp); if (ret < 0 || ret >= end - pos) return pos - buf; pos += ret; } if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X || wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos, verbose); if (res >= 0) pos += res; } res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose); if (res >= 0) pos += res; return pos - buf; }
/** * * @param params * @param req_id * @return */ int ICACHE_FLASH_ATTR dispatcher_t::wifiConnect(JVal* params, int32_t req_id) { // {"jsonrpc": "2.0", "method": "wifi_connect", "params": {"ssid": "MySSID", "password": "******"}, "id": 100} uint16_t flag = 0; /****************************************************************************************************************** * extract data from JSON-RPC request * */ const char* ssid = 0; const char* password = 0; m_Err->reset(); JVal* jv = params; // extract all data while(jv != 0) { const char* name = jv->getName(); if(os_strcmp("ssid", name) == 0) { DTXT("%lu dispatcher_t::wifiConnect(): ssid\n", millis()); ssid = jv->getString(m_Err); flag |= _WIFI_SSID; } else if(os_strcmp("password", name) == 0) { DTXT("%lu dispatcher_t::wifiConnect(): password\n", millis()); password = jv->getString(m_Err); flag |= _WIFI_PSW; } else { DTXT("%lu dispatcher_t::mqttConnect(): unknown = %s\n", millis(), name); } // check for errors if(m_Err->isError()) { os()->jsonRpc()->errorReply(EJSON_DECODER, req_id, "JSON decoder error; %s", m_Err->msg); return EJSON_DECODER; } jv = jv->getNextElem(); } /****************************************************************************************************************** * start connection * */ int ret = EOK; if((flag & _WIFI_SSID) == _WIFI_SSID) { m_Wifi->connect(ssid, password); os()->jsonRpc()->successReply(req_id, "0"); } else { ret = EWIFI_SSID; os()->jsonRpc()->errorReply(ret, req_id, "no ssid specified"); } return ret; }
static void anqp_add_osu_provider(struct wpabuf *buf, struct hostapd_bss_config *bss, struct hs20_osu_provider *p) { u8 *len, *len2, *count; unsigned int i; len = wpabuf_put(buf, 2); /* OSU Provider Length to be filled */ /* OSU Friendly Name Duples */ len2 = wpabuf_put(buf, 2); for (i = 0; i < p->friendly_name_count; i++) { struct hostapd_lang_string *s = &p->friendly_name[i]; wpabuf_put_u8(buf, 3 + s->name_len); wpabuf_put_data(buf, s->lang, 3); wpabuf_put_data(buf, s->name, s->name_len); } WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2); /* OSU Server URI */ if (p->server_uri) { wpabuf_put_u8(buf, os_strlen(p->server_uri)); wpabuf_put_str(buf, p->server_uri); } else wpabuf_put_u8(buf, 0); /* OSU Method List */ count = wpabuf_put(buf, 1); for (i = 0; p->method_list[i] >= 0; i++) wpabuf_put_u8(buf, p->method_list[i]); *count = i; /* Icons Available */ len2 = wpabuf_put(buf, 2); for (i = 0; i < p->icons_count; i++) { size_t j; struct hs20_icon *icon = NULL; for (j = 0; j < bss->hs20_icons_count && !icon; j++) { if (os_strcmp(p->icons[i], bss->hs20_icons[j].name) == 0) icon = &bss->hs20_icons[j]; } if (!icon) continue; /* icon info not found */ wpabuf_put_le16(buf, icon->width); wpabuf_put_le16(buf, icon->height); wpabuf_put_data(buf, icon->language, 3); wpabuf_put_u8(buf, os_strlen(icon->type)); wpabuf_put_str(buf, icon->type); wpabuf_put_u8(buf, os_strlen(icon->name)); wpabuf_put_str(buf, icon->name); } WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2); /* OSU_NAI */ if (p->osu_nai) { wpabuf_put_u8(buf, os_strlen(p->osu_nai)); wpabuf_put_str(buf, p->osu_nai); } else wpabuf_put_u8(buf, 0); /* OSU Service Description Duples */ len2 = wpabuf_put(buf, 2); for (i = 0; i < p->service_desc_count; i++) { struct hostapd_lang_string *s = &p->service_desc[i]; wpabuf_put_u8(buf, 3 + s->name_len); wpabuf_put_data(buf, s->lang, 3); wpabuf_put_data(buf, s->name, s->name_len); } WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2); WPA_PUT_LE16(len, (u8 *) wpabuf_put(buf, 0) - len - 2); }
/** * * @param params * @param req_id * @return */ int ICACHE_FLASH_ATTR dispatcher_t::mqttConnect(JVal* params, int32_t req_id) { // {"jsonrpc": "2.0", "method": "mqtt_connect", "params": {"broker": "192.168.1.82", "port": 1883, "secure": false, "client_id": "esp8266_client", "username": "", "password": "", "keep_alive": 30}, "id": 1} // {"jsonrpc": "2.0", "method": "mqtt_connect", "params": {"broker": "test.mosquitto.org", "port": 1883, "secure": false, "client_id": "esp8266_client", "username": "", "password": "", "keep_alive": 60}, "id": 1} // {"jsonrpc": "2.0", "method": "mqtt_connect", "params": {"broker": "iot.eclipse.org", "port": 1883, "secure": false, "client_id": "esp8266_client", "username": "", "password": "", "keep_alive": 60}, "id": 1} if(m_Wifi->isConnected() == false) { os()->jsonRpc()->errorReply(EWIFI_NOT_CONNECTED, req_id, "wifi not connected"); return EWIFI_NOT_CONNECTED; } uint16_t flag = 0; /****************************************************************************************************************** * extract data from JSON-RPC request * */ const char* broker = 0; int port = 1883; BaBool secure = false; const char* client_id = 0; const char* username = 0; const char* password = 0; int keep_alive = 60; const char* lwt_topic = 0; const char* lwt_payload = 0; int lwt_qos = 0; BaBool lwt_retain = false; BaBool clean_session = false; m_Err->reset(); JVal* jv = params; // extract all data while(jv != 0) { const char* name = jv->getName(); if(os_strcmp("broker", name) == 0) { broker = jv->getString(m_Err); flag |= _CONN_BROKER; DTXT("%lu dispatcher_t::mqttConnect(): broker = %s\n", millis(), broker); } else if(os_strcmp("port", name) == 0) { port = jv->getInt(m_Err); flag |= _CONN_PORT; DTXT("%lu dispatcher_t::mqttConnect(): port = %d\n", millis(), port); } else if(os_strcmp("secure", name) == 0) { secure = jv->getBoolean(m_Err); flag |= _CONN_SECURE; DTXT("%lu dispatcher_t::mqttConnect(): secure = %s\n", millis(), secure ? "True" : "False"); } else if(os_strcmp("client_id", name) == 0) { client_id = jv->getString(m_Err); flag |= _CONN_CLIENT_ID; DTXT("%lu dispatcher_t::mqttConnect(): client_id = %s\n", millis(), client_id); } else if(os_strcmp("username", name) == 0) { username = jv->getString(m_Err); flag |= _CONN_USERNAME; DTXT("%lu dispatcher_t::mqttConnect(): username = %s\n", millis(), username); } else if(os_strcmp("password", name) == 0) { password = jv->getString(m_Err); flag |= _CONN_PASSWORD; DTXT("%lu dispatcher_t::mqttConnect(): password = %s\n", millis(), password); } else if(os_strcmp("keep_alive", name) == 0) { keep_alive = jv->getInt(m_Err); flag |= _CONN_KEEP_ALIVE; DTXT("%lu dispatcher_t::mqttConnect(): keep_alive = %d\n", millis(), keep_alive); } else if(os_strcmp("lwt_topic", name) == 0) { lwt_topic = jv->getString(m_Err); DTXT("%lu dispatcher_t::mqttConnect(): lwt_topic = %s\n", millis(), lwt_topic); } else if(os_strcmp("lwt_payload", name) == 0) { lwt_payload = jv->getString(m_Err); DTXT("%lu dispatcher_t::mqttConnect(): lwt_payload = %s\n", millis(), lwt_payload); } else if(os_strcmp("lwt_qos", name) == 0) { lwt_qos = jv->getInt(m_Err); DTXT("%lu dispatcher_t::mqttConnect(): lwt_qos = %d\n", millis(), lwt_qos); } else if(os_strcmp("lwt_retain", name) == 0) { lwt_retain = jv->getBoolean(m_Err); DTXT("%lu dispatcher_t::mqttConnect(): lwt_retain = %s\n", millis(), lwt_retain ? "True" : "False"); } else if(os_strcmp("clean_session", name) == 0) { clean_session = jv->getBoolean(m_Err); DTXT("%lu dispatcher_t::mqttConnect(): clean_session = %s\n", millis(), clean_session ? "True" : "False"); } else { DTXT("%lu dispatcher_t::mqttConnect(): unknown = %s\n", millis(), name); } // check for errors if(m_Err->isError()) { os()->jsonRpc()->errorReply(EJSON_DECODER, req_id, "JSON decoder error; %s", m_Err->msg); return EJSON_DECODER; } jv = jv->getNextElem(); } //DTXT("%lu dispatcher_t::mqttConnect(): *1*\n", millis()); //os_delay_us(2000000); /****************************************************************************************************************** * start connection * */ int ret = EOK; if(((flag & _CONN_BROKER) == _CONN_BROKER) && ((flag & _CONN_CLIENT_ID) == _CONN_CLIENT_ID)) { int slot = m_MqttClient.getFreeSlot(); if(slot != EAVAILABLE_SLOT) { DTXT("%lu dispatcher_t::mqttConnect(): connecting\n", millis()); if(m_MqttClient.connect(slot, broker, port, client_id, username, password, keep_alive, lwt_topic, lwt_payload, lwt_qos, lwt_retain, clean_session, secure) == 0) { os()->jsonRpc()->successReply(req_id, "%d", slot); } else { ret = ECONNECTION_INFO; os()->jsonRpc()->errorReply(ret, req_id, "failed to set connection info"); } } else { ret = EAVAILABLE_SLOT; os()->jsonRpc()->errorReply(ret, req_id, "no available connection slot"); } } else { ret = EBROKER_CLIENT; os()->jsonRpc()->errorReply(ret, req_id, "no broker and/or client_id specified"); } return ret; }
static int test_nist_key_wrap_ad(const char *fname) { FILE *f; int ret = 0; char buf[15000], *pos, *pos2; u8 bin[2000], k[32], p[1024], c[1024 + 8], result[1024 + 8]; size_t bin_len, k_len = 0, p_len = 0, c_len = 0; int ok = 0; int fail; printf("NIST KW AD tests from %s\n", fname); f = fopen(fname, "r"); if (f == NULL) { printf("%s does not exist - cannot validate test vectors\n", fname); return 1; } while (fgets(buf, sizeof(buf), f)) { if (buf[0] == '#') continue; fail = 0; pos = os_strchr(buf, '='); if (pos == NULL) { if (os_strncmp(buf, "FAIL", 4) == 0) { fail = 1; goto skip_val_parse; } continue; } pos2 = pos - 1; while (pos2 >= buf && *pos2 == ' ') *pos2-- = '\0'; *pos++ = '\0'; while (*pos == ' ') *pos++ = '\0'; pos2 = os_strchr(pos, '\r'); if (!pos2) pos2 = os_strchr(pos, '\n'); if (pos2) *pos2 = '\0'; else pos2 = pos + os_strlen(pos); if (buf[0] == '[') { printf("%s = %s\n", buf, pos); continue; } if (os_strcmp(buf, "COUNT") == 0) { printf("Test %s - ", pos); continue; } bin_len = os_strlen(pos); if (bin_len > sizeof(bin) * 2) { printf("Too long binary data (%s)\n", buf); return 1; } if (bin_len & 0x01) { printf("Odd number of hexstring values (%s)\n", buf); return 1; } bin_len /= 2; if (hexstr2bin(pos, bin, bin_len) < 0) { printf("Invalid hex string '%s' (%s)\n", pos, buf); return 1; } if (os_strcmp(buf, "K") == 0) { if (bin_len > sizeof(k)) { printf("Too long K (%u)\n", (unsigned) bin_len); return 1; } os_memcpy(k, bin, bin_len); k_len = bin_len; continue; } if (os_strcmp(buf, "C") == 0) { if (bin_len > sizeof(c)) { printf("Too long C (%u)\n", (unsigned) bin_len); return 1; } os_memcpy(c, bin, bin_len); c_len = bin_len; continue; } skip_val_parse: if (!fail) { if (os_strcmp(buf, "P") != 0) { printf("Unexpected field '%s'\n", buf); continue; } if (bin_len > sizeof(p)) { printf("Too long P (%u)\n", (unsigned) bin_len); return 1; } os_memcpy(p, bin, bin_len); p_len = bin_len; if (p_len % 8 != 0 || c_len % 8 != 0 || c_len - p_len != 8) { printf("invalid parameter length (p_len=%u c_len=%u)\n", (unsigned) p_len, (unsigned) c_len); continue; } } if (aes_unwrap(k, k_len, (c_len / 8) - 1, c, result)) { if (fail) { printf("OK (fail reported)\n"); ok++; continue; } printf("aes_unwrap() failed\n"); ret++; continue; } if (fail) { printf("FAIL (mismatch not reported)\n"); ret++; } else if (os_memcmp(p, result, p_len) == 0) { printf("OK\n"); ok++; } else { printf("FAIL\n"); ret++; } } fclose(f); if (ret) printf("Test case failed\n"); else printf("%d test vectors OK\n", ok); return ret; }
/** * * @param params * @param req_id * @return */ int ICACHE_FLASH_ATTR dispatcher_t::mqttUnsubscribe(JVal* params, int32_t req_id) { // {"jsonrpc": "2.0", "method": "mqtt_unsubscribe", "params": {"id": 0, "topic": "fabric/esp8266/ingress/#"}, "id": 5} if(m_Wifi->isConnected() == false) { os()->jsonRpc()->errorReply(EWIFI_NOT_CONNECTED, req_id, "wifi not connected"); return EWIFI_NOT_CONNECTED; } uint16_t flag = 0; /****************************************************************************************************************** * extract data from JSON-RPC request * */ int slot = -1; const char* topic = 0; m_Err->reset(); JVal* jv = params; // extract all data while(jv != 0) { const char* name = jv->getName(); if(os_strcmp("id", name) == 0) { DTXT("%lu dispatcher_t::mqttSubscribe(): slot\n", millis()); slot = jv->getInt(m_Err); flag |= _USUB_SLOT; } else if(os_strcmp("topic", name) == 0) { DTXT("%lu dispatcher_t::mqttSubscribe(): topic\n", millis()); topic = jv->getString(m_Err); flag |= _USUB_TOPIC; } else { DTXT("%lu dispatcher_t::mqttSubscribe(): unknown = %s\n", millis(), name); } // check for errors if(m_Err->isError()) { os()->jsonRpc()->errorReply(EJSON_DECODER, req_id, "JSON decoder error; %s", m_Err->msg); return EJSON_DECODER; } jv = jv->getNextElem(); } /****************************************************************************************************************** * start unsubscribe * */ int ret = EOK; if(((flag & _USUB_SLOT) == _USUB_SLOT) && ((flag & _USUB_TOPIC) == _USUB_TOPIC)) { if(slot >= 0 && slot < m_MqttClient.getMaxConnections()) { ret = m_MqttClient.unsubscribe(slot, topic); if(ret == EOK) { os()->jsonRpc()->successReply(req_id, "%d", slot); } else { os()->jsonRpc()->errorReply(ret, req_id, "unsubscribe error"); } } else { ret = EID; os()->jsonRpc()->errorReply(ret, req_id, "invalid id"); } } else { ret = EMISSING_PARAMETER; os()->jsonRpc()->errorReply(ret, req_id, "no id and/or topic specified"); } return ret; }
static void ctrl_add_passphrase(struct wlantest *wt, int sock, u8 *cmd, size_t clen) { u8 *passphrase; size_t len; struct wlantest_passphrase *p, *pa; u8 *bssid; passphrase = attr_get(cmd, clen, WLANTEST_ATTR_PASSPHRASE, &len); if (passphrase == NULL) { u8 *wepkey; char *key; enum wlantest_ctrl_cmd res; wepkey = attr_get(cmd, clen, WLANTEST_ATTR_WEPKEY, &len); if (wepkey == NULL) { ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD); return; } key = os_zalloc(len + 1); if (key == NULL) { ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE); return; } os_memcpy(key, wepkey, len); if (add_wep(wt, key) < 0) res = WLANTEST_CTRL_FAILURE; else res = WLANTEST_CTRL_SUCCESS; os_free(key); ctrl_send_simple(wt, sock, res); return; } if (len < 8 || len > 63) { ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD); return; } p = os_zalloc(sizeof(*p)); if (p == NULL) { ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE); return; } os_memcpy(p->passphrase, passphrase, len); wpa_printf(MSG_INFO, "Add passphrase '%s'", p->passphrase); bssid = attr_get_macaddr(cmd, clen, WLANTEST_ATTR_BSSID); if (bssid) { os_memcpy(p->bssid, bssid, ETH_ALEN); wpa_printf(MSG_INFO, "Limit passphrase for BSSID " MACSTR, MAC2STR(p->bssid)); } dl_list_for_each(pa, &wt->passphrase, struct wlantest_passphrase, list) { if (os_strcmp(p->passphrase, pa->passphrase) == 0 && os_memcmp(p->bssid, pa->bssid, ETH_ALEN) == 0) { wpa_printf(MSG_INFO, "Passphrase was already known"); os_free(p); p = NULL; break; } } if (p) { struct wlantest_bss *bss; dl_list_add(&wt->passphrase, &p->list); dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) { if (bssid && os_memcmp(p->bssid, bss->bssid, ETH_ALEN) != 0) continue; bss_add_pmk_from_passphrase(bss, p->passphrase); } } ctrl_send_simple(wt, sock, WLANTEST_CTRL_SUCCESS); }
static int scard_get_triplets(int argc, char *argv[]) { struct scard_data *scard; size_t len; char imsi[20]; unsigned char _rand[16]; unsigned char sres[4]; unsigned char kc[8]; int num_triplets; int i; size_t j; if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) { printf("invalid parameters for sim command\n"); return -1; } if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) { /* disable debug output */ wpa_debug_level = 99; } scard = scard_init(SCARD_GSM_SIM_ONLY); if (scard == NULL) { printf("Failed to open smartcard connection\n"); return -1; } if (scard_set_pin(scard, argv[0])) { wpa_printf(MSG_WARNING, "PIN validation failed"); scard_deinit(scard); return -1; } len = sizeof(imsi); if (scard_get_imsi(scard, imsi, &len)) { scard_deinit(scard); return -1; } for (i = 0; i < num_triplets; i++) { os_memset(_rand, i, sizeof(_rand)); if (scard_gsm_auth(scard, _rand, sres, kc)) break; /* IMSI:Kc:SRES:RAND */ for (j = 0; j < len; j++) printf("%c", imsi[j]); printf(":"); for (j = 0; j < 8; j++) printf("%02X", kc[j]); printf(":"); for (j = 0; j < 4; j++) printf("%02X", sres[j]); printf(":"); for (j = 0; j < 16; j++) printf("%02X", _rand[j]); printf("\n"); } scard_deinit(scard); return 0; }
int eapol_auth_set_conf(struct eapol_state_machine *sm, const char *param, const char *value) { wpa_printf(MSG_DEBUG, "EAPOL: External configuration operation for " MACSTR " - param=%s value=%s", MAC2STR(sm->addr), param, value); if (os_strcasecmp(param, "AdminControlledDirections") == 0) { if (os_strcmp(value, "Both") == 0) sm->adminControlledDirections = Both; else if (os_strcmp(value, "In") == 0) sm->adminControlledDirections = In; else return -1; eapol_auth_step(sm); return 0; } if (os_strcasecmp(param, "AdminControlledPortControl") == 0) { if (os_strcmp(value, "ForceAuthorized") == 0) sm->portControl = ForceAuthorized; else if (os_strcmp(value, "ForceUnauthorized") == 0) sm->portControl = ForceUnauthorized; else if (os_strcmp(value, "Auto") == 0) sm->portControl = Auto; else return -1; eapol_auth_step(sm); return 0; } if (os_strcasecmp(param, "quietPeriod") == 0) { sm->quietPeriod = atoi(value); return 0; } if (os_strcasecmp(param, "serverTimeout") == 0) { sm->serverTimeout = atoi(value); return 0; } if (os_strcasecmp(param, "reAuthPeriod") == 0) { sm->reAuthPeriod = atoi(value); return 0; } if (os_strcasecmp(param, "reAuthEnabled") == 0) { if (os_strcmp(value, "TRUE") == 0) sm->reAuthEnabled = TRUE; else if (os_strcmp(value, "FALSE") == 0) sm->reAuthEnabled = FALSE; else return -1; eapol_auth_step(sm); return 0; } if (os_strcasecmp(param, "KeyTransmissionEnabled") == 0) { if (os_strcmp(value, "TRUE") == 0) sm->keyTxEnabled = TRUE; else if (os_strcmp(value, "FALSE") == 0) sm->keyTxEnabled = FALSE; else return -1; eapol_auth_step(sm); return 0; } return -1; }
int hostapd_drv_none(struct hostapd_data *hapd) { return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0; }
struct wpa_config * wpa_config_read(const char *name) { FILE *f; char buf[256], *pos; int errors = 0, line = 0; struct wpa_ssid *ssid, *tail = NULL, *head = NULL; struct wpa_config *config; int id = 0; config = wpa_config_alloc_empty(NULL, NULL); if (config == NULL) return NULL; wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name); f = fopen(name, "r"); if (f == NULL) { os_free(config); return NULL; } while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) { if (os_strcmp(pos, "network={") == 0) { ssid = wpa_config_read_network(f, &line, id++); if (ssid == NULL) { wpa_printf(MSG_ERROR, "Line %d: failed to " "parse network block.", line); #ifndef WPA_IGNORE_CONFIG_ERRORS errors++; #endif continue; } if (head == NULL) { head = tail = ssid; } else { tail->next = ssid; tail = ssid; } if (wpa_config_add_prio_network(config, ssid)) { wpa_printf(MSG_ERROR, "Line %d: failed to add " "network block to priority list.", line); errors++; continue; } } else if (os_strncmp(pos, "blob-base64-", 12) == 0) { char *bname = pos + 12, *name_end; struct wpa_config_blob *blob; name_end = os_strchr(bname, '='); if (name_end == NULL) { wpa_printf(MSG_ERROR, "Line %d: no blob name " "terminator", line); errors++; continue; } *name_end = '\0'; blob = wpa_config_read_blob(f, &line, bname); if (blob == NULL) { wpa_printf(MSG_ERROR, "Line %d: failed to read" " blob %s", line, bname); errors++; continue; } wpa_config_set_blob(config, blob); #ifdef CONFIG_CTRL_IFACE } else if (os_strncmp(pos, "ctrl_interface=", 15) == 0) { os_free(config->ctrl_interface); config->ctrl_interface = os_strdup(pos + 15); wpa_printf(MSG_DEBUG, "ctrl_interface='%s'", config->ctrl_interface); } else if (os_strncmp(pos, "ctrl_interface_group=", 21) == 0) { os_free(config->ctrl_interface_group); config->ctrl_interface_group = os_strdup(pos + 21); wpa_printf(MSG_DEBUG, "ctrl_interface_group='%s' " "(DEPRECATED)", config->ctrl_interface_group); #endif /* CONFIG_CTRL_IFACE */ } else if (os_strncmp(pos, "eapol_version=", 14) == 0) { config->eapol_version = atoi(pos + 14); if (config->eapol_version < 1 || config->eapol_version > 2) { wpa_printf(MSG_ERROR, "Line %d: Invalid EAPOL " "version (%d): '%s'.", line, config->eapol_version, pos); errors++; continue; } wpa_printf(MSG_DEBUG, "eapol_version=%d", config->eapol_version); } else if (os_strncmp(pos, "ap_scan=", 8) == 0) { config->ap_scan = atoi(pos + 8); wpa_printf(MSG_DEBUG, "ap_scan=%d", config->ap_scan); } else if (os_strncmp(pos, "fast_reauth=", 12) == 0) { config->fast_reauth = atoi(pos + 12); wpa_printf(MSG_DEBUG, "fast_reauth=%d", config->fast_reauth); } else if (os_strncmp(pos, "opensc_engine_path=", 19) == 0) { os_free(config->opensc_engine_path); config->opensc_engine_path = os_strdup(pos + 19); wpa_printf(MSG_DEBUG, "opensc_engine_path='%s'", config->opensc_engine_path); } else if (os_strncmp(pos, "pkcs11_engine_path=", 19) == 0) { os_free(config->pkcs11_engine_path); config->pkcs11_engine_path = os_strdup(pos + 19); wpa_printf(MSG_DEBUG, "pkcs11_engine_path='%s'", config->pkcs11_engine_path); } else if (os_strncmp(pos, "pkcs11_module_path=", 19) == 0) { os_free(config->pkcs11_module_path); config->pkcs11_module_path = os_strdup(pos + 19); wpa_printf(MSG_DEBUG, "pkcs11_module_path='%s'", config->pkcs11_module_path); } else if (os_strncmp(pos, "driver_param=", 13) == 0) { os_free(config->driver_param); config->driver_param = os_strdup(pos + 13); wpa_printf(MSG_DEBUG, "driver_param='%s'", config->driver_param); } else if (os_strncmp(pos, "dot11RSNAConfigPMKLifetime=", 27) == 0) { config->dot11RSNAConfigPMKLifetime = atoi(pos + 27); wpa_printf(MSG_DEBUG, "dot11RSNAConfigPMKLifetime=%d", config->dot11RSNAConfigPMKLifetime); } else if (os_strncmp(pos, "dot11RSNAConfigPMKReauthThreshold=", 34) == 0) { config->dot11RSNAConfigPMKReauthThreshold = atoi(pos + 34); wpa_printf(MSG_DEBUG, "dot11RSNAConfigPMKReauthThreshold=%d", config->dot11RSNAConfigPMKReauthThreshold); } else if (os_strncmp(pos, "dot11RSNAConfigSATimeout=", 25) == 0) { config->dot11RSNAConfigSATimeout = atoi(pos + 25); wpa_printf(MSG_DEBUG, "dot11RSNAConfigSATimeout=%d", config->dot11RSNAConfigSATimeout); } else if (os_strncmp(pos, "update_config=", 14) == 0) { config->update_config = atoi(pos + 14); wpa_printf(MSG_DEBUG, "update_config=%d", config->update_config); } else if (os_strncmp(pos, "load_dynamic_eap=", 17) == 0) { char *so = pos + 17; int ret; wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so); ret = eap_peer_method_load(so); if (ret == -2) { wpa_printf(MSG_DEBUG, "This EAP type was " "already loaded - not reloading."); } else if (ret) { wpa_printf(MSG_ERROR, "Line %d: Failed to " "load dynamic EAP method '%s'.", line, so); errors++; } } else { wpa_printf(MSG_ERROR, "Line %d: Invalid configuration " "line '%s'.", line, pos); errors++; continue; } } fclose(f); config->ssid = head; wpa_config_debug_dump_networks(config); #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { wpa_config_free(config); config = NULL; head = NULL; } #endif return config; }
/* espFsOpen */ EspFsFile ICACHE_FLASH_ATTR * espFsOpen(char * pszFilename) { /* initialization */ char * pbHeaderOffset = NULL; char * pbTmpFile = NULL; EspFsFile * ptEspFile = NULL; char pszFileNameBuffer[256] = { 0 }; EspFsHeader tEspFileHeader = { 0 }; /* acquire file system beginning */ #ifndef ESPFS_TEST int iEspFsOffset = 0; if (0 == system_upgrade_userbin_check()) { iEspFsOffset = partition[ESPFS_PART].iOffset; } else { iEspFsOffset = partition[ESPFS_PART2].iOffset; } pbTmpFile = (char *)(iEspFsOffset + ESP_FLASH_OFFSET); #else pbTmpFile = espFsData; #endif /* strip file name slashes */ while (SLASH_SYMBOL_STRING == pszFilename[0]) { ++pszFilename; } /* locate file */ while (1) { pbHeaderOffset = pbTmpFile; /* retrieve file header */ os_memcpy(&tEspFileHeader, pbTmpFile, sizeof(EspFsHeader)); if (ESPFS_MAGIC_HEADER != tEspFileHeader.magic) { #ifdef ESPFS_DEBUG os_printf("espFsOpen: magic mismatch - file system image broken. found 0x%x instead\n", tEspFileHeader.magic); #endif ptEspFile = NULL; goto lblCleanup; } if (tEspFileHeader.flags & FLAG_LASTFILE) { #ifdef ESPFS_DEBUG os_printf("espFsOpen: end of image reached\n"); #endif ptEspFile = NULL; goto lblCleanup; } /* acquire file name */ pbTmpFile += sizeof(EspFsHeader); os_memcpy(pszFileNameBuffer, pbTmpFile, sizeof(pszFileNameBuffer)); #ifdef ESPFS_DEBUG os_printf("espFsOpen: found file '%s'\nname length = %x, file length compressed = %x, compression = %d flags = %d\n", pszFileNameBuffer, (unsigned int)tEspFileHeader.nameLen, (unsigned int)tEspFileHeader.fileLenComp, tEspFileHeader.compression, tEspFileHeader.flags); #endif if (0 == os_strcmp(pszFileNameBuffer, pszFilename)) { /* desired file */ /* skip to content */ pbTmpFile += tEspFileHeader.nameLen; /* allocate file descriptor */ ptEspFile = (EspFsFile *)os_malloc(sizeof(EspFsFile)); #ifdef ESPFS_DEBUG os_printf("espFsOpen: file descriptor allocated at %p\n", ptEspFile); #endif if (NULL == ptEspFile) { goto lblCleanup; } /* fill file descriptor */ ptEspFile->header = (EspFsHeader *)pbHeaderOffset; ptEspFile->decompressor = tEspFileHeader.compression; ptEspFile->posComp = pbTmpFile; ptEspFile->posStart = pbTmpFile; ptEspFile->posDecomp = 0; if (COMPRESS_NONE == tEspFileHeader.compression) { ptEspFile->decompData = NULL; #ifdef EFS_HEATSHRINK } else if (COMPRESS_HEATSHRINK == tEspFileHeader.compression) { /* compression used */ char bDecoderParameter = { 0 }; heatshrink_decoder * ptDecoder = NULL; /* acquire decoder parameters - 1st byte */ memcpyAligned(&bDecoderParameter, ptEspFile->posComp, 1); ++ptEspFile->posComp; #ifdef HEATSHRINK_DEBUG os_printf("espFsOpen: heatshrink compressed file, decoder parameters = %x\n", bDecoderParameter); #endif ptDecoder = heatshrink_decoder_alloc(16, (bDecoderParameter >> 4) & 0xf, bDecoderParameter & 0xf); ptEspFile->decompData = ptDecoder; #endif } else {
static int hostapd_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[]) { if (argc > 0 && os_strcmp(argv[0], "driver") == 0) return wpa_ctrl_command(ctrl, "STATUS-DRIVER"); return wpa_ctrl_command(ctrl, "STATUS"); }
struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp) { FILE *f; char buf[512], *pos; int errors = 0, line = 0; struct wpa_ssid *ssid, *tail = NULL, *head = NULL; struct wpa_cred *cred, *cred_tail = NULL, *cred_head = NULL; struct wpa_config *config; int id = 0; int cred_id = 0; if (name == NULL) return NULL; if (cfgp) config = cfgp; else config = wpa_config_alloc_empty(NULL, NULL); if (config == NULL) { wpa_printf(MSG_ERROR, "Failed to allocate config file " "structure"); return NULL; } head = config->ssid; cred_head = config->cred; wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name); f = fopen(name, "r"); if (f == NULL) { wpa_printf(MSG_ERROR, "Failed to open config file '%s', " "error: %s", name, strerror(errno)); os_free(config); return NULL; } while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) { if (os_strcmp(pos, "network={") == 0) { ssid = wpa_config_read_network(f, &line, id++); if (ssid == NULL) { wpa_printf(MSG_ERROR, "Line %d: failed to " "parse network block.", line); errors++; continue; } if (head == NULL) { head = tail = ssid; } else { tail->next = ssid; tail = ssid; } if (wpa_config_add_prio_network(config, ssid)) { wpa_printf(MSG_ERROR, "Line %d: failed to add " "network block to priority list.", line); errors++; continue; } } else if (os_strcmp(pos, "cred={") == 0) { cred = wpa_config_read_cred(f, &line, cred_id++); if (cred == NULL) { wpa_printf(MSG_ERROR, "Line %d: failed to " "parse cred block.", line); errors++; continue; } if (cred_head == NULL) { cred_head = cred_tail = cred; } else { cred_tail->next = cred; cred_tail = cred; } #ifndef CONFIG_NO_CONFIG_BLOBS } else if (os_strncmp(pos, "blob-base64-", 12) == 0) { if (wpa_config_process_blob(config, f, &line, pos + 12) < 0) { wpa_printf(MSG_ERROR, "Line %d: failed to " "process blob.", line); errors++; continue; } #endif /* CONFIG_NO_CONFIG_BLOBS */ } else if (wpa_config_process_global(config, pos, line) < 0) { wpa_printf(MSG_ERROR, "Line %d: Invalid configuration " "line '%s'.", line, pos); errors++; continue; } } fclose(f); config->ssid = head; wpa_config_debug_dump_networks(config); config->cred = cred_head; #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { wpa_config_free(config); config = NULL; head = NULL; } #endif /* WPA_IGNORE_CONFIG_ERRORS */ return config; }
/** * * @param e */ void ICACHE_FLASH_ATTR dispatcher_t::runTask(os_event_t* e) { if(m_FirstRun == true) { m_FirstRun = false; os_printf("{\"jsonrpc\":\"2.0\",\"method\":\"system\",\"params\":{\"code\":1,\"sys\":\"system\",\"msg\":\"start\",\"p1\":null,\"p2\":null,\"n1\":0,\"n2\":0}}\n"); } m_MqttClient.run(m_Seconds); int c = uart0_rx_one_char(); // // TODO: handle too-long interval between indivdual characters - reset parser if interval too long // if(c != -1) { int ret = os()->jsonRpc()->parse(c); if(ret == EJSON_METHOD) { DTXT("%lu dispatcher_t::runTask(): parse() == EJSON_METHOD\n", millis()); if(os_strcmp("mqtt_connect", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; mqtt_connect\n", millis()); mqttConnect(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("mqtt_disconnect", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; mqtt_disconnect\n", millis()); mqttDisconnect(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("mqtt_publish", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; mqtt_publish\n", millis()); mqttPublish(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("mqtt_subscribe", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; mqtt_subscribe\n", millis()); mqttSubscribe(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("mqtt_unsubscribe", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; mqtt_unsubscribe\n", millis()); mqttUnsubscribe(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("wifi_connect", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; wifi_connect\n", millis()); wifiConnect(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("wifi_disconnect", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; wifi_disconnect\n", millis()); wifiDisconnect(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("wifi_scan", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; wifi_scan\n", millis()); wifiScan(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("sys_nop", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; sys_nop\n", millis()); sysNop(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else if(os_strcmp("sys_restart", os()->jsonRpc()->getMethod()) == 0) { DTXT("%lu dispatcher_t::runTask(): parse; sys_restart\n", millis()); sysRestart(os()->jsonRpc()->getParams(), os()->jsonRpc()->getMsgId()); } else { DTXT("%lu dispatcher_t::runTask(): parse; unknown\n", millis()); } os()->jsonRpc()->parseReset(); } else if(ret == EJSON_ERROR) { DTXT("%lu dispatcher_t::runTask(): parse; ret == EJSON_ERROR\n", millis()); } else if(ret == EJSON_RESULT) { DTXT("%lu dispatcher_t::runTask(): parse; ret == EJSON_RESULT\n", millis()); } else if(ret != EJSON_PARSE_INCOMPLETE && ret != EJSON_PARSE_ERR) { DTXT("%lu dispatcher_t::runTask(): parse; ret != EJSON_PARSE_INCOMPLETE && ret != EJSON_PARSE_ERR (%d)\n", millis(), ret); } } #if defined(WITH_TESTCODE) int qos = 0; if(millis() - m_LastRun >= getRunInterval()) { DTXT("%lu dispatcher_t::runTask(): time to publish; freeHeap = %lu\n", millis(), os()->freeHeap()); static char txt[60]; os_sprintf(txt, "{\"seconds\":%lu,\"contact\":\"[email protected]\"}", m_Seconds); for(int i = 0; i < m_MqttClient.getMaxConnections() - 1; ++i) { DTXT("%lu dispatcher_t::runTask(): m_Command = %d, m_Status = %d\n", millis(), m_MqttClient.getCommand(i), m_MqttClient.getStatus(i)); if(m_MqttClient.isReady(i) == 1) { DTXT("%lu dispatcher_t::runTask(): slot %d is connected\n", millis(), i); if(m_MqttClient.publish(i, "fabric/esp8266/seconds", txt, os_strlen(txt), qos, MQTT_RETAIN) != 0) { DTXT("%lu dispatcher_t::runTask(): could not publish\n", millis()); } } } m_LastRun = millis(); ++m_Seconds; } static int x0 = 0; static int x1 = 0; static int x2 = 0; static int x3 = 0; if(x0 == 0 && m_MqttClient.isReady(0) == 1) { if(m_MqttClient.publish(0, "fabric/esp8266/status", "online", 6, qos, MQTT_RETAIN) != 0) { DTXT("%lu dispatcher_t::runTask(): could not publish\n", millis()); } else { ++x0; } } if(x1 == 0 && m_MqttClient.isReady(1) == 1) { if(m_MqttClient.publish(1, "fabric/esp8266/status", "online", 6, qos, MQTT_RETAIN) != 0) { DTXT("%lu dispatcher_t::runTask(): could not publish\n", millis()); } else { ++x1; } } if(x2 == 0 && m_MqttClient.isReady(2) == 1) { if(m_MqttClient.publish(2, "fabric/esp8266/status", "online", 6, qos, MQTT_RETAIN) != 0) { DTXT("%lu dispatcher_t::runTask(): could not publish\n", millis()); } else { ++x2; } } if(x3 == 0 && m_MqttClient.isReady(3) == 1) { if(m_MqttClient.publish(3, "fabric/esp8266/status", "online", 6, qos, MQTT_RETAIN) != 0) { DTXT("%lu dispatcher_t::runTask(): could not publish\n", millis()); } else { ++x3; } } #else if(millis() - m_LastRun >= getRunInterval()) { m_LastRun = millis(); ++m_Seconds; } #endif }
int main(int argc, char *argv[]) { int warning_displayed = 0; int c; int daemonize = 0; if (os_program_init()) return -1; for (;;) { c = getopt(argc, argv, "a:BhG:i:p:v"); if (c < 0) break; switch (c) { case 'a': action_file = optarg; break; case 'B': daemonize = 1; break; case 'G': ping_interval = atoi(optarg); break; case 'h': usage(); return 0; case 'v': printf("%s\n", hostapd_cli_version); return 0; case 'i': os_free(ctrl_ifname); ctrl_ifname = os_strdup(optarg); break; case 'p': ctrl_iface_dir = optarg; break; default: usage(); return -1; } } interactive = (argc == optind) && (action_file == NULL); if (interactive) { printf("%s\n\n%s\n\n", hostapd_cli_version, hostapd_cli_license); } if (eloop_init()) return -1; for (;;) { if (ctrl_ifname == NULL) { struct dirent *dent; DIR *dir = opendir(ctrl_iface_dir); if (dir) { while ((dent = readdir(dir))) { if (os_strcmp(dent->d_name, ".") == 0 || os_strcmp(dent->d_name, "..") == 0) continue; printf("Selected interface '%s'\n", dent->d_name); ctrl_ifname = os_strdup(dent->d_name); break; } closedir(dir); } } ctrl_conn = hostapd_cli_open_connection(ctrl_ifname); if (ctrl_conn) { if (warning_displayed) printf("Connection established.\n"); break; } if (!interactive) { perror("Failed to connect to hostapd - " "wpa_ctrl_open"); return -1; } if (!warning_displayed) { printf("Could not connect to hostapd - re-trying\n"); warning_displayed = 1; } os_sleep(1, 0); continue; } if (interactive || action_file) { if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; } else { printf("Warning: Failed to attach to hostapd.\n"); if (action_file) return -1; } } if (daemonize && os_daemonize(pid_file)) return -1; if (interactive) hostapd_cli_interactive(); else if (action_file) hostapd_cli_action(ctrl_conn); else wpa_request(ctrl_conn, argc - optind, &argv[optind]); os_free(ctrl_ifname); eloop_destroy(); hostapd_cli_cleanup(); return 0; }
char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, char *buf, size_t *resp_len) { char *reply; const int reply_size = 4096; int ctrl_rsp = 0; int reply_len; if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 || os_strncmp(buf, "SET_NETWORK ", 12) == 0) { wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface", (const u8 *) buf, os_strlen(buf)); } else { if (os_strcmp(buf, "PING") != 0) wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface", (const u8 *) buf, os_strlen(buf)); } reply = os_malloc(reply_size); if (reply == NULL) { *resp_len = 1; return NULL; } os_memcpy(reply, "OK\n", 3); reply_len = 3; if (os_strcmp(buf, "PING") == 0) { os_memcpy(reply, "PONG\n", 5); reply_len = 5; } else if (os_strcmp(buf, "MIB") == 0) { reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size); if (reply_len >= 0) { int res; res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len, reply_size - reply_len); if (res < 0) reply_len = -1; else reply_len += res; } } else if (os_strncmp(buf, "STATUS", 6) == 0) { reply_len = wpa_supplicant_ctrl_iface_status( wpa_s, buf + 6, reply, reply_size); } else if (os_strcmp(buf, "PMKSA") == 0) { reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size); } else if (os_strncmp(buf, "SET ", 4) == 0) { if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4)) reply_len = -1; } else if (os_strcmp(buf, "LOGON") == 0) { eapol_sm_notify_logoff(wpa_s->eapol, FALSE); } else if (os_strcmp(buf, "LOGOFF") == 0) { eapol_sm_notify_logoff(wpa_s->eapol, TRUE); } else if (os_strcmp(buf, "REASSOCIATE") == 0) { wpa_s->disconnected = 0; wpa_s->reassociate = 1; wpa_supplicant_req_scan(wpa_s, 0, 0); } else if (os_strcmp(buf, "RECONNECT") == 0) { if (wpa_s->disconnected) { wpa_s->disconnected = 0; wpa_s->reassociate = 1; wpa_supplicant_req_scan(wpa_s, 0, 0); } #ifdef IEEE8021X_EAPOL } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) reply_len = -1; #endif /* IEEE8021X_EAPOL */ #ifdef CONFIG_PEERKEY } else if (os_strncmp(buf, "STKSTART ", 9) == 0) { if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9)) reply_len = -1; #endif /* CONFIG_PEERKEY */ } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0) { if (wpa_supplicant_ctrl_iface_ctrl_rsp( wpa_s, buf + os_strlen(WPA_CTRL_RSP))) reply_len = -1; else ctrl_rsp = 1; } else if (os_strcmp(buf, "RECONFIGURE") == 0) { if (wpa_supplicant_reload_configuration(wpa_s)) reply_len = -1; } else if (os_strcmp(buf, "TERMINATE") == 0) { eloop_terminate(); } else if (os_strncmp(buf, "BSSID ", 6) == 0) { if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6)) reply_len = -1; #ifdef ANDROID } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) { reply_len = wpa_supplicant_ctrl_iface_blacklist( wpa_s, buf + 9, reply, reply_size); if (os_strlen(buf) > 10 && reply_len == 0) { struct wpa_blacklist *bl = wpa_s->blacklist; if (os_strncmp(buf+10, "clear", 5) == 0 || (bl != NULL && os_memcmp(bl->bssid, wpa_s->bssid, ETH_ALEN) == 0)) { wpa_s->disconnected = 0; wpa_s->reassociate = 1; wpa_supplicant_req_scan(wpa_s, 0, 0); } } #endif } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) { reply_len = wpa_supplicant_ctrl_iface_list_networks( wpa_s, reply, reply_size); } else if (os_strcmp(buf, "DISCONNECT") == 0) { wpa_s->reassociate = 0; wpa_s->disconnected = 1; wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING); } else if (os_strcmp(buf, "SCAN") == 0) { #ifdef ANDROID if (!wpa_s->scan_ongoing && ((wpa_s->wpa_state <= WPA_SCANNING) || (wpa_s->wpa_state >= WPA_COMPLETED))) { #endif wpa_s->scan_req = 2; wpa_supplicant_req_scan(wpa_s, 0, 0); #ifdef ANDROID } else { wpa_printf(MSG_DEBUG, "Ongoing Scan action..."); } #endif } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) { reply_len = wpa_supplicant_ctrl_iface_scan_results( wpa_s, reply, reply_size); } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) { if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15)) reply_len = -1; } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) { if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15)) reply_len = -1; } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) { if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16)) reply_len = -1; } else if (os_strcmp(buf, "ADD_NETWORK") == 0) { reply_len = wpa_supplicant_ctrl_iface_add_network( wpa_s, reply, reply_size); } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) { if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15)) reply_len = -1; } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) { if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12)) reply_len = -1; } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) { reply_len = wpa_supplicant_ctrl_iface_get_network( wpa_s, buf + 12, reply, reply_size); } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) { if (wpa_supplicant_ctrl_iface_save_config(wpa_s)) reply_len = -1; } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) { reply_len = wpa_supplicant_ctrl_iface_get_capability( wpa_s, buf + 15, reply, reply_size); } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) { if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8)) reply_len = -1; } else if (os_strcmp(buf, "INTERFACES") == 0) { reply_len = wpa_supplicant_global_iface_interfaces( wpa_s->global, reply, reply_size); } else if (os_strncmp(buf, "DRIVER ", 7) == 0) { reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, reply_size); } else { os_memcpy(reply, "UNKNOWN COMMAND\n", 16); reply_len = 16; } if (reply_len < 0) { os_memcpy(reply, "FAIL\n", 5); reply_len = 5; } if (ctrl_rsp) eapol_sm_notify_ctrl_response(wpa_s->eapol); *resp_len = reply_len; return reply; }