b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | #if 1//def MBTK_TCP_SUPPORT
|
| 2 | #include "mbtk_at.h"
|
| 3 | //#include <sys/statfs.h>
|
| 4 | #include <sys/vfs.h>
|
| 5 | #include <errno.h>
|
| 6 | #include <linux/magic.h>
|
| 7 | #include <time.h>
|
| 8 | #include <sys/time.h>
|
| 9 | #include <signal.h>
|
| 10 | #include <pthread.h>
|
| 11 | #include <time.h>
|
| 12 | #include <sys/time.h>
|
| 13 | #include <cutils/properties.h>
|
| 14 | #include "configwrapper.h"
|
| 15 | #include<linux/msg.h>
|
| 16 |
|
| 17 | #include "mbtk_at_tcpip.h"
|
| 18 |
|
| 19 |
|
| 20 | /*******************DEFINE**********************/
|
| 21 | #define TEL_AT_MYNET_SOCKET_ID_MIN 0
|
| 22 | #define TEL_AT_MYNET_SOCKET_ID_MAX 3
|
| 23 | #define TEL_AT_MYNET_SOCKET_ID_DEFAULT 0
|
| 24 |
|
| 25 | #define MAX_NETTYPE_LEN 4
|
| 26 | #define MAX_IP_LEN 256
|
| 27 |
|
| 28 | #define TEL_AT_IPV4_STR_DEFAULT NULL
|
| 29 |
|
| 30 | #define TEL_AT_NET_PORT_MIN 0
|
| 31 | #define TEL_AT_NET_PORT_MAX 65535
|
| 32 | #define TEL_AT_NET_SRC_PORT_DEFAULT 0
|
| 33 |
|
| 34 | #define MAX_DATA_LEN 512
|
| 35 |
|
| 36 | #define TEL_AT_TCPIP_STR_DEFAULT NULL
|
| 37 |
|
| 38 | #define TEL_AT_SEND_DATA_PARAM_MIN 0
|
| 39 | #define TEL_AT_SEND_DATA_PARAM_MAX 2500
|
| 40 | #define TEL_AT_SEND_DATA_PARAM_DEFAULT 0
|
| 41 |
|
| 42 | #define TEL_AT_READ_MODE_MIN 0
|
| 43 | #define TEL_AT_READ_MODE_MAX 4
|
| 44 | #define TEL_AT_READ_MODE_DEFAULT 0
|
| 45 |
|
| 46 | #define TEL_AT_READ_DATA_MIN 0
|
| 47 | #define TEL_AT_READ_DATA_MAX 1500
|
| 48 | #define TEL_AT_READ_DATA_DEFAULT 0
|
| 49 |
|
| 50 | #define MAX_LINK_NUM 4
|
| 51 |
|
| 52 | #define TEL_AT_TIME_MIN 0
|
| 53 | #define TEL_AT_TIME_MAX 7200
|
| 54 | #define TEL_AT_TIME_DEFAULT 0
|
| 55 |
|
| 56 | #define MAX_AUTO_READ_LEN 2048
|
| 57 |
|
| 58 | #define MODEM_TCPIP_PORT_DEVICE "/dev/ttyGS0"
|
| 59 | /*******************DEFINE**********************/
|
| 60 |
|
| 61 | /*******************ENUM**********************/
|
| 62 | typedef enum {
|
| 63 | MBTK_TCPIP_RESULT_SUCCESS,
|
| 64 | MBTK_TCPIP_RESULT_FAIL,
|
| 65 | MBTK_TCPIP_RESULT_UNKNOWN
|
| 66 | } mbtk_tcpip_result_enum;
|
| 67 |
|
| 68 | typedef enum {
|
| 69 | MBTK_TCPIP_NET_STATUS_OFF,
|
| 70 | MBTK_TCPIP_NET_STATUS_ON
|
| 71 | } mbtk_tcpip_net_status_enum;
|
| 72 |
|
| 73 | typedef enum {
|
| 74 | MBTK_TCPIP_READ_AUTO,
|
| 75 | MBTK_TCPIP_READ_MANUALLY,
|
| 76 | MBTK_TCPIP_READ_MANUALLY_DATA,
|
| 77 | MBTK_TCPIP_READ_MANUALLY_HEX,
|
| 78 | MBTK_TCPIP_READ_MANUALLY_REST
|
| 79 | }mbtk_tcpip_read_type_enum;
|
| 80 |
|
| 81 | typedef enum {
|
| 82 | MBTK_TCPIP_SIG_NETOPEN,
|
| 83 | MBTK_TCPIP_SIG_NETCLOSE,
|
| 84 | MBTK_TCPIP_SIG_CIPOPEN,
|
| 85 | MBTK_TCPIP_SIG_CIPCLOSE,
|
| 86 | MBTK_TCPIP_SIG_CIPSEND,
|
| 87 | MBTK_TCPIP_SIG_CIPRXGET,
|
| 88 | MBTK_TCPIP_SIG_MCIPCFGPL,
|
| 89 | MBTK_TCPIP_SIG_MCIPCFG,
|
| 90 | MBTK_TCPIP_SIG_USEDDATA,
|
| 91 | MBTK_TCPIP_SIG_CLEARDATA,
|
| 92 | MBTK_TCPIP_SIG_CIPOPQUERY
|
| 93 | }mbtk_tcpip_at_type_enum;
|
| 94 | /*******************ENUM**********************/
|
| 95 |
|
| 96 | /*******************STRUCT**********************/
|
| 97 | typedef struct {
|
| 98 | int link_num;
|
| 99 | int length;
|
| 100 | char* lenth_data;
|
| 101 | char ser_addr[MAX_IP_LEN + 1];
|
| 102 | int ser_port;
|
| 103 | char data[MAX_DATA_LEN + 1];
|
| 104 | }mbtk_tcpip_send_info_t;
|
| 105 |
|
| 106 | typedef struct {
|
| 107 | int link_num;
|
| 108 | mbtk_tcpip_read_type_enum read_mode;
|
| 109 | char* read_len;
|
| 110 | }mbtk_tcpip_read_info_t;
|
| 111 | /*******************STRUCT**********************/
|
| 112 |
|
| 113 | /*******************VARIABLE**********************/
|
| 114 | bool link_status[MAX_LINK_NUM] = {false, false, false, false};
|
| 115 | mbtk_task_queue_info mbtk_tcpip_task;
|
| 116 | int mbtk_tcpip_port_fd = -1;
|
| 117 | #ifdef MBTK_DATA_MODE_SUPPORT
|
| 118 | unsigned int data_mode_atHandle = 0;
|
| 119 | mbtk_tcpip_send_info_t data_mode_info = {0};
|
| 120 | #endif
|
| 121 | /*******************VARIABLE**********************/
|
| 122 |
|
| 123 | /*******************STATIC VARIABLE**********************/
|
| 124 | static int tcpip_thread_init = 0;
|
| 125 | static uint32 mbtk_heartbeat_time = 0;
|
| 126 | static uint32 mbtk_delay_time = 0;
|
| 127 | static mbtk_tcpip_net_status_enum net_status = MBTK_TCPIP_NET_STATUS_OFF;
|
| 128 | static mbtk_tcpip_read_type_enum read_type[MAX_LINK_NUM] = {0};
|
| 129 | static mbtk_tcpip_info_t mbtk_tcpipip_info[MAX_LINK_NUM] = {0};
|
| 130 |
|
| 131 | /*******************STATIC VARIABLE**********************/
|
| 132 |
|
| 133 | /*******************EXTERN VARIABLE**********************/
|
| 134 | /*******************EXTERN VARIABLE**********************/
|
| 135 |
|
| 136 |
|
| 137 | /*********************************************FUNC************************************************************/
|
| 138 | int mbtk_tcpip_thread_status_get(void)
|
| 139 | {
|
| 140 | return tcpip_thread_init;
|
| 141 | }
|
| 142 |
|
| 143 | void mbtk_tcpip_thread_status_set(int status)
|
| 144 | {
|
| 145 | tcpip_thread_init = status;
|
| 146 | }
|
| 147 |
|
| 148 | mbtk_tcpip_net_status_enum mbtk_tcpip_net_status_get(void)
|
| 149 | {
|
| 150 | return net_status;
|
| 151 | }
|
| 152 |
|
| 153 | void mbtk_tcpip_net_status_set(mbtk_tcpip_net_status_enum status)
|
| 154 | {
|
| 155 | net_status = status;
|
| 156 | }
|
| 157 |
|
| 158 | mbtk_tcpip_read_type_enum mbtk_tcpip_read_type_get(int link_num)
|
| 159 | {
|
| 160 | return read_type[link_num];
|
| 161 | }
|
| 162 |
|
| 163 | void mbtk_tcpip_read_type_set(int link_num, mbtk_tcpip_read_type_enum type)
|
| 164 | {
|
| 165 | read_type[link_num] = type;
|
| 166 | }
|
| 167 |
|
| 168 | static int mbtk_tcpip_open_device(int *fd_ptr, const char *file_path, int flag, int tty)
|
| 169 | {
|
| 170 |
|
| 171 | int fd = -1;
|
| 172 |
|
| 173 | if((fd = open(file_path, flag)) < 0)
|
| 174 | {
|
| 175 | LOG("[mbtk_tcpip_open_device]: Open %s fail.", file_path);
|
| 176 | return -1;
|
| 177 | }
|
| 178 |
|
| 179 | LOG("[mbtk_tcpip_open_device]: Open %s success.", file_path);
|
| 180 | if (tty) {
|
| 181 | /* set newtio */
|
| 182 | }
|
| 183 |
|
| 184 | *fd_ptr = fd;
|
| 185 | return 0;
|
| 186 | }
|
| 187 |
|
| 188 | int mbtk_tcpip_open_port(void)
|
| 189 | {
|
| 190 | if(mbtk_tcpip_port_fd < 0)
|
| 191 | {
|
| 192 | return mbtk_tcpip_open_device(&mbtk_tcpip_port_fd, MODEM_TCPIP_PORT_DEVICE, O_RDWR | O_NONBLOCK | O_NOCTTY, 0);
|
| 193 | }
|
| 194 | return 0;
|
| 195 | }
|
| 196 |
|
| 197 | void mbtk_tcpip_close_port(void)
|
| 198 | {
|
| 199 | if(mbtk_tcpip_port_fd >= 0)
|
| 200 | {
|
| 201 | //tcflush(mbtk_tcpip_port_fd, TCIOFLUSH);
|
| 202 | close(mbtk_tcpip_port_fd);
|
| 203 | mbtk_tcpip_port_fd = -1;
|
| 204 | }
|
| 205 |
|
| 206 | }
|
| 207 |
|
| 208 | int mbtk_tcpip_write_data(void *data,int data_len)
|
| 209 | {
|
| 210 | if(mbtk_tcpip_port_fd < 0)
|
| 211 | {
|
| 212 | LOG("[mbtk_tcpip_write_data]: mbtk_tcpip_port_fd not open.");
|
| 213 | return -1;
|
| 214 | }
|
| 215 |
|
| 216 | int ret = write(mbtk_tcpip_port_fd, data, data_len);
|
| 217 | if(ret < 0)
|
| 218 | {
|
| 219 | if(errno)
|
| 220 | {
|
| 221 | LOG("[mbtk_tcpip_write_data]: errno[%d].", errno);
|
| 222 | }
|
| 223 | LOG("[mbtk_tcpip_write_data]: mbtk_tcpip_port_fd write fail.");
|
| 224 | return -1;
|
| 225 | }
|
| 226 |
|
| 227 | write(mbtk_tcpip_port_fd, "\r\n", strlen("\r\n"));
|
| 228 | return 0;
|
| 229 | }
|
| 230 |
|
| 231 | void mbtk_at_tcpip_net_callback_func(int state, const char* addr)
|
| 232 | {
|
| 233 | //UNUSEDPARAM(state);
|
| 234 | //UNUSEDPARAM(addr);
|
| 235 | if(addr == NULL)
|
| 236 | {
|
| 237 | LOG("[mbtk_at_tcpip_net_callback_func]: state = [%d].", state);
|
| 238 | }
|
| 239 | else
|
| 240 | {
|
| 241 | LOG("[mbtk_at_tcpip_net_callback_func]: state = [%d] addr = [%s].", state, addr);
|
| 242 | }
|
| 243 |
|
| 244 | if(state == 0)
|
| 245 | {
|
| 246 | memset(link_status, 0x0,MAX_LINK_NUM);
|
| 247 | }
|
| 248 | mbtk_tcpip_net_status_set(state);
|
| 249 | }
|
| 250 |
|
| 251 | void mbtk_at_tcpip_sock_callback_func(int link_id, int state)
|
| 252 | {
|
| 253 | //UNUSEDPARAM(link_id);
|
| 254 | //UNUSEDPARAM(state);
|
| 255 | char resp_buf[64] = {0};
|
| 256 | LOG("[mbtk_at_tcpip_sock_callback_func]: link_id = [%d] state = [%d].", link_id, state);
|
| 257 | if(state == 0)
|
| 258 | {
|
| 259 | link_status[link_id] = false;
|
| 260 | sprintf(resp_buf, "\r\n+DISCONNECT: %d\r\n", link_id);
|
| 261 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 262 | }
|
| 263 | }
|
| 264 |
|
| 265 | void mbtk_at_tcpip_read_callback_func(int link_id, const char* data, int data_len)
|
| 266 | {
|
| 267 | if(data == NULL || data_len == 0)
|
| 268 | {
|
| 269 | LOG("[mbtk_at_tcpip_read_callback_func]: data is NULL.");
|
| 270 | return;
|
| 271 | }
|
| 272 |
|
| 273 | //LOG("[mbtk_at_tcpip_read_callback_func]: link_id = [%d] data_len = [%d].", link_id, data_len);
|
| 274 |
|
| 275 | int ret = 0;
|
| 276 | int offset = 0;
|
| 277 | char buf[MAX_AUTO_READ_LEN + 64] = {0};
|
| 278 |
|
| 279 | #if 0
|
| 280 | while(data_len)
|
| 281 | {
|
| 282 | memset(buf, 0x0, TEL_AT_READ_DATA_MAX + 64);
|
| 283 | ret = snprintf(buf, 63, "\r\n+CIPRXGET: SUCCESS,0,%d,%d,\r\n", link_id, data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX);
|
| 284 | LOG("[mbtk_at_tcpip_read_callback_func]: ret[%d].", ret);
|
| 285 | memcpy(buf + ret, data + offset, data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX);
|
| 286 | offset += data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX;
|
| 287 | data_len -= data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX;
|
| 288 | LOG("[mbtk_at_tcpip_read_callback_func]: offset[%d] data_len[%d].", offset, data_len);
|
| 289 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
|
| 290 | usleep(10000);
|
| 291 | }
|
| 292 | #else
|
| 293 | memset(buf, 0x0, MAX_AUTO_READ_LEN + 64);
|
| 294 | ret = snprintf(buf, 63, "\r\n+CIPRXGET: SUCCESS,0,%d,%d,\r\n", link_id, data_len);
|
| 295 | memcpy(buf + ret, data + offset, data_len);
|
| 296 | //LOG("[mbtk_at_tcpip_read_callback_func]: buff_len[%d].", strlen(buf));
|
| 297 | mbtk_tcpip_write_data(buf, strlen(buf));
|
| 298 | //ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
|
| 299 | usleep(100000);
|
| 300 | #endif
|
| 301 | }
|
| 302 |
|
| 303 | void* mbtk_tcpip_task_cmd_process(void* arg)
|
| 304 | {
|
| 305 | UNUSEDPARAM(arg);
|
| 306 | LOG("[mbtk_tcpip_task_cmd_process]: tcpip_task start run.");
|
| 307 |
|
| 308 | int ret = -1;
|
| 309 | int result_read_len = 0;
|
| 310 | char resp_buf[64] = {0};
|
| 311 | char buf[TEL_AT_READ_DATA_MAX + 1] = {0};
|
| 312 | mbtk_tcpip_tcp_state_info_s t_s_info;
|
| 313 | mbtk_signal_info* msg = NULL;
|
| 314 | mbtk_tcpip_info_t * tcpip_info = NULL;
|
| 315 |
|
| 316 | mbtk_tcpip_open_port();
|
| 317 | while(1)
|
| 318 | {
|
| 319 | msg = MBTK_FUNC(mbtk_signal_get)(&mbtk_tcpip_task);
|
| 320 | if(msg == NULL)
|
| 321 | {
|
| 322 | LOG("[mbtk_tcpip_task_cmd_process]: get signal fail [msg] = [NULL].");
|
| 323 | continue;
|
| 324 | }
|
| 325 |
|
| 326 | usleep(10000);
|
| 327 | memset(resp_buf, 0x0, 64);
|
| 328 | LOG("[mbtk_tcpip_task_cmd_process]: get signal [msg.sig] = [%d].", msg->sig);
|
| 329 | switch(msg->sig)
|
| 330 | {
|
| 331 | case MBTK_TCPIP_SIG_NETOPEN:
|
| 332 | {
|
| 333 | ret = MBTK_FUNC(mbtk_tcpip_net_open)(mbtk_at_tcpip_net_callback_func, mbtk_at_tcpip_sock_callback_func);
|
| 334 | if(ret == MBTK_TCPIP_ERR_SUCCESS)
|
| 335 | {
|
| 336 | mbtk_tcpip_net_status_set(MBTK_TCPIP_NET_STATUS_ON);
|
| 337 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETOPEN: SUCCESS\r\n");
|
| 338 | }
|
| 339 | else
|
| 340 | {
|
| 341 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_net_open fail [ret] = [%d].", ret);
|
| 342 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETOPEN: FAIL\r\n");
|
| 343 | }
|
| 344 | break;
|
| 345 | }
|
| 346 | case MBTK_TCPIP_SIG_NETCLOSE:
|
| 347 | {
|
| 348 | ret = MBTK_FUNC(mbtk_tcpip_net_close)();
|
| 349 | if(ret == MBTK_TCPIP_ERR_SUCCESS)
|
| 350 | {
|
| 351 | mbtk_tcpip_net_status_set(MBTK_TCPIP_NET_STATUS_OFF);
|
| 352 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETCLOSE: SUCCESS\r\n");
|
| 353 | }
|
| 354 | else
|
| 355 | {
|
| 356 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_net_close fail [ret] = [%d].", ret);
|
| 357 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETCLOSE: FAIL\r\n");
|
| 358 | }
|
| 359 | break;
|
| 360 | }
|
| 361 | case MBTK_TCPIP_SIG_CIPOPEN:
|
| 362 | {
|
| 363 | if(msg->payload == NULL)
|
| 364 | {
|
| 365 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipopen msg->payload is NULL.");
|
| 366 | break;
|
| 367 | }
|
| 368 |
|
| 369 | tcpip_info = (mbtk_tcpip_info_t *)msg->payload;
|
| 370 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipopen link_id[%d] type[%d] ser_IP[%s] ser_port[%d] loacl_port[%d].", tcpip_info->link_id,
|
| 371 | tcpip_info->prot_type, tcpip_info->ser_addr, tcpip_info->ser_port, tcpip_info->local_port);
|
| 372 | tcpip_info->ack_support = mbtk_tcpipip_info[tcpip_info->link_id].ack_support;
|
| 373 | tcpip_info->ssl_support = mbtk_tcpipip_info[tcpip_info->link_id].ssl_support;
|
| 374 | tcpip_info->ignore_cert = mbtk_tcpipip_info[tcpip_info->link_id].ignore_cert;
|
| 375 | tcpip_info->heartbeat_time = mbtk_heartbeat_time;
|
| 376 | tcpip_info->delay_time = mbtk_delay_time;
|
| 377 | ret = MBTK_FUNC(mbtk_tcpip_sock_open)(tcpip_info);
|
| 378 | if(ret == MBTK_TCPIP_ERR_SUCCESS)
|
| 379 | {
|
| 380 | snprintf(resp_buf, 63, "+CIPOPEN: SUCCESS, %d\r\n", tcpip_info->link_id);
|
| 381 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 382 | memcpy(&(mbtk_tcpipip_info[tcpip_info->link_id]), tcpip_info, sizeof(mbtk_tcpip_info_t));
|
| 383 | link_status[tcpip_info->link_id] = true;
|
| 384 | }
|
| 385 | else
|
| 386 | {
|
| 387 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipopen fail [ret] = [%d].", ret);
|
| 388 | snprintf(resp_buf, 63, "+CIPOPEN: FAIL, %d\r\n", tcpip_info->link_id);
|
| 389 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 390 | }
|
| 391 | break;
|
| 392 | }
|
| 393 | case MBTK_TCPIP_SIG_CIPCLOSE:
|
| 394 | {
|
| 395 | if(msg->payload == NULL)
|
| 396 | {
|
| 397 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose msg->payload is NULL.");
|
| 398 | break;
|
| 399 | }
|
| 400 |
|
| 401 | int close_link = *((int *)msg->payload);
|
| 402 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose close link_num [%d].", close_link);
|
| 403 | ret = MBTK_FUNC(mbtk_tcpip_sock_close)(close_link);
|
| 404 | if(ret == MBTK_TCPIP_ERR_SUCCESS)
|
| 405 | {
|
| 406 | snprintf(resp_buf, 63, "+CIPCLOSE: SUCCESS, %d\r\n", close_link);
|
| 407 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 408 | link_status[close_link] = false;
|
| 409 | }
|
| 410 | else
|
| 411 | {
|
| 412 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose fail [ret] = [%d].", ret);
|
| 413 | snprintf(resp_buf, 63, "+CIPCLOSE: FAIL, %d\r\n", close_link);
|
| 414 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 415 | }
|
| 416 | break;
|
| 417 | }
|
| 418 | case MBTK_TCPIP_SIG_CIPSEND:
|
| 419 | {
|
| 420 | if(msg->payload == NULL)
|
| 421 | {
|
| 422 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipsend msg->payload is NULL.");
|
| 423 | break;
|
| 424 | }
|
| 425 |
|
| 426 | mbtk_tcpip_send_info_t* info = (mbtk_tcpip_send_info_t*)msg->payload;
|
| 427 | if(info->length)
|
| 428 | {
|
| 429 | if(info->lenth_data != NULL)
|
| 430 | {
|
| 431 | ret = MBTK_FUNC(mbtk_tcpip_send)(info->link_num, info->lenth_data, info->length, info->ser_addr, info->ser_port);
|
| 432 | if(info->lenth_data)
|
| 433 | {
|
| 434 | free(info->lenth_data);
|
| 435 | info->lenth_data = NULL;
|
| 436 | }
|
| 437 | }
|
| 438 | else
|
| 439 | {
|
| 440 | ret = -1;
|
| 441 | }
|
| 442 | }
|
| 443 | else
|
| 444 | {
|
| 445 | ret = MBTK_FUNC(mbtk_tcpip_send)(info->link_num, info->data, strlen(info->data), info->ser_addr, info->ser_port);
|
| 446 | }
|
| 447 | if(ret > 0)
|
| 448 | {
|
| 449 | if(info->length)
|
| 450 | {
|
| 451 | snprintf(resp_buf, 63, "+CIPSEND: SUCCESS,%d,%d,%d\r\n", info->link_num, info->length, ret);
|
| 452 | }
|
| 453 | else
|
| 454 | {
|
| 455 | snprintf(resp_buf, 63, "+CIPSEND: SUCCESS,%d,%d,%d\r\n", info->link_num, strlen(info->data), ret);
|
| 456 | }
|
| 457 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 458 | }
|
| 459 | else if(ret < 0)
|
| 460 | {
|
| 461 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipsend fail [ret] = [%d].", ret);
|
| 462 | snprintf(resp_buf, 63, "+CIPSEND: FAIL, %d\r\n", info->link_num);
|
| 463 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 464 | }
|
| 465 | break;
|
| 466 | }
|
| 467 | case MBTK_TCPIP_SIG_CIPRXGET:
|
| 468 | {
|
| 469 | if(msg->payload == NULL)
|
| 470 | {
|
| 471 | LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipreget msg->payload is NULL.");
|
| 472 | break;
|
| 473 | }
|
| 474 |
|
| 475 | mbtk_tcpip_read_info_t* info = (mbtk_tcpip_read_info_t*)msg->payload;
|
| 476 | if(info->read_mode < MBTK_TCPIP_READ_MANUALLY_DATA)
|
| 477 | {
|
| 478 | if(info->read_mode == MBTK_TCPIP_READ_AUTO)
|
| 479 | {
|
| 480 | MBTK_FUNC(mbtk_tcpip_set_read_cb)(info->link_num, mbtk_at_tcpip_read_callback_func);
|
| 481 | }
|
| 482 | else
|
| 483 | {
|
| 484 | MBTK_FUNC(mbtk_tcpip_set_read_cb)(info->link_num, NULL);
|
| 485 | }
|
| 486 |
|
| 487 | mbtk_tcpip_read_type_set(info->link_num, info->read_mode);
|
| 488 | snprintf(resp_buf, 63, "+CIPRXGET: SUCCESS,%d,%d\r\n", info->read_mode, info->link_num);
|
| 489 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 490 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
|
| 491 | break;
|
| 492 | }
|
| 493 |
|
| 494 | memset(buf, 0x0, TEL_AT_READ_DATA_MAX + 1);
|
| 495 | result_read_len = 0;
|
| 496 | if(info->read_len > 0)
|
| 497 | {
|
| 498 | result_read_len = MBTK_FUNC(mbtk_tcpip_read)(info->link_num, buf, info->read_len);
|
| 499 | if(result_read_len < 0)
|
| 500 | {
|
| 501 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
|
| 502 | break;
|
| 503 | }
|
| 504 | else if(result_read_len == 0)
|
| 505 | {
|
| 506 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
|
| 507 | break;
|
| 508 | }
|
| 509 | }
|
| 510 |
|
| 511 | memset(&t_s_info, 0x0, sizeof(mbtk_tcpip_tcp_state_info_s));
|
| 512 | MBTK_FUNC(mbtk_tcpip_info_get)(info->link_num, &t_s_info);
|
| 513 | snprintf(resp_buf, 63, "+CIPRXGET: SUCCESS,1,%d,%d,%d,", info->link_num, result_read_len,t_s_info.recv_data_len);
|
| 514 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
|
| 515 | usleep(5000);
|
| 516 | //ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
|
| 517 | mbtk_tcpip_write_data(buf, result_read_len);
|
| 518 | ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
|
| 519 | break;
|
| 520 | }
|
| 521 | #if 0
|
| 522 | case MBTK_TCPIP_SIG_MCIPCFGPL:
|
| 523 | {
|
| 524 | break;
|
| 525 | }
|
| 526 | case MBTK_TCPIP_SIG_MCIPCFG:
|
| 527 | {
|
| 528 | break;
|
| 529 | }
|
| 530 | case MBTK_TCPIP_SIG_USEDDATA:
|
| 531 | {
|
| 532 | break;
|
| 533 | }
|
| 534 | case MBTK_TCPIP_SIG_CLEARDATA:
|
| 535 | {
|
| 536 | break;
|
| 537 | }
|
| 538 | case MBTK_TCPIP_SIG_CIPOPQUERY:
|
| 539 | {
|
| 540 | break;
|
| 541 | }
|
| 542 | #endif
|
| 543 | default:
|
| 544 | {
|
| 545 | break;
|
| 546 | }
|
| 547 | }
|
| 548 |
|
| 549 | if(msg != NULL)
|
| 550 | {
|
| 551 | if(msg->payload != NULL)
|
| 552 | {
|
| 553 | free(msg->payload);
|
| 554 | msg->payload = NULL;
|
| 555 | }
|
| 556 | free(msg);
|
| 557 | msg = NULL;
|
| 558 | }
|
| 559 | }
|
| 560 |
|
| 561 | LOG("[mbtk_tcpip_task_cmd_process]: tcpip_task exit.");
|
| 562 | return NULL;
|
| 563 | }
|
| 564 |
|
| 565 | mbtk_tcpip_result_enum mbtk_at_tcpip_init(void)
|
| 566 | {
|
| 567 | LOG("[mbtk_at_tcpip_init]: entry func [tcpip_thread_init] = [%d].", mbtk_tcpip_thread_status_get());
|
| 568 |
|
| 569 | int ret = 0;
|
| 570 | if(!mbtk_tcpip_thread_status_get())
|
| 571 | {
|
| 572 | memset(&mbtk_tcpip_task, 0x0, sizeof(mbtk_tcpip_task));
|
| 573 | ret = MBTK_FUNC(mbtk_task_queue_start)(&mbtk_tcpip_task,mbtk_tcpip_task_cmd_process);
|
| 574 | if(ret)
|
| 575 | {
|
| 576 | LOG("[mbtk_at_tcpip_init]: creat tcpip task_queue fail.");
|
| 577 | return MBTK_TCPIP_RESULT_FAIL;
|
| 578 | }
|
| 579 |
|
| 580 | LOG("[mbtk_at_tcpip_init]: creat tcpip task_queue success.");
|
| 581 | usleep(500000);
|
| 582 | mbtk_tcpip_thread_status_set(1);
|
| 583 | }
|
| 584 |
|
| 585 | return MBTK_TCPIP_RESULT_SUCCESS;
|
| 586 | }
|
| 587 |
|
| 588 | mbtk_tcpip_result_enum mbtk_tcpip_sig_send(mbtk_tcpip_at_type_enum sig, void* payload)
|
| 589 | {
|
| 590 | int ret = 0;
|
| 591 | mbtk_signal_info* info = NULL;
|
| 592 |
|
| 593 | if(!mbtk_tcpip_thread_status_get())
|
| 594 | {
|
| 595 | ret = mbtk_at_tcpip_init();
|
| 596 | if(ret)
|
| 597 | {
|
| 598 | LOG("[mbtk_tcpip_sig_send]: mbtk_at_tcpip_init fail [ret] = [%d].", ret);
|
| 599 | return MBTK_TCPIP_RESULT_FAIL;
|
| 600 | }
|
| 601 | }
|
| 602 |
|
| 603 | info = (mbtk_signal_info*)malloc(sizeof(mbtk_signal_info));
|
| 604 | if(info == NULL)
|
| 605 | {
|
| 606 | LOG("[mbtk_tcpip_sig_send]: malloc fail.");
|
| 607 | return MBTK_TCPIP_RESULT_FAIL;
|
| 608 | }
|
| 609 | else
|
| 610 | {
|
| 611 | memset(info, 0x0, sizeof(mbtk_signal_info));
|
| 612 | info->sig = sig;
|
| 613 | if(payload == NULL)
|
| 614 | {
|
| 615 | info->payload = NULL;
|
| 616 | }
|
| 617 | else
|
| 618 | {
|
| 619 | info->payload = payload;
|
| 620 | }
|
| 621 | }
|
| 622 |
|
| 623 | ret = MBTK_FUNC(mbtk_signal_send)(&mbtk_tcpip_task, info);
|
| 624 | if(ret)
|
| 625 | {
|
| 626 | LOG("[mbtk_tcpip_sig_send]: send tcpip sig fail [ret] = [%d].", ret);
|
| 627 | if(info != NULL)
|
| 628 | {
|
| 629 | if(info->payload != NULL)
|
| 630 | {
|
| 631 | free(info->payload);
|
| 632 | info->payload = NULL;
|
| 633 | }
|
| 634 | free(info);
|
| 635 | info = NULL;
|
| 636 | }
|
| 637 | return MBTK_TCPIP_RESULT_FAIL;
|
| 638 | }
|
| 639 |
|
| 640 | LOG("[mbtk_tcpip_sig_send]: send tcpip sig success.");
|
| 641 | return MBTK_TCPIP_RESULT_SUCCESS;
|
| 642 | }
|
| 643 |
|
| 644 | #ifdef MBTK_DATA_MODE_SUPPORT
|
| 645 | static void tcpip_data_mode_callback_cb(const char *data, int data_len)
|
| 646 | {
|
| 647 | LOG("[tcpip_data_mode_callback_cb]: DATA - %d:%s.", data_len, data);
|
| 648 |
|
| 649 | if(data_len == data_mode_info.length)
|
| 650 | {
|
| 651 | char *data_buff = NULL;
|
| 652 | mbtk_tcpip_send_info_t* info = NULL;
|
| 653 | info = (mbtk_tcpip_send_info_t*)malloc(sizeof(mbtk_tcpip_send_info_t));
|
| 654 | if(info == NULL)
|
| 655 | {
|
| 656 | LOG("[tcpip_data_mode_callback_cb]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
|
| 657 | ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
|
| 658 | return;
|
| 659 | }
|
| 660 |
|
| 661 | memset(info, 0x0, sizeof(mbtk_tcpip_send_info_t));
|
| 662 | info->link_num = data_mode_info.link_num;
|
| 663 | info->length = data_mode_info.length;
|
| 664 | memcpy(info->ser_addr, data_mode_info.ser_addr, strlen(data_mode_info.ser_addr));
|
| 665 | info->ser_port = data_mode_info.ser_port;
|
| 666 |
|
| 667 | data_buff = (char *)malloc(data_len + 1);
|
| 668 | if(data_buff == NULL)
|
| 669 | {
|
| 670 | LOG("[tcpip_data_mode_callback_cb]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
|
| 671 | free(info);
|
| 672 | info = NULL;
|
| 673 | ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
|
| 674 | return;
|
| 675 | }
|
| 676 | memcpy(data_buff, data, data_len);
|
| 677 | info->lenth_data = data_buff;
|
| 678 | if(mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPSEND, info))
|
| 679 | {
|
| 680 | ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
|
| 681 | free(data_buff);
|
| 682 | data_buff = NULL;
|
| 683 | }
|
| 684 | else
|
| 685 | {
|
| 686 | ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
|
| 687 | }
|
| 688 | }
|
| 689 | else
|
| 690 | {
|
| 691 | ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
|
| 692 | }
|
| 693 | }
|
| 694 | #endif
|
| 695 |
|
| 696 |
|
| 697 | /***********************************************************AT COMMAND************************************************/
|
| 698 |
|
| 699 | utlReturnCode_T MBTK_AT_NETOPEN_PROCESS( const utlAtParameterOp_T op,
|
| 700 | const char *command_name_p,
|
| 701 | const utlAtParameterValue_P2c parameter_values_p,
|
| 702 | const size_t num_parameters,
|
| 703 | const char *info_text_p,
|
| 704 | unsigned int *xid_p,
|
| 705 | void *arg_p)
|
| 706 | {
|
| 707 | UNUSEDPARAM(command_name_p);
|
| 708 | UNUSEDPARAM(num_parameters);
|
| 709 | UNUSEDPARAM(info_text_p);
|
| 710 |
|
| 711 | utlReturnCode_T ret = utlFAILED;
|
| 712 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 713 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 714 | *xid_p = atHandle;
|
| 715 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 716 |
|
| 717 | LOG("[at_command_tcpip]: MBTK_AT_NETOPEN_PROCESS enter with command_op [%s]", op2str(op));
|
| 718 |
|
| 719 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 720 |
|
| 721 | switch(op)
|
| 722 | {
|
| 723 | case TEL_EXT_GET_CMD:
|
| 724 | {
|
| 725 | sprintf(resp_buf, "+NETOPEN: %d\r\n", mbtk_tcpip_net_status_get());
|
| 726 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 727 | break;
|
| 728 | }
|
| 729 | case TEL_EXT_ACTION_CMD:
|
| 730 | {
|
| 731 | if(mbtk_tcpip_net_status_get())
|
| 732 | {
|
| 733 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
|
| 734 | break;
|
| 735 | }
|
| 736 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_NETOPEN, NULL);
|
| 737 | if(tcpip_ret)
|
| 738 | {
|
| 739 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 740 | }
|
| 741 | else
|
| 742 | {
|
| 743 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 744 | }
|
| 745 | break;
|
| 746 | }
|
| 747 | default:
|
| 748 | {
|
| 749 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 750 | break;
|
| 751 | }
|
| 752 | }
|
| 753 |
|
| 754 | return ret;
|
| 755 | }
|
| 756 |
|
| 757 | utlReturnCode_T MBTK_AT_NETCLOSE_PROCESS( const utlAtParameterOp_T op,
|
| 758 | const char *command_name_p,
|
| 759 | const utlAtParameterValue_P2c parameter_values_p,
|
| 760 | const size_t num_parameters,
|
| 761 | const char *info_text_p,
|
| 762 | unsigned int *xid_p,
|
| 763 | void *arg_p)
|
| 764 | {
|
| 765 | UNUSEDPARAM(command_name_p);
|
| 766 | UNUSEDPARAM(num_parameters);
|
| 767 | UNUSEDPARAM(info_text_p);
|
| 768 |
|
| 769 | utlReturnCode_T ret = utlFAILED;
|
| 770 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 771 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 772 | *xid_p = atHandle;
|
| 773 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 774 |
|
| 775 | LOG("[at_command_tcpip]: MBTK_AT_NETCLOSE_PROCESS enter with command_op [%s]", op2str(op));
|
| 776 |
|
| 777 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 778 |
|
| 779 | switch(op)
|
| 780 | {
|
| 781 | case TEL_EXT_GET_CMD:
|
| 782 | {
|
| 783 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 784 | break;
|
| 785 | }
|
| 786 | case TEL_EXT_ACTION_CMD:
|
| 787 | {
|
| 788 | if(!mbtk_tcpip_net_status_get())
|
| 789 | {
|
| 790 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
|
| 791 | break;
|
| 792 | }
|
| 793 |
|
| 794 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_NETCLOSE, NULL);
|
| 795 | if(tcpip_ret)
|
| 796 | {
|
| 797 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 798 | }
|
| 799 | else
|
| 800 | {
|
| 801 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 802 | }
|
| 803 | break;
|
| 804 | }
|
| 805 | default:
|
| 806 | {
|
| 807 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 808 | break;
|
| 809 | }
|
| 810 | }
|
| 811 |
|
| 812 | return ret;
|
| 813 | }
|
| 814 |
|
| 815 | utlReturnCode_T MBTK_AT_CIPOPEN_PROCESS( const utlAtParameterOp_T op,
|
| 816 | const char *command_name_p,
|
| 817 | const utlAtParameterValue_P2c parameter_values_p,
|
| 818 | const size_t num_parameters,
|
| 819 | const char *info_text_p,
|
| 820 | unsigned int *xid_p,
|
| 821 | void *arg_p)
|
| 822 | {
|
| 823 | UNUSEDPARAM(command_name_p);
|
| 824 | UNUSEDPARAM(num_parameters);
|
| 825 | UNUSEDPARAM(info_text_p);
|
| 826 |
|
| 827 | utlReturnCode_T ret = utlFAILED;
|
| 828 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 829 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 830 | *xid_p = atHandle;
|
| 831 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 832 |
|
| 833 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS enter with command_op [%s].", op2str(op));
|
| 834 |
|
| 835 | int socketID;
|
| 836 | int dstPort = -1;
|
| 837 | mbtk_sock_type port_type = MBTK_SOCK_TCP;
|
| 838 | int type_size = 0;
|
| 839 | int dstIPlen = 0;
|
| 840 | int localport = -1;
|
| 841 | int i = 0;
|
| 842 | int offset_ret = 0;
|
| 843 | char netType[MAX_NETTYPE_LEN] = {0};
|
| 844 | char dstIP[MAX_IP_LEN + 1] = {0};
|
| 845 | bool flag = false;
|
| 846 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 847 |
|
| 848 | if(!mbtk_tcpip_net_status_get())
|
| 849 | {
|
| 850 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS net not open.");
|
| 851 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 852 | return ret;
|
| 853 | }
|
| 854 |
|
| 855 | switch(op)
|
| 856 | {
|
| 857 | case TEL_EXT_GET_CMD:
|
| 858 | {
|
| 859 | offset_ret = sprintf(resp_buf, "+CIPOPEN: ");
|
| 860 | for(i = 0; i < MAX_LINK_NUM; i++)
|
| 861 | {
|
| 862 | if(link_status[i])
|
| 863 | {
|
| 864 | offset_ret += sprintf(resp_buf + offset_ret, "%d,%d,%s,%d\r\n", mbtk_tcpipip_info[i].link_id, mbtk_tcpipip_info[i].prot_type, mbtk_tcpipip_info[i].ser_addr, mbtk_tcpipip_info[i].ser_port);
|
| 865 | flag = true;
|
| 866 | }
|
| 867 | }
|
| 868 |
|
| 869 | if(true == flag)
|
| 870 | {
|
| 871 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 872 | }
|
| 873 | else
|
| 874 | {
|
| 875 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 876 | }
|
| 877 | break;
|
| 878 | }
|
| 879 | case TEL_EXT_SET_CMD:
|
| 880 | {
|
| 881 | if( getExtValue( parameter_values_p, 0, &socketID, TEL_AT_MYNET_SOCKET_ID_MIN, TEL_AT_MYNET_SOCKET_ID_MAX, TEL_AT_MYNET_SOCKET_ID_DEFAULT) == FALSE )
|
| 882 | {
|
| 883 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 884 | break;
|
| 885 | }
|
| 886 |
|
| 887 | if(link_status[socketID] == true)
|
| 888 | {
|
| 889 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
|
| 890 | break;
|
| 891 | }
|
| 892 |
|
| 893 | memset(netType,0,MAX_NETTYPE_LEN);
|
| 894 | if( getExtString( parameter_values_p, 1, netType, 3, &type_size, 0 ) == FALSE )
|
| 895 | {
|
| 896 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 897 | break;
|
| 898 | }
|
| 899 |
|
| 900 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS get port type type_size[%d].", type_size);
|
| 901 | if(strncasecmp((char *)netType, "TCP", 3) == 0)
|
| 902 | {
|
| 903 | if(parameter_values_p[2].is_default && parameter_values_p[3].is_default)
|
| 904 | {
|
| 905 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 906 | break;
|
| 907 | }
|
| 908 | if( getExtString( parameter_values_p, 2, dstIP, MAX_IP_LEN, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
|
| 909 | {
|
| 910 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 911 | break;
|
| 912 | }
|
| 913 | if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT) == FALSE )
|
| 914 | {
|
| 915 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 916 | break;
|
| 917 | }
|
| 918 | port_type = MBTK_SOCK_TCP;
|
| 919 | }
|
| 920 | else if(strncasecmp((char *)netType, "UDP", 3) == 0)
|
| 921 | {
|
| 922 | if( getExtString( parameter_values_p, 2, dstIP, 64, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
|
| 923 | {
|
| 924 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 925 | break;
|
| 926 | }
|
| 927 | if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, 0 ) == FALSE )
|
| 928 | {
|
| 929 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 930 | break;
|
| 931 | }
|
| 932 | port_type = MBTK_SOCK_UDP;
|
| 933 | }
|
| 934 | else{
|
| 935 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 936 | break;
|
| 937 | }
|
| 938 | if( getExtValue( parameter_values_p, 4, &localport, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT ) == FALSE )
|
| 939 | {
|
| 940 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 941 | break;
|
| 942 | }
|
| 943 |
|
| 944 | mbtk_tcpip_info_t* info = NULL;
|
| 945 | info = ( mbtk_tcpip_info_t*)malloc(sizeof(mbtk_tcpip_info_t));
|
| 946 | if(info == NULL)
|
| 947 | {
|
| 948 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS malloc fail.");
|
| 949 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 950 | break;
|
| 951 | }
|
| 952 |
|
| 953 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS link_id[%d] type[%d] ser_IP[%s] ser_port[%d] loacl_port[%d].", socketID, port_type, dstIP, dstPort, localport);
|
| 954 | memset(info, 0x0, sizeof(mbtk_tcpip_info_t));
|
| 955 | info->link_id = socketID;
|
| 956 | info->prot_type = port_type;
|
| 957 | memcpy(info->ser_addr, dstIP, MAX_IP_LEN);
|
| 958 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS info->ser_addr[%s] dstIPlen[%d].", info->ser_addr, dstIPlen);
|
| 959 | info->ser_port = dstPort;
|
| 960 | info->local_port = localport;
|
| 961 | if(mbtk_tcpip_read_type_get(socketID) == MBTK_TCPIP_READ_AUTO)
|
| 962 | {
|
| 963 | info->read_cb = mbtk_at_tcpip_read_callback_func;
|
| 964 | }
|
| 965 | else
|
| 966 | {
|
| 967 | info->read_cb = NULL;
|
| 968 | }
|
| 969 |
|
| 970 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPOPEN, info);
|
| 971 | if(tcpip_ret)
|
| 972 | {
|
| 973 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 974 | }
|
| 975 | else
|
| 976 | {
|
| 977 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 978 | }
|
| 979 | break;
|
| 980 | }
|
| 981 | default:
|
| 982 | {
|
| 983 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 984 | break;
|
| 985 | }
|
| 986 | }
|
| 987 |
|
| 988 | return ret;
|
| 989 | }
|
| 990 |
|
| 991 | utlReturnCode_T MBTK_AT_CIPCLOSE_PROCESS( const utlAtParameterOp_T op,
|
| 992 | const char *command_name_p,
|
| 993 | const utlAtParameterValue_P2c parameter_values_p,
|
| 994 | const size_t num_parameters,
|
| 995 | const char *info_text_p,
|
| 996 | unsigned int *xid_p,
|
| 997 | void *arg_p)
|
| 998 | {
|
| 999 | UNUSEDPARAM(command_name_p);
|
| 1000 | UNUSEDPARAM(num_parameters);
|
| 1001 | UNUSEDPARAM(info_text_p);
|
| 1002 |
|
| 1003 | utlReturnCode_T ret = utlFAILED;
|
| 1004 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1005 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1006 | *xid_p = atHandle;
|
| 1007 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1008 |
|
| 1009 | LOG("[at_command_tcpip]: MBTK_AT_CIPCLOSE_PROCESS enter with command_op [%s].", op2str(op));
|
| 1010 |
|
| 1011 | int link_num;
|
| 1012 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 1013 | switch(op)
|
| 1014 | {
|
| 1015 | case TEL_EXT_GET_CMD:
|
| 1016 | {
|
| 1017 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1018 | break;
|
| 1019 | }
|
| 1020 | case TEL_EXT_SET_CMD:
|
| 1021 | {
|
| 1022 | if( getExtValue( parameter_values_p, 0, &link_num, TEL_AT_MYNET_SOCKET_ID_MIN, TEL_AT_MYNET_SOCKET_ID_MAX, TEL_AT_MYNET_SOCKET_ID_DEFAULT) == FALSE )
|
| 1023 | {
|
| 1024 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1025 | break;
|
| 1026 | }
|
| 1027 |
|
| 1028 | if(link_status[link_num] == false)
|
| 1029 | {
|
| 1030 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1031 | break;
|
| 1032 | }
|
| 1033 |
|
| 1034 | int* info = NULL;
|
| 1035 | info = (int*)malloc(sizeof(int));
|
| 1036 | if(info == NULL)
|
| 1037 | {
|
| 1038 | LOG("[at_command_tcpip]: MBTK_AT_CIPCLOSE_PROCESS malloc fail.");
|
| 1039 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1040 | break;
|
| 1041 | }
|
| 1042 |
|
| 1043 | *info = link_num;
|
| 1044 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPCLOSE, info);
|
| 1045 | if(tcpip_ret)
|
| 1046 | {
|
| 1047 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1048 | }
|
| 1049 | else
|
| 1050 | {
|
| 1051 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1052 | }
|
| 1053 | break;
|
| 1054 | }
|
| 1055 | default:
|
| 1056 | {
|
| 1057 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1058 | break;
|
| 1059 | }
|
| 1060 | }
|
| 1061 |
|
| 1062 | return ret;
|
| 1063 | }
|
| 1064 |
|
| 1065 | utlReturnCode_T MBTK_AT_CIPSEND_PROCESS( const utlAtParameterOp_T op,
|
| 1066 | const char *command_name_p,
|
| 1067 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1068 | const size_t num_parameters,
|
| 1069 | const char *info_text_p,
|
| 1070 | unsigned int *xid_p,
|
| 1071 | void *arg_p)
|
| 1072 | {
|
| 1073 | UNUSEDPARAM(command_name_p);
|
| 1074 | UNUSEDPARAM(num_parameters);
|
| 1075 | UNUSEDPARAM(info_text_p);
|
| 1076 |
|
| 1077 | utlReturnCode_T ret = utlFAILED;
|
| 1078 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1079 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1080 | *xid_p = atHandle;
|
| 1081 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1082 |
|
| 1083 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS enter with command_op [%s].", op2str(op));
|
| 1084 |
|
| 1085 | int link_num = 0;
|
| 1086 | int length = 0;
|
| 1087 | int dstIPlen = 0;
|
| 1088 | int dstPort = 0;
|
| 1089 | int data_len = 0;
|
| 1090 | char dstIP[MAX_IP_LEN + 1] = {0};
|
| 1091 | char data[MAX_DATA_LEN + 1] = {0};
|
| 1092 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 1093 | switch(op)
|
| 1094 | {
|
| 1095 | case TEL_EXT_GET_CMD:
|
| 1096 | {
|
| 1097 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1098 | break;
|
| 1099 | }
|
| 1100 | case TEL_EXT_SET_CMD:
|
| 1101 | {
|
| 1102 | if( getExtValue( parameter_values_p, 0, &link_num, TEL_AT_MYNET_SOCKET_ID_MIN, TEL_AT_MYNET_SOCKET_ID_MAX, TEL_AT_MYNET_SOCKET_ID_DEFAULT) == FALSE )
|
| 1103 | {
|
| 1104 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1105 | break;
|
| 1106 | }
|
| 1107 |
|
| 1108 | if(link_status[link_num] == false)
|
| 1109 | {
|
| 1110 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS link_num[%d] not open.", link_num);
|
| 1111 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1112 | break;
|
| 1113 | }
|
| 1114 |
|
| 1115 | if( getExtValue( parameter_values_p, 1, &length, TEL_AT_SEND_DATA_PARAM_MIN, TEL_AT_SEND_DATA_PARAM_MAX, TEL_AT_SEND_DATA_PARAM_DEFAULT) == FALSE )
|
| 1116 | {
|
| 1117 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1118 | break;
|
| 1119 | }
|
| 1120 |
|
| 1121 | if( getExtString( parameter_values_p, 2, dstIP, MAX_IP_LEN, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
|
| 1122 | {
|
| 1123 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1124 | break;
|
| 1125 | }
|
| 1126 | if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT) == FALSE )
|
| 1127 | {
|
| 1128 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1129 | break;
|
| 1130 | }
|
| 1131 |
|
| 1132 | if(length > 0)
|
| 1133 | {
|
| 1134 | #ifdef MBTK_DATA_MODE_SUPPORT
|
| 1135 | if(!parameter_values_p[4].is_default)
|
| 1136 | {
|
| 1137 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS param error.");
|
| 1138 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1139 | break;
|
| 1140 | }
|
| 1141 |
|
| 1142 | data_mode_info.link_num = link_num;
|
| 1143 | data_mode_info.length = length;
|
| 1144 | memcpy(data_mode_info.ser_addr, dstIP, dstIPlen);
|
| 1145 | data_mode_info.ser_port = dstPort;
|
| 1146 | data_mode_atHandle = atHandle;
|
| 1147 | ret = mbtk_data_mode_enter(sAtp_index, tcpip_data_mode_callback_cb);
|
| 1148 | break;
|
| 1149 | #else
|
| 1150 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1151 | break;
|
| 1152 | #endif
|
| 1153 | }
|
| 1154 | else
|
| 1155 | {
|
| 1156 | if(parameter_values_p[4].is_default)
|
| 1157 | {
|
| 1158 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS data is NULL.");
|
| 1159 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1160 | break;
|
| 1161 | }
|
| 1162 |
|
| 1163 | if( getExtString( parameter_values_p, 4, data, MAX_DATA_LEN, &data_len, TEL_AT_TCPIP_STR_DEFAULT ) == FALSE )
|
| 1164 | {
|
| 1165 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1166 | break;
|
| 1167 | }
|
| 1168 | }
|
| 1169 |
|
| 1170 | mbtk_tcpip_send_info_t* info = NULL;
|
| 1171 | info = (mbtk_tcpip_send_info_t*)malloc(sizeof(mbtk_tcpip_send_info_t));
|
| 1172 | if(info == NULL)
|
| 1173 | {
|
| 1174 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
|
| 1175 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1176 | break;
|
| 1177 | }
|
| 1178 |
|
| 1179 | LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS dstIPlen[%d] data_len[%d].", dstIPlen, data_len);
|
| 1180 | memset(info, 0x0, sizeof(mbtk_tcpip_send_info_t));
|
| 1181 | info->link_num = link_num;
|
| 1182 | info->length = length;
|
| 1183 | memcpy(info->ser_addr, dstIP, dstIPlen);
|
| 1184 | info->ser_port = dstPort;
|
| 1185 | memcpy(info->data, data, data_len);
|
| 1186 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPSEND, info);
|
| 1187 | if(tcpip_ret)
|
| 1188 | {
|
| 1189 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1190 | }
|
| 1191 | else
|
| 1192 | {
|
| 1193 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1194 | }
|
| 1195 | break;
|
| 1196 | }
|
| 1197 | default:
|
| 1198 | {
|
| 1199 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1200 | break;
|
| 1201 | }
|
| 1202 | }
|
| 1203 |
|
| 1204 | return ret;
|
| 1205 | }
|
| 1206 |
|
| 1207 | utlReturnCode_T MBTK_AT_CIPRXGET_PROCESS( const utlAtParameterOp_T op,
|
| 1208 | const char *command_name_p,
|
| 1209 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1210 | const size_t num_parameters,
|
| 1211 | const char *info_text_p,
|
| 1212 | unsigned int *xid_p,
|
| 1213 | void *arg_p)
|
| 1214 | {
|
| 1215 | UNUSEDPARAM(command_name_p);
|
| 1216 | UNUSEDPARAM(num_parameters);
|
| 1217 | UNUSEDPARAM(info_text_p);
|
| 1218 |
|
| 1219 | utlReturnCode_T ret = utlFAILED;
|
| 1220 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1221 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1222 | *xid_p = atHandle;
|
| 1223 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1224 |
|
| 1225 | LOG("[at_command_tcpip]: MBTK_AT_CIPRXGET_PROCESS enter with command_op [%s].", op2str(op));
|
| 1226 |
|
| 1227 | mbtk_tcpip_read_type_enum read_mode = MBTK_TCPIP_READ_AUTO;
|
| 1228 | int link_num = 0;
|
| 1229 | int read_len = 0;
|
| 1230 | mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
|
| 1231 | switch(op)
|
| 1232 | {
|
| 1233 | case TEL_EXT_GET_CMD:
|
| 1234 | {
|
| 1235 | sprintf(resp_buf, "+CIPRXGET: %d,%d,%d,%d", read_type[0], read_type[1], read_type[2], read_type[3]);
|
| 1236 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 1237 | break;
|
| 1238 | }
|
| 1239 | case TEL_EXT_SET_CMD:
|
| 1240 | {
|
| 1241 | if( getExtValue( parameter_values_p, 0, &read_mode, TEL_AT_READ_MODE_MIN, TEL_AT_READ_MODE_MAX, TEL_AT_READ_MODE_DEFAULT) == FALSE )
|
| 1242 | {
|
| 1243 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1244 | break;
|
| 1245 | }
|
| 1246 |
|
| 1247 | if(read_mode < MBTK_TCPIP_READ_MANUALLY_DATA && !parameter_values_p[2].is_default)
|
| 1248 | {
|
| 1249 | LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS param error.");
|
| 1250 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1251 | break;
|
| 1252 | }
|
| 1253 |
|
| 1254 | if( getExtValue( parameter_values_p, 1, &link_num, TEL_AT_MYNET_SOCKET_ID_MIN, TEL_AT_MYNET_SOCKET_ID_MAX, TEL_AT_MYNET_SOCKET_ID_DEFAULT) == FALSE )
|
| 1255 | {
|
| 1256 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1257 | break;
|
| 1258 | }
|
| 1259 |
|
| 1260 | if(read_mode >= MBTK_TCPIP_READ_MANUALLY_DATA)
|
| 1261 | {
|
| 1262 | if(link_status[link_num] && !parameter_values_p[2].is_default)
|
| 1263 | {
|
| 1264 | if( getExtValue( parameter_values_p, 2, &read_len, TEL_AT_READ_DATA_MIN, TEL_AT_READ_DATA_MAX, TEL_AT_READ_DATA_DEFAULT) == FALSE )
|
| 1265 | {
|
| 1266 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1267 | break;
|
| 1268 | }
|
| 1269 | }
|
| 1270 | else
|
| 1271 | {
|
| 1272 | LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS link not open or param is error.");
|
| 1273 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1274 | break;
|
| 1275 | }
|
| 1276 | }
|
| 1277 |
|
| 1278 | mbtk_tcpip_read_info_t* info = NULL;
|
| 1279 | info = (mbtk_tcpip_read_info_t*)malloc(sizeof(mbtk_tcpip_read_info_t));
|
| 1280 | if(info == NULL)
|
| 1281 | {
|
| 1282 | LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS malloc fail.");
|
| 1283 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1284 | break;
|
| 1285 | }
|
| 1286 |
|
| 1287 | memset(info, 0x0, sizeof(mbtk_tcpip_read_info_t));
|
| 1288 | info->link_num = link_num;
|
| 1289 | info->read_mode = read_mode;
|
| 1290 | info->read_len = read_len;
|
| 1291 | tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPRXGET, info);
|
| 1292 | if(tcpip_ret)
|
| 1293 | {
|
| 1294 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1295 | }
|
| 1296 | else
|
| 1297 | {
|
| 1298 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, NULL);
|
| 1299 | }
|
| 1300 | break;
|
| 1301 | }
|
| 1302 | default:
|
| 1303 | {
|
| 1304 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1305 | break;
|
| 1306 | }
|
| 1307 | }
|
| 1308 |
|
| 1309 | return ret;
|
| 1310 | }
|
| 1311 |
|
| 1312 | utlReturnCode_T MBTK_AT_MCIPCFGPL_PROCESS( const utlAtParameterOp_T op,
|
| 1313 | const char *command_name_p,
|
| 1314 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1315 | const size_t num_parameters,
|
| 1316 | const char *info_text_p,
|
| 1317 | unsigned int *xid_p,
|
| 1318 | void *arg_p)
|
| 1319 | {
|
| 1320 | UNUSEDPARAM(command_name_p);
|
| 1321 | UNUSEDPARAM(num_parameters);
|
| 1322 | UNUSEDPARAM(info_text_p);
|
| 1323 |
|
| 1324 | utlReturnCode_T ret = utlFAILED;
|
| 1325 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1326 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1327 | *xid_p = atHandle;
|
| 1328 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1329 |
|
| 1330 | LOG("[at_command_tcpip]: MBTK_AT_MCIPCFGPL_PROCESS enter with command_op [%s].", op2str(op));
|
| 1331 |
|
| 1332 | int link_id = 0;
|
| 1333 | int hex_support;
|
| 1334 | int ack_support;
|
| 1335 | int ssl_support;
|
| 1336 | int ignore_cert;
|
| 1337 | int num_ret = 0;
|
| 1338 | int i = 0;
|
| 1339 | switch(op)
|
| 1340 | {
|
| 1341 | case TEL_EXT_GET_CMD:
|
| 1342 | {
|
| 1343 | num_ret = sprintf(resp_buf,"+MCIPCFGPL: ");
|
| 1344 | for(; i < MAX_LINK_NUM; i++)
|
| 1345 | {
|
| 1346 | num_ret += sprintf(resp_buf + num_ret,"%d,%d,%d,%d\r\n", 0,
|
| 1347 | mbtk_tcpipip_info[i].ack_support, mbtk_tcpipip_info[i].ssl_support, mbtk_tcpipip_info[i].ignore_cert);
|
| 1348 | }
|
| 1349 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 1350 | break;
|
| 1351 | }
|
| 1352 | case TEL_EXT_SET_CMD:
|
| 1353 | {
|
| 1354 | if( getExtValue( parameter_values_p, 0, &link_id, TEL_AT_MYNET_SOCKET_ID_MIN, TEL_AT_MYNET_SOCKET_ID_MAX, TEL_AT_MYNET_SOCKET_ID_DEFAULT) == FALSE )
|
| 1355 | {
|
| 1356 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1357 | break;
|
| 1358 | }
|
| 1359 |
|
| 1360 | if( getExtValue( parameter_values_p, 1, &hex_support, 0, 1, 0) == FALSE )
|
| 1361 | {
|
| 1362 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1363 | break;
|
| 1364 | }
|
| 1365 |
|
| 1366 | if( getExtValue( parameter_values_p, 2, &ack_support, 0, 1, 0) == FALSE )
|
| 1367 | {
|
| 1368 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1369 | break;
|
| 1370 | }
|
| 1371 |
|
| 1372 | if( getExtValue( parameter_values_p, 3, &ssl_support, 0, 1, 0) == FALSE )
|
| 1373 | {
|
| 1374 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1375 | break;
|
| 1376 | }
|
| 1377 |
|
| 1378 | if( getExtValue( parameter_values_p, 4, &ignore_cert, 0, 1, 0) == FALSE )
|
| 1379 | {
|
| 1380 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1381 | break;
|
| 1382 | }
|
| 1383 |
|
| 1384 | LOG("[at_command_tcpip]: MBTK_AT_MCIPCFGPL_PROCESS link_num[%d].", link_id);
|
| 1385 | if(link_id != 0 && ssl_support == 1)
|
| 1386 | {
|
| 1387 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1388 | break;
|
| 1389 | }
|
| 1390 | //mbtk_tcpipip_info[link_num].hex_support = hex_support;
|
| 1391 | mbtk_tcpipip_info[link_id].ack_support = (ack_support == 1 ? true : false);
|
| 1392 | mbtk_tcpipip_info[link_id].ssl_support = (ssl_support == 1 ? true : false);
|
| 1393 | mbtk_tcpipip_info[link_id].ignore_cert = (ignore_cert == 1 ? false : true);
|
| 1394 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1395 | break;
|
| 1396 | }
|
| 1397 | default:
|
| 1398 | {
|
| 1399 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1400 | break;
|
| 1401 | }
|
| 1402 | }
|
| 1403 |
|
| 1404 | return ret;
|
| 1405 | }
|
| 1406 |
|
| 1407 | utlReturnCode_T MBTK_AT_MCIPCFG_PROCESS( const utlAtParameterOp_T op,
|
| 1408 | const char *command_name_p,
|
| 1409 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1410 | const size_t num_parameters,
|
| 1411 | const char *info_text_p,
|
| 1412 | unsigned int *xid_p,
|
| 1413 | void *arg_p)
|
| 1414 | {
|
| 1415 | UNUSEDPARAM(command_name_p);
|
| 1416 | UNUSEDPARAM(num_parameters);
|
| 1417 | UNUSEDPARAM(info_text_p);
|
| 1418 |
|
| 1419 | utlReturnCode_T ret = utlFAILED;
|
| 1420 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1421 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1422 | *xid_p = atHandle;
|
| 1423 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1424 |
|
| 1425 | LOG("[at_command_tcpip]: MBTK_AT_MCIPCFG_PROCESS enter with command_op [%s].", op2str(op));
|
| 1426 |
|
| 1427 | uint32 heartbeat_time;
|
| 1428 | uint32 delay_time;
|
| 1429 | switch(op)
|
| 1430 | {
|
| 1431 | case TEL_EXT_GET_CMD:
|
| 1432 | {
|
| 1433 | sprintf(resp_buf,"+MCIPCFG: %d,%d\r\n", mbtk_heartbeat_time, mbtk_delay_time);
|
| 1434 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1435 | break;
|
| 1436 | }
|
| 1437 | case TEL_EXT_SET_CMD:
|
| 1438 | {
|
| 1439 | if( getExtValue( parameter_values_p, 0, &heartbeat_time, TEL_AT_TIME_MIN, TEL_AT_TIME_MAX, TEL_AT_TIME_DEFAULT) == FALSE )
|
| 1440 | {
|
| 1441 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1442 | break;
|
| 1443 | }
|
| 1444 |
|
| 1445 | if( getExtValue( parameter_values_p, 1, &delay_time, TEL_AT_TIME_MIN, TEL_AT_TIME_MAX, TEL_AT_TIME_DEFAULT) == FALSE )
|
| 1446 | {
|
| 1447 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1448 | break;
|
| 1449 | }
|
| 1450 |
|
| 1451 | mbtk_heartbeat_time = heartbeat_time;
|
| 1452 | mbtk_delay_time = delay_time;
|
| 1453 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1454 | break;
|
| 1455 | }
|
| 1456 | default:
|
| 1457 | {
|
| 1458 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1459 | break;
|
| 1460 | }
|
| 1461 | }
|
| 1462 |
|
| 1463 | return ret;
|
| 1464 | }
|
| 1465 |
|
| 1466 | utlReturnCode_T MBTK_AT_USEDDATA_PROCESS( const utlAtParameterOp_T op,
|
| 1467 | const char *command_name_p,
|
| 1468 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1469 | const size_t num_parameters,
|
| 1470 | const char *info_text_p,
|
| 1471 | unsigned int *xid_p,
|
| 1472 | void *arg_p)
|
| 1473 | {
|
| 1474 | UNUSEDPARAM(command_name_p);
|
| 1475 | UNUSEDPARAM(num_parameters);
|
| 1476 | UNUSEDPARAM(info_text_p);
|
| 1477 |
|
| 1478 | utlReturnCode_T ret = utlFAILED;
|
| 1479 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1480 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1481 | *xid_p = atHandle;
|
| 1482 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1483 |
|
| 1484 | LOG("[at_command_tcpip]: MBTK_AT_USEDDATA_PROCESS enter with command_op [%s].", op2str(op));
|
| 1485 |
|
| 1486 | int i = 0;
|
| 1487 | int data_size = 0;
|
| 1488 | int data_result = 0;
|
| 1489 | switch(op)
|
| 1490 | {
|
| 1491 | case TEL_EXT_ACTION_CMD:
|
| 1492 | {
|
| 1493 | for(;i < MAX_LINK_NUM; i++)
|
| 1494 | {
|
| 1495 | data_result = MBTK_FUNC(mbtk_tcpip_data_traffic_get)(i);
|
| 1496 | if(data_result > 0)
|
| 1497 | {
|
| 1498 | data_size += data_result;
|
| 1499 | }
|
| 1500 | }
|
| 1501 |
|
| 1502 | sprintf(resp_buf, "+USEDDATA: %d", data_size);
|
| 1503 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 1504 | break;
|
| 1505 | }
|
| 1506 | default:
|
| 1507 | {
|
| 1508 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1509 | break;
|
| 1510 | }
|
| 1511 | }
|
| 1512 |
|
| 1513 | return ret;
|
| 1514 | }
|
| 1515 |
|
| 1516 | utlReturnCode_T MBTK_AT_CLEARDATA_PROCESS( const utlAtParameterOp_T op,
|
| 1517 | const char *command_name_p,
|
| 1518 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1519 | const size_t num_parameters,
|
| 1520 | const char *info_text_p,
|
| 1521 | unsigned int *xid_p,
|
| 1522 | void *arg_p)
|
| 1523 | {
|
| 1524 | UNUSEDPARAM(command_name_p);
|
| 1525 | UNUSEDPARAM(num_parameters);
|
| 1526 | UNUSEDPARAM(info_text_p);
|
| 1527 |
|
| 1528 | utlReturnCode_T ret = utlFAILED;
|
| 1529 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1530 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1531 | *xid_p = atHandle;
|
| 1532 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1533 |
|
| 1534 | LOG("[at_command_tcpip]: MBTK_AT_CLEARDATA_PROCESS enter with command_op [%s].", op2str(op));
|
| 1535 |
|
| 1536 | int i = 0;
|
| 1537 | switch(op)
|
| 1538 | {
|
| 1539 | case TEL_EXT_ACTION_CMD:
|
| 1540 | {
|
| 1541 | for(;i < MAX_LINK_NUM; i++)
|
| 1542 | {
|
| 1543 | MBTK_FUNC(mbtk_tcpip_data_traffic_reset)(i);
|
| 1544 | }
|
| 1545 |
|
| 1546 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 1547 | break;
|
| 1548 | }
|
| 1549 | default:
|
| 1550 | {
|
| 1551 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1552 | break;
|
| 1553 | }
|
| 1554 | }
|
| 1555 |
|
| 1556 | return ret;
|
| 1557 | }
|
| 1558 |
|
| 1559 | utlReturnCode_T MBTK_AT_CIPOPQUERY_PROCESS( const utlAtParameterOp_T op,
|
| 1560 | const char *command_name_p,
|
| 1561 | const utlAtParameterValue_P2c parameter_values_p,
|
| 1562 | const size_t num_parameters,
|
| 1563 | const char *info_text_p,
|
| 1564 | unsigned int *xid_p,
|
| 1565 | void *arg_p)
|
| 1566 | {
|
| 1567 | UNUSEDPARAM(command_name_p);
|
| 1568 | UNUSEDPARAM(num_parameters);
|
| 1569 | UNUSEDPARAM(info_text_p);
|
| 1570 |
|
| 1571 | utlReturnCode_T ret = utlFAILED;
|
| 1572 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
|
| 1573 | unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
|
| 1574 | *xid_p = atHandle;
|
| 1575 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
|
| 1576 |
|
| 1577 | LOG("[at_command_tcpip]: MBTK_AT_CIPOPQUERY_PROCESS enter with command_op [%s].", op2str(op));
|
| 1578 |
|
| 1579 | int i = 0;
|
| 1580 | int link_num[MAX_LINK_NUM]={-1,-1,-1,-1};
|
| 1581 | int get_num = 0;
|
| 1582 | int num = 0;
|
| 1583 | int state = 0;
|
| 1584 | switch(op)
|
| 1585 | {
|
| 1586 | case TEL_EXT_GET_CMD:
|
| 1587 | {
|
| 1588 | state = MBTK_FUNC(mbtk_tcpip_link_state_get)(0);
|
| 1589 | num = sprintf(resp_buf, "+CIPOPQUERY: %d", state);
|
| 1590 | for(i = 1; i < MAX_LINK_NUM; i++)
|
| 1591 | {
|
| 1592 | state = MBTK_FUNC(mbtk_tcpip_link_state_get)(i);
|
| 1593 | num += sprintf(resp_buf + num, ",%d", state);
|
| 1594 | }
|
| 1595 | sprintf(resp_buf + num, "\r\n");
|
| 1596 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 1597 | break;
|
| 1598 | }
|
| 1599 | case TEL_EXT_SET_CMD:
|
| 1600 | {
|
| 1601 | for(i=0; i < MAX_LINK_NUM; i++)
|
| 1602 | {
|
| 1603 | if(!parameter_values_p[i].is_default)
|
| 1604 | {
|
| 1605 | if( getExtValue( parameter_values_p, i, &link_num[i], 0, 3, 0) == FALSE )
|
| 1606 | {
|
| 1607 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1608 | return ret;
|
| 1609 | }
|
| 1610 | }else
|
| 1611 | {
|
| 1612 | break;
|
| 1613 | }
|
| 1614 | }
|
| 1615 |
|
| 1616 | get_num = i;
|
| 1617 | state = MBTK_FUNC(mbtk_tcpip_link_state_get)(link_num[0]);
|
| 1618 | num = sprintf(resp_buf, "+CIPOPQUERY: %d", state);
|
| 1619 | for(i = 1;i < get_num;i++)
|
| 1620 | {
|
| 1621 | state = MBTK_FUNC(mbtk_tcpip_link_state_get)(link_num[i]);
|
| 1622 | num += sprintf(resp_buf + num, ",%d", state);
|
| 1623 | }
|
| 1624 | sprintf(resp_buf + num, "\r\n");
|
| 1625 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
|
| 1626 | break;
|
| 1627 | }
|
| 1628 | default:
|
| 1629 | {
|
| 1630 | ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
|
| 1631 | break;
|
| 1632 | }
|
| 1633 | }
|
| 1634 |
|
| 1635 | return ret;
|
| 1636 | }
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 | #endif
|