+typedef enum {
+ WIFI_SECURITY_TYPE_NONE = 0,
+ WIFI_SECURITY_TYPE_WEP = 1,
+ WIFI_SECURITY_TYPE_WPA_PSK = 2,
+ WIFI_SECURITY_TYPE_WPA2_PSK = 3,
+ WIFI_SECURITY_TYPE_EAP = 4,
+} wifi_security_type_e;
+
+typedef enum {
+ WIFI_ENCRYPTION_TYPE_NONE = 0,
+ WIFI_ENCRYPTION_TYPE_WEP = 1,
+ WIFI_ENCRYPTION_TYPE_TKIP = 2,
+ WIFI_ENCRYPTION_TYPE_AES = 3,
+ WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED = 4,
+} wifi_encryption_type_e;
+
+static unsigned char ms_oui[3] = { 0x00, 0x50, 0xf2 };
+static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
+
+static void __netconfig_get_security(unsigned char *bss_element, int length, wifi_security_type_e *sec_type, wifi_encryption_type_e *enc_type)
+{
+ int i;
+ unsigned char *data;
+ uint8_t *t_data;
+ int len;
+ __u16 count;
+
+ *sec_type = WIFI_SECURITY_TYPE_NONE;
+ *enc_type = WIFI_ENCRYPTION_TYPE_NONE;
+
+ while (length >= 2 && length >= bss_element[1]) {
+ if (bss_element[0] == 221 && (bss_element[1] >= 4 && memcmp(bss_element + 2, ms_oui, 3) == 0)) {
+ data = bss_element + 2 + 4 + 2 + 4;
+ len = bss_element[1] - 4 - 2 - 4;
+
+ if (len < 2) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ count = data[0] | (data[1] << 8);
+
+ if (2 + (count * 4) > len) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ for (i = 0; i < count; i++) {
+ t_data = (data + 2 + (i * 4));
+
+ if ((memcmp(t_data, ms_oui, 3) == 0) || (memcmp(t_data, ieee80211_oui, 3) == 0)) {
+ if (t_data[3] == 1 || t_data[3] == 5) { // 1 : WEP-40, 5 : WEP-104
+ *sec_type = WIFI_SECURITY_TYPE_WEP;
+ *enc_type = WIFI_ENCRYPTION_TYPE_WEP;
+ return;
+ } else if (t_data[3] == 2) { // 2 : TKIP
+ if (*sec_type != WIFI_SECURITY_TYPE_WPA2_PSK)
+ *sec_type = WIFI_SECURITY_TYPE_WPA_PSK;
+ if (*enc_type == WIFI_ENCRYPTION_TYPE_AES)
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
+ else
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP;
+ } else if (t_data[3] == 4) { // 3 : CCMP
+ if (*sec_type != WIFI_SECURITY_TYPE_WPA2_PSK)
+ *sec_type = WIFI_SECURITY_TYPE_WPA_PSK;
+ if (*enc_type == WIFI_ENCRYPTION_TYPE_TKIP)
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
+ else
+ *enc_type = WIFI_ENCRYPTION_TYPE_AES;
+ }
+ } //if
+ } //for
+
+ data += 2 + (count * 4);
+ len -= 2 + (count * 4);
+
+ if (len < 2) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ count = data[0] | (data[1] << 8);
+
+ if (2 + (count * 4) > len) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ for (i = 0; i < count; i++) {
+ t_data = (data + 2 + (i * 4));
+
+ if ((memcmp(t_data, ms_oui, 3) == 0) || (memcmp(t_data, ieee80211_oui, 3) == 0)) {
+ if (t_data[3] == 1 || t_data[3] == 3 || t_data[3] == 5) { // 1 : IEEE 802.1X, 3 : FT/IEEE 802.1X, 5 : IEEE 802.1X/SHA-256
+ *sec_type = WIFI_SECURITY_TYPE_EAP;
+ } else if (t_data[3] == 2 || t_data[3] == 4 || t_data[3] == 6) { // 2 : PSK, 4 : FT/PSK, 6 : PSK/SHA-256
+ if (*sec_type != WIFI_SECURITY_TYPE_WPA2_PSK)
+ *sec_type = WIFI_SECURITY_TYPE_WPA_PSK;
+ }
+ }
+ }
+ } else if (bss_element[0] == 48 && (bss_element[1] >= 2 && bss_element[1] <= 255)) {
+ data = bss_element + 2 + 2 + 4;
+ len = bss_element[1] - 2 - 4;
+
+ if (len < 2) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ count = data[0] | (data[1] << 8);
+ if (2 + (count + 4) > len) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ for (i = 0; i < count; i++) {
+ t_data = (data + 2 + (i * 4));
+
+ if ((memcmp(t_data, ms_oui, 3) == 0) || (memcmp(t_data, ieee80211_oui, 3) == 0)) {
+ if (t_data[3] == 1 || t_data[3] == 5) { // 1 : WEP-40, 5 : WEP-104
+ *sec_type = WIFI_SECURITY_TYPE_WEP;
+ *enc_type = WIFI_ENCRYPTION_TYPE_WEP;
+ return;
+ } else if (t_data[3] == 2) { // 2 : TKIP
+ *sec_type = WIFI_SECURITY_TYPE_WPA2_PSK;
+ if (*enc_type == WIFI_ENCRYPTION_TYPE_AES)
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
+ else
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP;
+ } else if (t_data[3] == 4) { // 3 : CCMP
+ *sec_type = WIFI_SECURITY_TYPE_WPA2_PSK;
+ if (*enc_type == WIFI_ENCRYPTION_TYPE_TKIP)
+ *enc_type = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED;
+ else
+ *enc_type = WIFI_ENCRYPTION_TYPE_AES;
+ }
+ }
+ }
+
+ data += 2 + (count * 4);
+ len -= 2 + (count * 4);
+
+ if (len < 2) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ count = data[0] | (data[1] << 8);
+ if (2 + (count * 4) > len) {
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ continue;
+ }
+
+ for (i = 0; i < count; i++) {
+ t_data = (data + 2 + (i * 4));
+
+ if ((memcmp(t_data, ms_oui, 3) == 0) || (memcmp(t_data, ieee80211_oui, 3) == 0)) {
+ if (t_data[3] == 1 || t_data[3] == 3 || t_data[3] == 5) { // 1 : IEEE 802.1X, 3 : FT/IEEE 802.1X, 5 : IEEE 802.1X/SHA-256
+ *sec_type = WIFI_SECURITY_TYPE_EAP;
+ } else if (t_data[3] == 2 || t_data[3] == 4 || t_data[3] == 6) { // 2 : PSK, 4 : FT/PSK, 6 : PSK/SHA-256
+ *sec_type = WIFI_SECURITY_TYPE_WPA2_PSK;
+ }
+ }
+ } //for
+ } //else if
+
+ length -= bss_element[1] + 2;
+ bss_element += bss_element[1] + 2;
+ } //while
+
+ return;
+}
+
+static void __netconfig_get_vsie(unsigned char *bss_element, int length, GSList **dst)