blob: 7546e13ff9a5016e5cda1cf71f605dd0c40be288 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <softap_api.h>
2#include <errno.h>
3#include <wifi.h>
4#include "wlan_interface.h"
5
6/*char to hex*/
7char c2x(char c)
8{
9 if ((c >= '0') && (c <= '9'))
10 {
11 return c - '0';
12 }
13 if ((c >= 'a') && (c <= 'f'))
14 {
15 return (c - 'a') + 10;
16 }
17 if ((c >= 'A') && (c <= 'F'))
18 {
19 return (c - 'A') + 10;
20 }
21 return 0;
22}
23
24/*string to hex*/
25unsigned char s2x(char *s)
26{
27 int i;
28 char str[3];
29 unsigned char result;
30
31
32 for (i = 0; i < 3; i++)
33 {
34 str[i] = *s++;
35 if (str[i] == '\0')
36 {
37 break;
38 }
39 }
40
41 result = 0;
42 for (i = 0; i < 3; i++)
43 {
44 if (str[i] == '\0')
45 {
46 break;
47 }
48 result = (unsigned char)( c2x(str[i]) + (result << 4));
49 }
50
51 return result;
52}
53
54//cov
55__attribute__((visibility("hidden")))
56void base64_encode(const char* data, int data_len, char* encode, int encode_len)
57{
58 //int data_len = strlen(data);
59 int prepare = 0;
60 int ret_len;
61 int temp = 0;
62 char *ret = NULL;
63 char *f = NULL;
64 int tmp = 0;
65 char changed[4];
66 int i = 0;
67 const char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
68
69 if(data == NULL)
70 {
71 return;
72 }
73 if(encode == NULL)
74 {
75 return;
76 }
77 if(data_len == 0)
78 {
79 return;
80 }
81 ret_len = data_len / 3;
82 temp = data_len % 3;
83 if (temp > 0)
84 {
85 ret_len += 1;
86 }
87 ret_len = ret_len*4 + 1;
88 ret = (char *)malloc(ret_len);
89
90 if (ret == NULL)
91 {
92 printf("No enough memory.\n");
93 return;
94 }
95 memset(ret, 0, ret_len);
96 f = ret;
97 while (tmp < data_len)
98 {
99 temp = 0;
100 prepare = 0;
101 memset(changed, '\0', 4);
102 while (temp < 3)
103 {
104 //printf("tmp = %d\n", tmp);
105 if (tmp >= data_len)
106 {
107 break;
108 }
109 prepare = ((prepare << 8) | (data[tmp] & 0xFF));
110 tmp++;
111 temp++;
112 }
113 prepare = (prepare<<((3-temp)*8));
114 //printf("before for : temp = %d, prepare = %d\n", temp, prepare);
115 for (i = 0; i < 4 ;i++ )
116 {
117 if (temp < i)
118 {
119 changed[i] = 0x40;
120 }
121 else
122 {
123 changed[i] = (prepare>>((3-i)*6)) & 0x3F;
124 }
125 *f = base[changed[i]];
126 //printf("%.2X", changed[i]);
127 f++;
128 }
129 }
130 *f = '\0';
131 strncpy(encode, ret, encode_len - 1);
132 free(ret); //cov
133}
134
135static int get_msg_qid(int module_id)
136{
137 int msg_qid=-1;
138 printf("module_id = %d\n",module_id);
139AGAIN:
140 msg_qid = msgget(module_id,0);
141
142 if(msg_qid == -1)
143 {
144 printf("[%s] fail,module_id=%d, errno=%d\n", __FUNCTION__, module_id, errno);
145
146 goto AGAIN;
147 }
148
149 return msg_qid;
150
151}
152#if 0 //kw 3
153int pipecmd(const char *cmd, char *result)
154{
155 FILE *pp = NULL;
156 int tmp_len = 0;
157 char tmp[128]={0};
158
159 if (cmd == NULL)
160 {
161 return -1;
162 }
163
164 pp = popen(cmd, "r"); //½¨Á¢¹ÜµÀ
165 if (!pp)
166 {
167 return -1;
168 }
169
170 if (result != NULL)
171 {
172 while (fgets(tmp, sizeof(tmp), pp) != NULL)
173 {
174 tmp_len = strlen(tmp);
175 if (tmp_len > 0)
176 {
177 if (tmp[tmp_len - 1] == '\n')
178 {
179 tmp[tmp_len - 1] = '\0'; //È¥³ý»»Ðзû
180 }
181
182 strncpy(result,tmp,tmp_len);
183 printf("[%s]pcmd:tmp = %s\n",__FUNCTION__, tmp);
184 }
185 }
186 }
187 pclose(pp); //¹Ø±Õ¹ÜµÀ
188 return 0;
189}
190#endif
191#ifdef __NO_WIFI__
192void zte_get_wifi_sta_list(RT_802_11_MAC_TABLE *staList)
193{
194 printf("[%s]WIFI function closed\n", __FUNCTION__);
195}
196
197int zte_wlan_capture_sta_num()
198{
199 printf("[%s]WIFI function closed\n", __FUNCTION__);
200 return 0;
201}
202
203int get_channel()
204{
205 printf("[%s]WIFI function closed\n", __FUNCTION__);
206 return 1;
207}
208
209#endif
210