summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/p1905_managerd/src/mt7601_io.c
diff options
context:
space:
mode:
authorsamuel.chou2013-10-03 10:48:50 +0800
committersamuel.chou2013-10-11 09:33:12 +0800
commitef5c0c79316f864a38feee254c14a07fe409734c (patch)
treec8ba5986fc43ea5c2286d595edca23bef8e37464 /cleopatre/devkit/p1905_managerd/src/mt7601_io.c
parentb413722410e6da5d2600688248e9a9bca91b352c (diff)
cleo/{linux/net/bridge,devkit/p1905}: add ieee1905.1 feature, closes #4220
Diffstat (limited to 'cleopatre/devkit/p1905_managerd/src/mt7601_io.c')
-rw-r--r--cleopatre/devkit/p1905_managerd/src/mt7601_io.c1448
1 files changed, 1448 insertions, 0 deletions
diff --git a/cleopatre/devkit/p1905_managerd/src/mt7601_io.c b/cleopatre/devkit/p1905_managerd/src/mt7601_io.c
new file mode 100644
index 0000000000..273b081b99
--- /dev/null
+++ b/cleopatre/devkit/p1905_managerd/src/mt7601_io.c
@@ -0,0 +1,1448 @@
+/*
+ * cleopatre/application/p1905_managerd/src/mt7601_io.c
+ *
+ * (C) Copyright 2013 MStar Semiconductor, Inc.
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <syslog.h>
+#include <asm/byteorder.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <linux/wireless.h>
+#include "wifi_utils.h"
+#include <time.h>
+#include "mt7601_io.h"
+#include "libspid.h"
+
+//#define MT7601_IO_DEBUG
+#ifdef MT7601_IO_DEBUG
+#define debug(...) printf(__VA_ARGS__)
+#define debug_syslog(...) printf(__VA_ARGS__)
+#else
+#define debug(...)
+#define debug_syslog(format, ...) syslog(LOG_WARNING, format, ##__VA_ARGS__)
+#endif
+
+/*define wifi interface name*/
+#define RA0 "ra0"
+
+static WIFI_UTILS_STATUS mt7601_ioctl(int cmd, mt7601_io_table *tab)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+
+ wrq.u.data.length = tab->length;
+ wrq.u.data.pointer =(unsigned char *) tab->data;
+ wrq.u.data.flags = tab->flag;
+
+ if(ioctl(socket_id, cmd, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ tab->length = wrq.u.data.length;
+
+ close(socket_id);
+ return status;
+}
+
+void mt7601_init(void)
+{
+ /*use srand to set seed of rand*/
+ srand(time(NULL));
+}
+
+WIFI_UTILS_STATUS mt7601_get_rf_band(RF_BAND *band)
+{
+ libspid_wifi_t config_file;
+
+ if(LIBSPID_SUCCESS != libspid_network_wifi_data(RA0, &config_file, 0))
+ return wifi_utils_error;
+
+ if(!strcmp(config_file.wireless_mode, "2") ||
+ !strcmp(config_file.wireless_mode, "8") ||
+ !strcmp(config_file.wireless_mode, "10"))
+ {
+ *band = rf_band_5G;
+ }
+ else
+ *band = rf_band_2p4G;
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_get_uuid(unsigned char uu[])
+{
+ mt7601_io_table tab;
+ unsigned char data[50] = {0};
+ int i = 0;
+ unsigned char h_nibble = 0, l_nibble = 0;
+
+ tab.data = data;
+ tab.length = sizeof(sizeof(unsigned char));
+ tab.flag = RT_OID_WSC_UUID;
+
+ if(wifi_utils_error == mt7601_ioctl(RT_PRIV_IOCTL, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ debug("uuid length %d\n",tab.length);
+ debug("uuid %s\n",tab.data);
+
+ while(*(tab.data) != '\0')
+ {
+ if(*(tab.data) != '-')
+ {
+ h_nibble = *(tab.data);
+ l_nibble = *(tab.data + 1);
+
+ if(h_nibble >= 'a' && h_nibble <= 'f')
+ h_nibble -= ('a' - 10);
+ else if(h_nibble >= 'A' && h_nibble <= 'F')
+ h_nibble -= ('A' - 10);
+ else
+ h_nibble -= '0';
+
+ if(l_nibble >= 'a' && l_nibble <= 'f')
+ l_nibble -= ('a' - 10);
+ else if(l_nibble >= 'A' && l_nibble <= 'F')
+ l_nibble -= ('A' - 10);
+ else
+ l_nibble -= '0';
+
+ uu[i] = (h_nibble << 4) | l_nibble;
+ tab.data += 2;
+ i++;
+ }
+ else
+ {
+ tab.data += 1;
+ }
+ }
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS
+mt7601_get_statistics(unsigned char peer_mac[], unsigned int *packet_total,
+ unsigned int *packet_error, unsigned char is_tx)
+{
+#ifndef SUPPORT_WIFI_STATION
+ mt7601_io_table tab;
+ unsigned char data[2048] = {0};
+ unsigned char *parse_str;
+ unsigned char *ptr;
+ char *pEnd;
+ char sta_mac[6] = {0};
+
+ strcpy(data, "stat");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_STATISTICS, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ parse_str = data;
+
+ while((parse_str = strstr(parse_str, "mac")) != NULL)
+ {
+ parse_str = strstr(parse_str, "=");
+ parse_str = parse_str + 2;
+
+ ptr = strstr(parse_str, "\n");
+ *ptr = '\0';
+ ptr++;
+
+ sta_mac[0] = strtol(parse_str, &pEnd, 16);
+ sta_mac[1] = strtol(pEnd, &pEnd, 16);
+ sta_mac[2] = strtol(pEnd, &pEnd, 16);
+ sta_mac[3] = strtol(pEnd, &pEnd, 16);
+ sta_mac[4] = strtol(pEnd, &pEnd, 16);
+ sta_mac[5] = strtol(pEnd, &pEnd, 16);
+
+ debug("%.2x %.2x %.2x %.2x %.2x %.2x",sta_mac[0],sta_mac[1],
+ sta_mac[2],sta_mac[3],sta_mac[4],sta_mac[5]);
+
+ if(!memcmp(peer_mac, sta_mac, 6))
+ {
+ if(is_tx)
+ {
+ if((ptr = strstr(ptr, "TxPacket")) != NULL)
+ {
+ ptr = strstr(ptr, "=");
+ ptr = ptr + 2;
+
+ *packet_total = (unsigned int)strtol(ptr, NULL, 10);
+ /*temp let packet error = 0, need to implement*/
+ *packet_error = 0;
+
+ debug("packet tx = %d",*packet_total);
+ break;
+ }
+ else
+ {
+ debug_syslog("get TxPacket error\n");
+ return wifi_utils_error;
+ }
+ }
+ else
+ {
+ if((ptr = strstr(ptr, "RxPacket")) != NULL)
+ {
+ ptr = strstr(ptr, "=");
+ ptr = ptr + 2;
+
+ *packet_total = (unsigned int)strtol(ptr, NULL, 10);
+ /*temp let packet error = 0, need to implement*/
+ *packet_error = 0;
+ debug("packet rx = %d",*packet_total);
+ break;
+ }
+ else
+ {
+ debug_syslog("get RxPacket error\n");
+ return wifi_utils_error;
+ }
+ }
+ }
+
+ parse_str = ptr;
+ }
+
+ return wifi_utils_success;
+#else
+
+ *packet_total = 0;
+ *packet_error = 0;
+ return wifi_utils_success;
+#endif
+}
+
+WIFI_UTILS_STATUS
+mt7601_get_phyrate(unsigned char peer_mac[], unsigned short *phyrate)
+{
+#ifndef SUPPORT_WIFI_STATION
+ mt7601_io_table tab;
+ unsigned char data[2048] = {0};
+ unsigned char *parse_str;
+ unsigned char *ptr;
+ char *pEnd;
+ char sta_mac[6] = {0};
+
+ strcpy(data, "stat");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_STATISTICS, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ parse_str = data;
+
+ while((parse_str = strstr(parse_str, "mac")) != NULL)
+ {
+ parse_str = strstr(parse_str, "=");
+ parse_str = parse_str + 2;
+
+ ptr = strstr(parse_str, "\n");
+ *ptr = '\0';
+ ptr++;
+
+ sta_mac[0] = strtol(parse_str, &pEnd, 16);
+ sta_mac[1] = strtol(pEnd, &pEnd, 16);
+ sta_mac[2] = strtol(pEnd, &pEnd, 16);
+ sta_mac[3] = strtol(pEnd, &pEnd, 16);
+ sta_mac[4] = strtol(pEnd, &pEnd, 16);
+ sta_mac[5] = strtol(pEnd, &pEnd, 16);
+
+ debug("%.2x %.2x %.2x %.2x %.2x %.2x",sta_mac[0],sta_mac[1],
+ sta_mac[2],sta_mac[3],sta_mac[4],sta_mac[5]);
+
+ if(!memcmp(peer_mac, sta_mac, 6))
+ {
+ if((ptr = strstr(ptr, "Rate")) != NULL)
+ {
+ ptr = strstr(ptr, "=");
+ ptr = ptr + 2;
+
+ *phyrate = (unsigned short)strtol(ptr, NULL, 10);
+ debug("phyrate tx = %d",*phyrate);
+ break;
+ }
+ else
+ {
+ debug_syslog("get phyrate error\n");
+ return wifi_utils_error;
+ }
+ }
+ parse_str = ptr;
+ }
+ return wifi_utils_success;
+#else
+ *phyrate = 0;
+ return wifi_utils_success;
+#endif
+}
+
+WIFI_UTILS_STATUS mt7601_get_rssi(char *rssi, unsigned char peer_mac[])
+{
+#ifndef SUPPORT_WIFI_STATION
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+ RT_802_11_MAC_TABLE MacTable;
+ int i = 0;
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(RT_802_11_MAC_TABLE);
+ wrq.u.data.pointer =(unsigned char *) &MacTable;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_MAC_TABLE, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ for(i=0;i<MacTable.Num;i++)
+ {
+ if(!memcmp(MacTable.Entry[i].Addr, peer_mac, 6))
+ {
+ *rssi = MacTable.Entry[i].AvgRssi0;
+ break;
+ }
+ }
+
+ close(socket_id);
+ return status;
+#else
+ *rssi = 0xFF;
+ return wifi_utils_success;
+#endif
+}
+
+WIFI_UTILS_STATUS mt7601_get_current_channelwidth(unsigned char *width)
+{
+#ifndef SUPPORT_WIFI_STATION
+ mt7601_io_table tab;
+ unsigned char data[2048] = {0};
+ unsigned char *parse_str;
+ unsigned char BW;
+
+ strcpy(data, "stat");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_STATISTICS, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ parse_str = data;
+
+ if((parse_str = strstr(parse_str, "CurrentBW")) != NULL)
+ {
+ parse_str = strstr(parse_str, "=");
+ parse_str = parse_str + 2;
+
+ BW = (unsigned char)strtol(parse_str, NULL, 10);
+
+ if(BW == 0)
+ *width = 0;
+ else if(BW == 1)
+ *width = 1;
+ else
+ {
+ debug_syslog("mt7601_get_current_channelwidth wrong\n");
+ return wifi_utils_error;
+ }
+ }
+ else
+ return wifi_utils_error;
+
+ return wifi_utils_success;
+#else
+ *width = 0;
+ return wifi_utils_success;
+#endif
+}
+
+WIFI_UTILS_STATUS mt7601_get_center_freq_index(unsigned char *index)
+{
+#ifndef SUPPORT_WIFI_STATION
+ mt7601_io_table tab;
+ unsigned char data[2048] = {0};
+ unsigned char *parse_str;
+
+ strcpy(data, "stat");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_STATISTICS, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ parse_str = data;
+
+ if((parse_str = strstr(parse_str, "CenterFreq")) != NULL)
+ {
+ parse_str = strstr(parse_str, "=");
+ parse_str = parse_str + 2;
+
+ *index = (unsigned char)strtol(parse_str, NULL, 10);
+ }
+ else
+ return wifi_utils_error;
+
+ return wifi_utils_success;
+#else
+ *index = 0;
+ return wifi_utils_success;
+#endif
+}
+
+WIFI_UTILS_STATUS
+mt7601_get_station_mac(unsigned char station_list[WIFI_MAX_STATION_NUM][6],
+ unsigned char *sta_num)
+{
+#ifndef SUPPORT_WIFI_STATION
+ mt7601_io_table tab;
+ unsigned char data[2048] = {0};
+ unsigned char *parse_str;
+ unsigned char *ptr;
+ char *pEnd;
+ unsigned char num = 0;
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_STATISTICS, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ parse_str = data;
+
+ while((parse_str = strstr(parse_str, "mac")) != NULL)
+ {
+ parse_str = strstr(parse_str, "=");
+ parse_str = parse_str + 2;
+
+ ptr = strstr(parse_str, "\n");
+ *ptr = '\0';
+ ptr++;
+
+ station_list[num][0] = strtol(parse_str, &pEnd, 16);
+ station_list[num][1] = strtol(pEnd, &pEnd, 16);
+ station_list[num][2] = strtol(pEnd, &pEnd, 16);
+ station_list[num][3] = strtol(pEnd, &pEnd, 16);
+ station_list[num][4] = strtol(pEnd, &pEnd, 16);
+ station_list[num][5] = strtol(pEnd, &pEnd, 16);
+
+ num++;
+ parse_str = ptr;
+ }
+
+ *sta_num = num;
+#else
+ /*return fail if MT7601 used as a station*/
+ return wifi_utils_error;
+#endif
+ return wifi_utils_success;
+}
+
+#ifdef SUPPORT_AP_AUTO_CONFIG
+WIFI_UTILS_STATUS mt7601_get_wsc_conf_status(unsigned char *status)
+{
+ mt7601_io_table tab;
+ unsigned char data[1] = {0};
+
+ tab.data = data;
+ tab.length = sizeof(sizeof(unsigned char));
+ tab.flag = RT_OID_WSC_CONFIG_STATUS;
+
+ if(wifi_utils_error == mt7601_ioctl(RT_PRIV_IOCTL, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ *status = data[0];
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_DH_pub_priv_key(DH_TABLE *pdh)
+{
+ struct iwreq wrq;
+ int socket_id, i = 0, len = 0;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ len = sizeof(pdh->priv_key);
+
+ /*ramdon generate the Diffie-Hellman private key*/
+ for(i=0;i<len;i++)
+ pdh->priv_key[i] = ((rand() % 255) + 1);
+
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer =(unsigned char *) pdh;
+ wrq.u.data.flags = 0;
+
+ /* use this ioctl to generate Diffie-Helman public key*/
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_DH_PUB_KEY, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_DH_secu_key(DH_TABLE *pdh)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer =(unsigned char *) pdh;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_DH_SECU_KEY, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_auth_keywrap_key(KDK_KDF_TABLE *pkdk_kdf)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(KDK_KDF_TABLE);
+ wrq.u.data.pointer =(unsigned char *) pkdk_kdf;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_AUTH_KEYWRAP_KEY, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_kwa(KWA_TABLE *pkwa)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(KWA_TABLE);
+ wrq.u.data.pointer =(unsigned char *) pkwa;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_KWA_VALUE, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_AES_encrypt_value(AES_TABLE *paes)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(AES_TABLE);
+ wrq.u.data.pointer =(unsigned char *) paes;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_AES_ENCRYPT_VALUE, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+
+WIFI_UTILS_STATUS mt7601_generate_AES_decrypt_value(AES_TABLE *paes)
+{
+ struct iwreq wrq;
+ int socket_id;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+ unsigned char name[6] = {0};
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(AES_TABLE);
+ wrq.u.data.pointer =(unsigned char *) paes;
+ wrq.u.data.flags = 0;
+
+ if(ioctl(socket_id, RTPRIV_IOCTL_GET_AES_DECRYPT_VALUE, &wrq))
+ {
+ status = wifi_utils_error;
+ }
+
+ close(socket_id);
+ return status;
+}
+#endif
+
+WIFI_UTILS_STATUS mt7601_get_mac_addr(unsigned char *mac_addr)
+{
+ int socket_id;
+ struct ifreq ifr;
+ WIFI_UTILS_STATUS status = wifi_utils_success;
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+ strncpy(ifr.ifr_name, (char*)RA0, IFNAMSIZ);
+
+ if(-1 == (ioctl(socket_id, SIOCGIFINDEX, &ifr)))
+ {
+ /*need to do error handle*/
+ }
+
+ if(-1 == (ioctl(socket_id, SIOCGIFHWADDR, &ifr)))
+ {
+ /*need to do error handle*/
+ }
+
+ memcpy(mac_addr, ifr.ifr_hwaddr.sa_data, 6);
+
+ close(socket_id);
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_get_ssid(unsigned char *ssid, unsigned short *len)
+{
+ mt7601_io_table tab;
+
+ tab.data = ssid;
+ tab.length = (*len);
+ tab.flag = 0;
+ if(wifi_utils_error == mt7601_ioctl(SIOCGIWESSID, &tab))
+ {
+ return wifi_utils_error;
+ }
+ *len = tab.length;
+
+ return wifi_utils_success;
+}
+
+/*the parameter len = strlen(ssid)*/
+WIFI_UTILS_STATUS mt7601_set_ssid(unsigned char *ssid, unsigned short len)
+{
+ mt7601_io_table tab;
+ /*5 otects =>SSID= ; 32 otects ==> max SSID length ; 1 otects==> '\0'*/
+ unsigned char data[37 + 1] = {0};
+
+ data[0] = 'S';
+ data[1] = 'S';
+ data[2] = 'I';
+ data[3] = 'D';
+ data[4] = '=';
+
+ memcpy(&data[5], ssid, (len+1));
+ tab.data = data;
+ tab.length = 5 + len + 1;
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+#ifdef SUPPORT_AP_AUTO_CONFIG
+WIFI_UTILS_STATUS mt7601_set_authmode(unsigned short authmode)
+{
+ mt7601_io_table tab;
+ unsigned char data[25] = {0};
+
+ strcpy(data, "AuthMode=");
+
+ switch(authmode)
+ {
+ case AUTH_OPEN:
+ strcat(data, "OPEN");
+ break;
+ case AUTH_WPA_PERSONAL:
+ strcat(data, "WPAPSK");
+ break;
+ case AUTH_SHARED:
+ strcat(data, "SHARED");
+ break;
+ case AUTH_WPA_ENTERPRISE:
+ strcat(data, "WPA");
+ break;
+ case AUTH_WPA2_ENTERPRISE:
+ strcat(data, "WPA2");
+ break;
+ case (AUTH_WPA2_ENTERPRISE | AUTH_WPA_ENTERPRISE):
+ strcat(data, "WPA1WPA2");
+ break;
+ case AUTH_WPA2_PERSONAL:
+ strcat(data, "WPA2PSK");
+ break;
+ case (AUTH_WPA2_PERSONAL | AUTH_WPA_PERSONAL):
+ strcat(data, "WPAPSKWPA2PSK");
+ break;
+ default:
+ strcat(data, "OPEN");
+ break;
+ }
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_set_encryptmode(unsigned short encryptmode)
+{
+ mt7601_io_table tab;
+ unsigned char data[20] = {0};
+
+ strcpy(data, "EncrypType=");
+
+ switch(encryptmode)
+ {
+ case ENCRYP_NONE:
+ strcat(data, "NONE");
+ break;
+ case ENCRYP_WEP:
+ strcat(data, "WEP");
+ break;
+ case ENCRYP_TKIP:
+ strcat(data, "TKIP");
+ break;
+ case ENCRYP_AES:
+ strcat(data, "AES");
+ break;
+ case (ENCRYP_TKIP|ENCRYP_AES):
+ strcat(data, "TKIPAES");
+ break;
+ default:
+ strcat(data, "NONE");
+ break;
+ }
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_set_wsc_conf_status(unsigned char confstatus)
+{
+ mt7601_io_table tab;
+ unsigned char data[20] = {0};
+
+ strcpy(data, "WscConfStatus=");
+
+ if(confstatus == 2)//ap configured
+ strcat(data,"2");
+ else
+ strcat(data,"1");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_set_ieee802_1x(unsigned char ieee8021x)
+{
+ mt7601_io_table tab;
+ unsigned char data[20] = {0};
+
+ strcpy(data, "IEEE8021X=");
+
+ if(ieee8021x)
+ strcat(data, "1");
+ else
+ strcat(data, "0");
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+/*the parameter len = strlen(wpapsk)*/
+WIFI_UTILS_STATUS mt7601_set_wpapsk(unsigned char *wpapsk, unsigned short len)
+{
+ mt7601_io_table tab;
+ unsigned char data[7+64+1] = {0};
+
+ strcpy(data, "WPAPSK=");
+ memcpy(&data[7], wpapsk, len+1);
+ tab.data = data;
+ tab.length = 7 + len + 1;
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_set_default_keyid(unsigned char keyid)
+{
+ mt7601_io_table tab;
+ unsigned char data[20] = {0};
+
+ strcpy(data, "DefaultKeyID=");
+
+ if(keyid >= 1 && keyid <= 4)
+ {
+ keyid += 0x30;//changne Hex to ASCII
+ }
+ else
+ return wifi_utils_error;
+
+ data[13] = keyid;
+ data[14] = '\0';
+
+ tab.data = data;
+ tab.length = strlen(data);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_set_key1(unsigned char *key, unsigned short len)
+{
+ mt7601_io_table tab;
+ unsigned char data[5+65] = {0};
+
+ strcpy(data, "Key1=");
+ memcpy(&data[5], key, len+1);
+ tab.data = data;
+ tab.length = 5 + len + 1;
+
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_SET, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_get_wsc_config(WSC_CONFIG *wsc_config)
+{
+ WSC_CONFIGURED_VALUE *wsc;
+ mt7601_io_table tab;
+
+ wsc = (WSC_CONFIGURED_VALUE *)malloc(sizeof(WSC_CONFIGURED_VALUE));
+
+ tab.data = (unsigned char *)wsc;
+ tab.length = sizeof(WSC_CONFIGURED_VALUE);
+ tab.flag = 0;
+
+ if(wifi_utils_error == mt7601_ioctl(RTPRIV_IOCTL_WSC_PROFILE, &tab))
+ {
+ return wifi_utils_error;
+ }
+
+ memcpy(wsc_config->Ssid, wsc->WscSsid, sizeof(wsc_config->Ssid));
+ wsc_config->AuthMode = wsc->WscAuthMode;
+ wsc_config->EncrypType = wsc->WscEncrypType;
+ memcpy(wsc_config->WPAKey, wsc->WscWPAKey, sizeof(wsc_config->WPAKey));
+
+ free(wsc);
+}
+
+WIFI_UTILS_STATUS mt7601_set_wsc_config(WSC_CONFIG *wsc_config)
+{
+
+ if(wsc_config->AuthMode & (AUTH_WPA_PERSONAL | AUTH_WPA2_PERSONAL))
+ {
+ if(wsc_config->EncrypType & (ENCRYP_TKIP | ENCRYP_AES))
+ {
+ /*need to check more aout mixed mode*/
+ mt7601_set_authmode(wsc_config->AuthMode);
+ mt7601_set_encryptmode(wsc_config->EncrypType);
+ mt7601_set_ssid(wsc_config->Ssid, strlen(wsc_config->Ssid));
+ mt7601_set_wpapsk(wsc_config->WPAKey, strlen(wsc_config->WPAKey));
+ mt7601_set_ssid(wsc_config->Ssid, strlen(wsc_config->Ssid));
+ }
+ else
+ {
+ return wifi_utils_error;
+ }
+ }
+ else if(wsc_config->EncrypType == ENCRYP_WEP)
+ {
+ mt7601_set_authmode(wsc_config->AuthMode);
+ mt7601_set_encryptmode(wsc_config->EncrypType);
+ mt7601_set_default_keyid(1);
+ mt7601_set_key1(wsc_config->WPAKey, strlen(wsc_config->WPAKey));
+ mt7601_set_ssid(wsc_config->Ssid, strlen(wsc_config->Ssid));
+ }
+ else if(wsc_config->AuthMode == AUTH_OPEN && wsc_config->EncrypType == ENCRYP_NONE)
+ {
+ mt7601_set_authmode(wsc_config->AuthMode);
+ mt7601_set_encryptmode(wsc_config->EncrypType);
+ mt7601_set_ssid(wsc_config->Ssid, strlen(wsc_config->Ssid));
+ }
+
+ return wifi_utils_success;
+}
+
+WIFI_UTILS_STATUS mt7601_update_config_file(WSC_CONFIG *wsc_config)
+{
+ libspid_wifi_t config_file;
+
+ if(LIBSPID_SUCCESS != libspid_network_wifi_data(RA0, &config_file, 0))
+ return wifi_utils_error;
+
+ strcpy(config_file.ssid, wsc_config->Ssid);
+ if(wsc_config->AuthMode & (AUTH_WPA_PERSONAL | AUTH_WPA2_PERSONAL))
+ {
+ strcpy(config_file.wpapsk, wsc_config->WPAKey);
+ }
+ else
+ {
+ if(wsc_config->EncrypType == ENCRYP_WEP)
+ {
+ strcpy(config_file.default_key_id,"1");
+
+ if(strlen(wsc_config->WPAKey) == 5 || strlen(wsc_config->WPAKey) == 13)
+ strcpy(config_file.key1_type,"1");//ASCII
+ else if(strlen(wsc_config->WPAKey) == 10 || strlen(wsc_config->WPAKey) == 26)
+ strcpy(config_file.key1_type,"0");//HEX
+ else
+ {
+ debug_syslog("wep key length = %d\n",strlen(wsc_config->WPAKey));
+ return wifi_utils_error;
+ }
+ strcpy(config_file.key1_str, wsc_config->WPAKey);
+ }
+ }
+
+ switch(wsc_config->AuthMode)
+ {
+ case AUTH_OPEN:
+ strcpy(config_file.auth_mode, "OPEN");
+ break;
+ case AUTH_WPA_PERSONAL:
+ strcpy(config_file.auth_mode, "WPAPSK");
+ break;
+ case AUTH_SHARED:
+ strcpy(config_file.auth_mode, "SHARED");
+ break;
+ case AUTH_WPA_ENTERPRISE:
+ strcpy(config_file.auth_mode, "WPA");
+ break;
+ case AUTH_WPA2_ENTERPRISE:
+ strcpy(config_file.auth_mode, "WPA2");
+ break;
+ case (AUTH_WPA2_ENTERPRISE | AUTH_WPA_ENTERPRISE):
+ strcpy(config_file.auth_mode, "WPA1WPA2");
+ break;
+ case AUTH_WPA2_PERSONAL:
+ strcpy(config_file.auth_mode, "WPA2PSK");
+ break;
+ case (AUTH_WPA2_PERSONAL | AUTH_WPA_PERSONAL):
+ strcpy(config_file.auth_mode, "WPAPSKWPA2PSK");
+ break;
+ default:
+ strcpy(config_file.auth_mode, "OPEN");
+ break;
+ }
+
+ switch(wsc_config->EncrypType)
+ {
+ case ENCRYP_NONE:
+ strcpy(config_file.encryp_type, "NONE");
+ break;
+ case ENCRYP_WEP:
+ strcpy(config_file.encryp_type, "WEP");
+ break;
+ case ENCRYP_TKIP:
+ strcpy(config_file.encryp_type, "TKIP");
+ break;
+ case ENCRYP_AES:
+ strcpy(config_file.encryp_type, "AES");
+ break;
+ case (ENCRYP_TKIP|ENCRYP_AES):
+ strcpy(config_file.encryp_type, "TKIPAES");
+ break;
+ default:
+ strcpy(config_file.encryp_type, "NONE");
+ break;
+ }
+
+ /*set confstatus to configured*/
+ strcpy(config_file.wsc_conf_status, "2");
+
+ if(LIBSPID_SUCCESS != libspid_network_wifi_data(RA0, &config_file, 1))
+ return wifi_utils_error;
+
+ if(LIBSPID_SUCCESS != libspid_system_save())
+ return wifi_utils_error;
+
+ return wifi_utils_success;
+}
+
+void mt7601_set_wsc_config_test(void)
+{
+#if 1
+ unsigned char ssid[32+1] = "testwpa2aes";
+ unsigned char wpapsk[64+1] = "iwanttotestwpa2aes";
+ WSC_CONFIG wsc;
+
+ mt7601_set_authmode(AUTH_WPA2_PERSONAL);
+ mt7601_set_encryptmode(ENCRYP_AES);
+ mt7601_set_ssid(ssid, strlen(ssid));
+ mt7601_set_wpapsk(wpapsk, strlen(wpapsk));
+ mt7601_set_ssid(ssid, strlen(ssid));
+#endif
+
+#if 0
+ unsigned char ssid[32+1] = "testwpa2tkip";
+ unsigned char wpapsk[64+1] = "iwanttotestwpa2tkip";
+ WSC_CONFIG wsc;
+
+ mt7601_set_authmode(AUTH_WPA2_PERSONAL);
+ mt7601_set_encryptmode(ENCRYP_TKIP);
+ mt7601_set_ssid(ssid, strlen(ssid));
+ mt7601_set_wpapsk(wpapsk, strlen(wpapsk));
+ mt7601_set_ssid(ssid, strlen(ssid));
+#endif
+
+#if 0
+ unsigned char ssid[32+1] = "testwepshareascii13";
+ unsigned char wpapsk[64+1] = "itestascii13y";
+ WSC_CONFIG wsc;
+ mt7601_set_authmode(AUTH_SHARED);
+ mt7601_set_encryptmode(ENCRYP_WEP);
+ mt7601_set_default_keyid(1);
+ mt7601_set_key1(wpapsk, strlen(wpapsk));
+ mt7601_set_ssid(ssid, strlen(ssid));
+#endif
+
+#if 0
+ unsigned char ssid[32+1] = "testwpaaes";
+ unsigned char wpapsk[64+1] = "iwanttotestwpaaes";
+ WSC_CONFIG wsc;
+
+ mt7601_set_authmode(AUTH_WPA_PERSONAL);
+ mt7601_set_encryptmode(ENCRYP_AES);
+ mt7601_set_ssid(ssid, strlen(ssid));
+ mt7601_set_wpapsk(wpapsk, strlen(wpapsk));
+ mt7601_set_ssid(ssid, strlen(ssid));
+#endif
+
+#if 0
+ unsigned char ssid[32+1] = "testnone";
+ WSC_CONFIG wsc;
+
+ mt7601_set_authmode(AUTH_OPEN);
+ mt7601_set_encryptmode(ENCRYP_NONE);
+ mt7601_set_ssid(ssid, strlen(ssid));
+#endif
+
+
+ mt7601_get_wsc_config(&wsc);
+ printf("ssid %s\n",wsc.Ssid);
+ printf("authmode 0x%.4x\n",wsc.AuthMode);
+ printf("encrypt mode 0x%.4x\n",wsc.EncrypType);
+ printf("wpapsk %s\n",wsc.WPAKey);
+}
+
+void mt7601_AES_test(void)
+{
+#ifdef MT7601_IO_DEBUG
+ int i = 0;
+ AES_TABLE Enc;
+ AES_TABLE Dec;
+
+ srand(time(NULL));
+
+ for(i=0;i<16;i++)
+ Enc.KeyWrapKey[i] = ((rand() % 255) + 1);
+ memcpy(Dec.KeyWrapKey, Enc.KeyWrapKey, 16);
+
+ for(i=0;i<16;i++)
+ Enc.IV[i] = ((rand() % 255) + 1);
+ memcpy(Dec.IV, Enc.IV, 16);
+
+ Enc.PlainTextLen = ((rand() % (512-16)) + 1);
+ printf("plain text len = %d\n",Enc.PlainTextLen);
+
+ Enc.PlainText = malloc(Enc.PlainTextLen);
+ for(i=0;i<Enc.PlainTextLen;i++)
+ *(Enc.PlainText + i) = ((rand() % 255) + 1);
+
+ Enc.CipherText = malloc(512-16);
+ Enc.CipherTextLen = 512 -16;
+
+ mt7601_generate_AES_encrypt_value(&Enc);
+
+ printf("encrypt data len = %d\n",Enc.CipherTextLen);
+
+ Dec.CipherText = malloc(Enc.CipherTextLen);
+ Dec.CipherTextLen = Enc.CipherTextLen;
+ memcpy(Dec.CipherText, Enc.CipherText, Enc.CipherTextLen);
+
+ Dec.PlainText = malloc(1024);
+ Dec.PlainTextLen = 1024;
+
+ mt7601_generate_AES_decrypt_value(&Dec);
+
+ if(Dec.PlainTextLen != Enc.PlainTextLen)
+ {
+ printf("Dec.PlainTextLen = %d\n",Dec.PlainTextLen);
+ printf("Enc.PlainTextLen = %d\n",Enc.PlainTextLen);
+ }
+ else if(memcmp(Enc.PlainText, Dec.PlainText, Dec.PlainTextLen))
+ {
+ printf("Dec/Encrypt error\n");
+ }
+ else
+ printf("Dec/Encrypt success\n");
+
+
+ free(Enc.PlainText);
+ free(Enc.CipherText);
+ free(Dec.CipherText);
+ free(Dec.PlainText);
+#endif
+}
+
+void mt7601_keywrap_test(void)
+{
+#ifdef MT7601_IO_DEBUG
+ DH_TABLE dh1;
+ DH_TABLE dh2;
+ KDK_KDF_TABLE k1;
+ KDK_KDF_TABLE k2;
+ unsigned char temp_public[192] = {0};
+ int i = 0;
+
+ srand(time(NULL));
+
+ mt7601_generate_DH_pub_priv_key(&dh2);
+ mt7601_generate_DH_pub_priv_key(&dh1);
+
+ printf("DH public 1:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh1.pub_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+ printf("DH public 2:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh2.pub_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+ memcpy(temp_public, dh2.pub_key, 192);
+ memcpy(dh2.pub_key, dh1.pub_key, 192);
+ memcpy(dh1.pub_key, temp_public, 192);
+
+ printf("after DH public 1:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh1.pub_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+ printf("after DH public 2:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh2.pub_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+ mt7601_generate_DH_secu_key(&dh2);
+ mt7601_generate_DH_secu_key(&dh1);
+
+ printf("DH security 1:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh1.secu_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+ printf("DH security 2:\n");
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",dh2.secu_key[i]);
+ if((i % 10) == 0)
+ printf("\n");
+ }
+ printf("\n");
+
+
+ if(!memcmp(dh1.secu_key, dh2.secu_key, 192))
+ printf("DH key ok\n");
+ else
+ printf("DH key fail\n");
+
+ memcpy(k1.DH_Secu_Key, dh1.secu_key, 192);
+ memcpy(k2.DH_Secu_Key, dh2.secu_key, 192);
+
+ for(i=0;i<16;i++)
+ k1.E_Nonce[i] = ((rand() % 255) + 1);
+ memcpy(k2.E_Nonce, k1.E_Nonce, 16);
+
+ for(i=0;i<16;i++)
+ k1.R_Nonce[i] = ((rand() % 255) + 1);
+ memcpy(k2.R_Nonce, k1.R_Nonce, 16);
+
+ for(i=0;i<6;i++)
+ k1.E_Mac_Addr[i] = ((rand() % 255) + 1);
+ memcpy(k2.E_Mac_Addr, k1.E_Mac_Addr, 6);
+
+ mt7601_generate_auth_keywrap_key(&k1);
+ mt7601_generate_auth_keywrap_key(&k2);
+
+ printf("auth key1 =\n");
+ for(i=0;i<sizeof(k1.AuthKey);i++)
+ {
+ printf("%.2x ",k1.AuthKey[i]);
+ }
+ printf("\n");
+
+ printf("auth key2 =\n");
+ for(i=0;i<sizeof(k2.AuthKey);i++)
+ {
+ printf("%.2x ",k2.AuthKey[i]);
+ }
+ printf("\n");
+ if(!memcmp(k1.AuthKey, k2.AuthKey, 32))
+ printf("auth key OK\n");
+
+ printf("keywrap key1 =\n");
+ for(i=0;i<sizeof(k1.KeyWrapKey);i++)
+ {
+ printf("%.2x ",k1.KeyWrapKey[i]);
+ }
+ printf("\n");
+
+ printf("keywrap key2 =\n");
+ for(i=0;i<sizeof(k2.KeyWrapKey);i++)
+ {
+ printf("%.2x ",k2.KeyWrapKey[i]);
+ }
+ printf("\n");
+ if(!memcmp(k1.KeyWrapKey, k2.KeyWrapKey, 32))
+ printf("auth key OK\n");
+#endif
+}
+
+void mt7601_DH_test(void)
+{
+#ifdef MT7601_IO_DEBUG
+ DH_TABLE dh1;
+ DH_TABLE dh2;
+
+ struct iwreq wrq;
+ int socket_id;
+ unsigned char name[6] = {0};
+ unsigned char public[192] = {0};
+
+ int i = 0;
+ int len = 0;
+
+ socket_id = socket(AF_INET, SOCK_STREAM, 0);
+
+ srand(time(NULL));
+
+ for(i=0;i<192;i++)
+ {
+ dh1.priv_key[i] = ((rand() % 255) + 1);
+ }
+
+ sprintf(name, RA0);
+ strcpy(wrq.ifr_name, name);
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer =(unsigned char *) &dh1;
+ wrq.u.data.flags = 0;
+
+ if(0 == ioctl(socket_id, RTPRIV_IOCTL_GET_DH_PUB_KEY, &wrq))
+ {
+ printf("1 ==>wsc_dh_generate_key OK, len = %d\n",wrq.u.data.length);
+
+ len = sizeof(dh1.pub_key);
+ for(i=0;i<len;i++)
+ {
+ printf("%.2x ",dh1.pub_key[i]);
+ if(i%10 == 0)
+ printf("\n");
+ }
+ }
+ /*=================================================================*/
+ for(i=0;i<192;i++)
+ {
+ dh2.priv_key[i] = ((rand() % 255) + 1);
+ }
+
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer = (unsigned char *) &dh2;
+ wrq.u.data.flags = 0;
+
+ if(0 == ioctl(socket_id, RTPRIV_IOCTL_GET_DH_PUB_KEY, &wrq))
+ {
+ printf("2 ==>wsc_dh_generate_key OK, len = %d\n",wrq.u.data.length);
+
+ len = sizeof(dh2.pub_key);
+ for(i=0;i<len;i++)
+ {
+ printf("%.2x ",dh2.pub_key[i]);
+ if(i%10 == 0)
+ printf("\n");
+ }
+ }
+ /*=================================================================*/
+ memcpy(public, dh1.pub_key, 192);
+ memcpy(dh1.pub_key, dh2.pub_key, 192);
+ memset(dh1.secu_key,0,192);
+ memcpy(dh2.pub_key, public, 192);
+ memset(dh2.secu_key,0,192);
+
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer = (unsigned char *)(&dh1);
+ wrq.u.data.flags = 0;
+
+ if(0 == ioctl(socket_id, RTPRIV_IOCTL_GET_DH_SECU_KEY, &wrq))
+ {
+ printf("1 ==>compute key OK, len = %d\n",wrq.u.data.length);
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",(dh1.secu_key[i]));
+ if(i%10 == 0)
+ printf("\n");
+ }
+ }
+
+ wrq.u.data.length = sizeof(DH_TABLE);
+ wrq.u.data.pointer = (unsigned char *)(&dh2);
+ wrq.u.data.flags = 0;
+
+ if(0 == ioctl(socket_id, RTPRIV_IOCTL_GET_DH_SECU_KEY, &wrq))
+ {
+ printf("2 ==>compute key OK, len = %d\n",wrq.u.data.length);
+
+ for(i=0;i<192;i++)
+ {
+ printf("%.2x ",(dh2.secu_key[i]));
+ if(i%10 == 0)
+ printf("\n");
+ }
+ }
+
+ if(!memcmp(dh1.secu_key, dh2.secu_key, sizeof(dh1.secu_key)))
+ printf("\nkey is same\n");
+
+ close(socket_id);
+#endif
+}
+#endif