blob: 5e0499c94edec5c1eb6b4b20c710a06fa7a49e1f [file] [log] [blame]
#if 1//def MBTK_TCP_SUPPORT
#include "mbtk_at.h"
//#include <sys/statfs.h>
#include <sys/vfs.h>
#include <errno.h>
#include <linux/magic.h>
#include <time.h>
#include <sys/time.h>
#include <signal.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <cutils/properties.h>
#include "configwrapper.h"
#include<linux/msg.h>
#include "mbtk_at_tcpip.h"
/*******************DEFINE**********************/
#define TEL_AT_MYNET_SOCKET_ID_MIN 0
#define TEL_AT_MYNET_SOCKET_ID_MAX 3
#define TEL_AT_MYNET_SOCKET_ID_DEFAULT 0
#define MAX_NETTYPE_LEN 4
#define MAX_IP_LEN 256
#define TEL_AT_IPV4_STR_DEFAULT NULL
#define TEL_AT_NET_PORT_MIN 0
#define TEL_AT_NET_PORT_MAX 65535
#define TEL_AT_NET_SRC_PORT_DEFAULT 0
#define MAX_DATA_LEN 512
#define TEL_AT_TCPIP_STR_DEFAULT NULL
#define TEL_AT_SEND_DATA_PARAM_MIN 0
#define TEL_AT_SEND_DATA_PARAM_MAX 2500
#define TEL_AT_SEND_DATA_PARAM_DEFAULT 0
#define TEL_AT_READ_MODE_MIN 0
#define TEL_AT_READ_MODE_MAX 4
#define TEL_AT_READ_MODE_DEFAULT 0
#define TEL_AT_READ_DATA_MIN 0
#define TEL_AT_READ_DATA_MAX 1500
#define TEL_AT_READ_DATA_DEFAULT 0
#define MAX_LINK_NUM 4
#define TEL_AT_TIME_MIN 0
#define TEL_AT_TIME_MAX 7200
#define TEL_AT_TIME_DEFAULT 0
#define MAX_AUTO_READ_LEN 2048
#define MODEM_TCPIP_PORT_DEVICE "/dev/ttyGS0"
/*******************DEFINE**********************/
/*******************ENUM**********************/
typedef enum {
MBTK_TCPIP_RESULT_SUCCESS,
MBTK_TCPIP_RESULT_FAIL,
MBTK_TCPIP_RESULT_UNKNOWN
} mbtk_tcpip_result_enum;
typedef enum {
MBTK_TCPIP_NET_STATUS_OFF,
MBTK_TCPIP_NET_STATUS_ON
} mbtk_tcpip_net_status_enum;
typedef enum {
MBTK_TCPIP_READ_AUTO,
MBTK_TCPIP_READ_MANUALLY,
MBTK_TCPIP_READ_MANUALLY_DATA,
MBTK_TCPIP_READ_MANUALLY_HEX,
MBTK_TCPIP_READ_MANUALLY_REST
}mbtk_tcpip_read_type_enum;
typedef enum {
MBTK_TCPIP_SIG_NETOPEN,
MBTK_TCPIP_SIG_NETCLOSE,
MBTK_TCPIP_SIG_CIPOPEN,
MBTK_TCPIP_SIG_CIPCLOSE,
MBTK_TCPIP_SIG_CIPSEND,
MBTK_TCPIP_SIG_CIPRXGET,
MBTK_TCPIP_SIG_MCIPCFGPL,
MBTK_TCPIP_SIG_MCIPCFG,
MBTK_TCPIP_SIG_USEDDATA,
MBTK_TCPIP_SIG_CLEARDATA,
MBTK_TCPIP_SIG_CIPOPQUERY
}mbtk_tcpip_at_type_enum;
/*******************ENUM**********************/
/*******************STRUCT**********************/
typedef struct {
int link_num;
int length;
char* lenth_data;
char ser_addr[MAX_IP_LEN + 1];
int ser_port;
char data[MAX_DATA_LEN + 1];
}mbtk_tcpip_send_info_t;
typedef struct {
int link_num;
mbtk_tcpip_read_type_enum read_mode;
char* read_len;
}mbtk_tcpip_read_info_t;
/*******************STRUCT**********************/
/*******************VARIABLE**********************/
bool link_status[MAX_LINK_NUM] = {false, false, false, false};
mbtk_task_queue_info mbtk_tcpip_task;
int mbtk_tcpip_port_fd = -1;
#ifdef MBTK_DATA_MODE_SUPPORT
unsigned int data_mode_atHandle = 0;
mbtk_tcpip_send_info_t data_mode_info = {0};
#endif
/*******************VARIABLE**********************/
/*******************STATIC VARIABLE**********************/
static int tcpip_thread_init = 0;
static uint32 mbtk_heartbeat_time = 0;
static uint32 mbtk_delay_time = 0;
static mbtk_tcpip_net_status_enum net_status = MBTK_TCPIP_NET_STATUS_OFF;
static mbtk_tcpip_read_type_enum read_type[MAX_LINK_NUM] = {0};
static mbtk_tcpip_info_t mbtk_tcpipip_info[MAX_LINK_NUM] = {0};
/*******************STATIC VARIABLE**********************/
/*******************EXTERN VARIABLE**********************/
/*******************EXTERN VARIABLE**********************/
/*********************************************FUNC************************************************************/
int mbtk_tcpip_thread_status_get(void)
{
return tcpip_thread_init;
}
void mbtk_tcpip_thread_status_set(int status)
{
tcpip_thread_init = status;
}
mbtk_tcpip_net_status_enum mbtk_tcpip_net_status_get(void)
{
return net_status;
}
void mbtk_tcpip_net_status_set(mbtk_tcpip_net_status_enum status)
{
net_status = status;
}
mbtk_tcpip_read_type_enum mbtk_tcpip_read_type_get(int link_num)
{
return read_type[link_num];
}
void mbtk_tcpip_read_type_set(int link_num, mbtk_tcpip_read_type_enum type)
{
read_type[link_num] = type;
}
static int mbtk_tcpip_open_device(int *fd_ptr, const char *file_path, int flag, int tty)
{
int fd = -1;
if((fd = open(file_path, flag)) < 0)
{
LOG("[mbtk_tcpip_open_device]: Open %s fail.", file_path);
return -1;
}
LOG("[mbtk_tcpip_open_device]: Open %s success.", file_path);
if (tty) {
/* set newtio */
}
*fd_ptr = fd;
return 0;
}
int mbtk_tcpip_open_port(void)
{
if(mbtk_tcpip_port_fd < 0)
{
return mbtk_tcpip_open_device(&mbtk_tcpip_port_fd, MODEM_TCPIP_PORT_DEVICE, O_RDWR | O_NONBLOCK | O_NOCTTY, 0);
}
return 0;
}
void mbtk_tcpip_close_port(void)
{
if(mbtk_tcpip_port_fd >= 0)
{
//tcflush(mbtk_tcpip_port_fd, TCIOFLUSH);
close(mbtk_tcpip_port_fd);
mbtk_tcpip_port_fd = -1;
}
}
int mbtk_tcpip_write_data(void *data,int data_len)
{
if(mbtk_tcpip_port_fd < 0)
{
LOG("[mbtk_tcpip_write_data]: mbtk_tcpip_port_fd not open.");
return -1;
}
int ret = write(mbtk_tcpip_port_fd, data, data_len);
if(ret < 0)
{
if(errno)
{
LOG("[mbtk_tcpip_write_data]: errno[%d].", errno);
}
LOG("[mbtk_tcpip_write_data]: mbtk_tcpip_port_fd write fail.");
return -1;
}
write(mbtk_tcpip_port_fd, "\r\n", strlen("\r\n"));
return 0;
}
void mbtk_at_tcpip_net_callback_func(int state, const char* addr)
{
//UNUSEDPARAM(state);
//UNUSEDPARAM(addr);
if(addr == NULL)
{
LOG("[mbtk_at_tcpip_net_callback_func]: state = [%d].", state);
}
else
{
LOG("[mbtk_at_tcpip_net_callback_func]: state = [%d] addr = [%s].", state, addr);
}
if(state == 0)
{
memset(link_status, 0x0,MAX_LINK_NUM);
}
mbtk_tcpip_net_status_set(state);
}
void mbtk_at_tcpip_sock_callback_func(int link_id, int state)
{
//UNUSEDPARAM(link_id);
//UNUSEDPARAM(state);
char resp_buf[64] = {0};
LOG("[mbtk_at_tcpip_sock_callback_func]: link_id = [%d] state = [%d].", link_id, state);
if(state == 0)
{
link_status[link_id] = false;
sprintf(resp_buf, "\r\n+DISCONNECT: %d\r\n", link_id);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
}
}
void mbtk_at_tcpip_read_callback_func(int link_id, const char* data, int data_len)
{
if(data == NULL || data_len == 0)
{
LOG("[mbtk_at_tcpip_read_callback_func]: data is NULL.");
return;
}
//LOG("[mbtk_at_tcpip_read_callback_func]: link_id = [%d] data_len = [%d].", link_id, data_len);
int ret = 0;
int offset = 0;
char buf[MAX_AUTO_READ_LEN + 64] = {0};
#if 0
while(data_len)
{
memset(buf, 0x0, TEL_AT_READ_DATA_MAX + 64);
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);
LOG("[mbtk_at_tcpip_read_callback_func]: ret[%d].", ret);
memcpy(buf + ret, data + offset, data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX);
offset += data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX;
data_len -= data_len <= TEL_AT_READ_DATA_MAX ? data_len : TEL_AT_READ_DATA_MAX;
LOG("[mbtk_at_tcpip_read_callback_func]: offset[%d] data_len[%d].", offset, data_len);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
usleep(10000);
}
#else
memset(buf, 0x0, MAX_AUTO_READ_LEN + 64);
ret = snprintf(buf, 63, "\r\n+CIPRXGET: SUCCESS,0,%d,%d,\r\n", link_id, data_len);
memcpy(buf + ret, data + offset, data_len);
//LOG("[mbtk_at_tcpip_read_callback_func]: buff_len[%d].", strlen(buf));
mbtk_tcpip_write_data(buf, strlen(buf));
//ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
usleep(100000);
#endif
}
void* mbtk_tcpip_task_cmd_process(void* arg)
{
UNUSEDPARAM(arg);
LOG("[mbtk_tcpip_task_cmd_process]: tcpip_task start run.");
int ret = -1;
int result_read_len = 0;
char resp_buf[64] = {0};
char buf[TEL_AT_READ_DATA_MAX + 1] = {0};
mbtk_tcpip_tcp_state_info_s t_s_info;
mbtk_signal_info* msg = NULL;
mbtk_tcpip_info_t * tcpip_info = NULL;
mbtk_tcpip_open_port();
while(1)
{
msg = MBTK_FUNC(mbtk_signal_get)(&mbtk_tcpip_task);
if(msg == NULL)
{
LOG("[mbtk_tcpip_task_cmd_process]: get signal fail [msg] = [NULL].");
continue;
}
usleep(10000);
memset(resp_buf, 0x0, 64);
LOG("[mbtk_tcpip_task_cmd_process]: get signal [msg.sig] = [%d].", msg->sig);
switch(msg->sig)
{
case MBTK_TCPIP_SIG_NETOPEN:
{
ret = MBTK_FUNC(mbtk_tcpip_net_open)(mbtk_at_tcpip_net_callback_func, mbtk_at_tcpip_sock_callback_func);
if(ret == MBTK_TCPIP_ERR_SUCCESS)
{
mbtk_tcpip_net_status_set(MBTK_TCPIP_NET_STATUS_ON);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETOPEN: SUCCESS\r\n");
}
else
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_net_open fail [ret] = [%d].", ret);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETOPEN: FAIL\r\n");
}
break;
}
case MBTK_TCPIP_SIG_NETCLOSE:
{
ret = MBTK_FUNC(mbtk_tcpip_net_close)();
if(ret == MBTK_TCPIP_ERR_SUCCESS)
{
mbtk_tcpip_net_status_set(MBTK_TCPIP_NET_STATUS_OFF);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETCLOSE: SUCCESS\r\n");
}
else
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_net_close fail [ret] = [%d].", ret);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "+NETCLOSE: FAIL\r\n");
}
break;
}
case MBTK_TCPIP_SIG_CIPOPEN:
{
if(msg->payload == NULL)
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipopen msg->payload is NULL.");
break;
}
tcpip_info = (mbtk_tcpip_info_t *)msg->payload;
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,
tcpip_info->prot_type, tcpip_info->ser_addr, tcpip_info->ser_port, tcpip_info->local_port);
tcpip_info->ack_support = mbtk_tcpipip_info[tcpip_info->link_id].ack_support;
tcpip_info->ssl_support = mbtk_tcpipip_info[tcpip_info->link_id].ssl_support;
tcpip_info->ignore_cert = mbtk_tcpipip_info[tcpip_info->link_id].ignore_cert;
tcpip_info->heartbeat_time = mbtk_heartbeat_time;
tcpip_info->delay_time = mbtk_delay_time;
ret = MBTK_FUNC(mbtk_tcpip_sock_open)(tcpip_info);
if(ret == MBTK_TCPIP_ERR_SUCCESS)
{
snprintf(resp_buf, 63, "+CIPOPEN: SUCCESS, %d\r\n", tcpip_info->link_id);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
memcpy(&(mbtk_tcpipip_info[tcpip_info->link_id]), tcpip_info, sizeof(mbtk_tcpip_info_t));
link_status[tcpip_info->link_id] = true;
}
else
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipopen fail [ret] = [%d].", ret);
snprintf(resp_buf, 63, "+CIPOPEN: FAIL, %d\r\n", tcpip_info->link_id);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
}
break;
}
case MBTK_TCPIP_SIG_CIPCLOSE:
{
if(msg->payload == NULL)
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose msg->payload is NULL.");
break;
}
int close_link = *((int *)msg->payload);
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose close link_num [%d].", close_link);
ret = MBTK_FUNC(mbtk_tcpip_sock_close)(close_link);
if(ret == MBTK_TCPIP_ERR_SUCCESS)
{
snprintf(resp_buf, 63, "+CIPCLOSE: SUCCESS, %d\r\n", close_link);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
link_status[close_link] = false;
}
else
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipclose fail [ret] = [%d].", ret);
snprintf(resp_buf, 63, "+CIPCLOSE: FAIL, %d\r\n", close_link);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
}
break;
}
case MBTK_TCPIP_SIG_CIPSEND:
{
if(msg->payload == NULL)
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipsend msg->payload is NULL.");
break;
}
mbtk_tcpip_send_info_t* info = (mbtk_tcpip_send_info_t*)msg->payload;
if(info->length)
{
if(info->lenth_data != NULL)
{
ret = MBTK_FUNC(mbtk_tcpip_send)(info->link_num, info->lenth_data, info->length, info->ser_addr, info->ser_port);
if(info->lenth_data)
{
free(info->lenth_data);
info->lenth_data = NULL;
}
}
else
{
ret = -1;
}
}
else
{
ret = MBTK_FUNC(mbtk_tcpip_send)(info->link_num, info->data, strlen(info->data), info->ser_addr, info->ser_port);
}
if(ret > 0)
{
if(info->length)
{
snprintf(resp_buf, 63, "+CIPSEND: SUCCESS,%d,%d,%d\r\n", info->link_num, info->length, ret);
}
else
{
snprintf(resp_buf, 63, "+CIPSEND: SUCCESS,%d,%d,%d\r\n", info->link_num, strlen(info->data), ret);
}
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
}
else if(ret < 0)
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipsend fail [ret] = [%d].", ret);
snprintf(resp_buf, 63, "+CIPSEND: FAIL, %d\r\n", info->link_num);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
}
break;
}
case MBTK_TCPIP_SIG_CIPRXGET:
{
if(msg->payload == NULL)
{
LOG("[mbtk_tcpip_task_cmd_process]: mbtk_tcpip_cipreget msg->payload is NULL.");
break;
}
mbtk_tcpip_read_info_t* info = (mbtk_tcpip_read_info_t*)msg->payload;
if(info->read_mode < MBTK_TCPIP_READ_MANUALLY_DATA)
{
if(info->read_mode == MBTK_TCPIP_READ_AUTO)
{
MBTK_FUNC(mbtk_tcpip_set_read_cb)(info->link_num, mbtk_at_tcpip_read_callback_func);
}
else
{
MBTK_FUNC(mbtk_tcpip_set_read_cb)(info->link_num, NULL);
}
mbtk_tcpip_read_type_set(info->link_num, info->read_mode);
snprintf(resp_buf, 63, "+CIPRXGET: SUCCESS,%d,%d\r\n", info->read_mode, info->link_num);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
break;
}
memset(buf, 0x0, TEL_AT_READ_DATA_MAX + 1);
result_read_len = 0;
if(info->read_len > 0)
{
result_read_len = MBTK_FUNC(mbtk_tcpip_read)(info->link_num, buf, info->read_len);
if(result_read_len < 0)
{
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
break;
}
else if(result_read_len == 0)
{
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
break;
}
}
memset(&t_s_info, 0x0, sizeof(mbtk_tcpip_tcp_state_info_s));
MBTK_FUNC(mbtk_tcpip_info_get)(info->link_num, &t_s_info);
snprintf(resp_buf, 63, "+CIPRXGET: SUCCESS,1,%d,%d,%d,", info->link_num, result_read_len,t_s_info.recv_data_len);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, resp_buf);
usleep(5000);
//ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, buf);
mbtk_tcpip_write_data(buf, result_read_len);
ATRESP(IND_REQ_HANDLE, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
break;
}
#if 0
case MBTK_TCPIP_SIG_MCIPCFGPL:
{
break;
}
case MBTK_TCPIP_SIG_MCIPCFG:
{
break;
}
case MBTK_TCPIP_SIG_USEDDATA:
{
break;
}
case MBTK_TCPIP_SIG_CLEARDATA:
{
break;
}
case MBTK_TCPIP_SIG_CIPOPQUERY:
{
break;
}
#endif
default:
{
break;
}
}
if(msg != NULL)
{
if(msg->payload != NULL)
{
free(msg->payload);
msg->payload = NULL;
}
free(msg);
msg = NULL;
}
}
LOG("[mbtk_tcpip_task_cmd_process]: tcpip_task exit.");
return NULL;
}
mbtk_tcpip_result_enum mbtk_at_tcpip_init(void)
{
LOG("[mbtk_at_tcpip_init]: entry func [tcpip_thread_init] = [%d].", mbtk_tcpip_thread_status_get());
int ret = 0;
if(!mbtk_tcpip_thread_status_get())
{
memset(&mbtk_tcpip_task, 0x0, sizeof(mbtk_tcpip_task));
ret = MBTK_FUNC(mbtk_task_queue_start)(&mbtk_tcpip_task,mbtk_tcpip_task_cmd_process);
if(ret)
{
LOG("[mbtk_at_tcpip_init]: creat tcpip task_queue fail.");
return MBTK_TCPIP_RESULT_FAIL;
}
LOG("[mbtk_at_tcpip_init]: creat tcpip task_queue success.");
usleep(500000);
mbtk_tcpip_thread_status_set(1);
}
return MBTK_TCPIP_RESULT_SUCCESS;
}
mbtk_tcpip_result_enum mbtk_tcpip_sig_send(mbtk_tcpip_at_type_enum sig, void* payload)
{
int ret = 0;
mbtk_signal_info* info = NULL;
if(!mbtk_tcpip_thread_status_get())
{
ret = mbtk_at_tcpip_init();
if(ret)
{
LOG("[mbtk_tcpip_sig_send]: mbtk_at_tcpip_init fail [ret] = [%d].", ret);
return MBTK_TCPIP_RESULT_FAIL;
}
}
info = (mbtk_signal_info*)malloc(sizeof(mbtk_signal_info));
if(info == NULL)
{
LOG("[mbtk_tcpip_sig_send]: malloc fail.");
return MBTK_TCPIP_RESULT_FAIL;
}
else
{
memset(info, 0x0, sizeof(mbtk_signal_info));
info->sig = sig;
if(payload == NULL)
{
info->payload = NULL;
}
else
{
info->payload = payload;
}
}
ret = MBTK_FUNC(mbtk_signal_send)(&mbtk_tcpip_task, info);
if(ret)
{
LOG("[mbtk_tcpip_sig_send]: send tcpip sig fail [ret] = [%d].", ret);
if(info != NULL)
{
if(info->payload != NULL)
{
free(info->payload);
info->payload = NULL;
}
free(info);
info = NULL;
}
return MBTK_TCPIP_RESULT_FAIL;
}
LOG("[mbtk_tcpip_sig_send]: send tcpip sig success.");
return MBTK_TCPIP_RESULT_SUCCESS;
}
#ifdef MBTK_DATA_MODE_SUPPORT
static void tcpip_data_mode_callback_cb(const char *data, int data_len)
{
LOG("[tcpip_data_mode_callback_cb]: DATA - %d:%s.", data_len, data);
if(data_len == data_mode_info.length)
{
char *data_buff = NULL;
mbtk_tcpip_send_info_t* info = NULL;
info = (mbtk_tcpip_send_info_t*)malloc(sizeof(mbtk_tcpip_send_info_t));
if(info == NULL)
{
LOG("[tcpip_data_mode_callback_cb]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
return;
}
memset(info, 0x0, sizeof(mbtk_tcpip_send_info_t));
info->link_num = data_mode_info.link_num;
info->length = data_mode_info.length;
memcpy(info->ser_addr, data_mode_info.ser_addr, strlen(data_mode_info.ser_addr));
info->ser_port = data_mode_info.ser_port;
data_buff = (char *)malloc(data_len + 1);
if(data_buff == NULL)
{
LOG("[tcpip_data_mode_callback_cb]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
free(info);
info = NULL;
ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
return;
}
memcpy(data_buff, data, data_len);
info->lenth_data = data_buff;
if(mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPSEND, info))
{
ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
free(data_buff);
data_buff = NULL;
}
else
{
ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "OK");
}
}
else
{
ATRESP(data_mode_atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "ERROR");
}
}
#endif
/***********************************************************AT COMMAND************************************************/
utlReturnCode_T MBTK_AT_NETOPEN_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_NETOPEN_PROCESS enter with command_op [%s]", op2str(op));
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
switch(op)
{
case TEL_EXT_GET_CMD:
{
sprintf(resp_buf, "+NETOPEN: %d\r\n", mbtk_tcpip_net_status_get());
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_ACTION_CMD:
{
if(mbtk_tcpip_net_status_get())
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
break;
}
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_NETOPEN, NULL);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_NETCLOSE_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_NETCLOSE_PROCESS enter with command_op [%s]", op2str(op));
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
switch(op)
{
case TEL_EXT_GET_CMD:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_ACTION_CMD:
{
if(!mbtk_tcpip_net_status_get())
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
break;
}
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_NETCLOSE, NULL);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CIPOPEN_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS enter with command_op [%s].", op2str(op));
int socketID;
int dstPort = -1;
mbtk_sock_type port_type = MBTK_SOCK_TCP;
int type_size = 0;
int dstIPlen = 0;
int localport = -1;
int i = 0;
int offset_ret = 0;
char netType[MAX_NETTYPE_LEN] = {0};
char dstIP[MAX_IP_LEN + 1] = {0};
bool flag = false;
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
if(!mbtk_tcpip_net_status_get())
{
LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS net not open.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
return ret;
}
switch(op)
{
case TEL_EXT_GET_CMD:
{
offset_ret = sprintf(resp_buf, "+CIPOPEN: ");
for(i = 0; i < MAX_LINK_NUM; i++)
{
if(link_status[i])
{
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);
flag = true;
}
}
if(true == flag)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
case TEL_EXT_SET_CMD:
{
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(link_status[socketID] == true)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, "BUSY\r\n");
break;
}
memset(netType,0,MAX_NETTYPE_LEN);
if( getExtString( parameter_values_p, 1, netType, 3, &type_size, 0 ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS get port type type_size[%d].", type_size);
if(strncasecmp((char *)netType, "TCP", 3) == 0)
{
if(parameter_values_p[2].is_default && parameter_values_p[3].is_default)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtString( parameter_values_p, 2, dstIP, MAX_IP_LEN, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
port_type = MBTK_SOCK_TCP;
}
else if(strncasecmp((char *)netType, "UDP", 3) == 0)
{
if( getExtString( parameter_values_p, 2, dstIP, 64, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, 0 ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
port_type = MBTK_SOCK_UDP;
}
else{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 4, &localport, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
mbtk_tcpip_info_t* info = NULL;
info = ( mbtk_tcpip_info_t*)malloc(sizeof(mbtk_tcpip_info_t));
if(info == NULL)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS malloc fail.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
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);
memset(info, 0x0, sizeof(mbtk_tcpip_info_t));
info->link_id = socketID;
info->prot_type = port_type;
memcpy(info->ser_addr, dstIP, MAX_IP_LEN);
LOG("[at_command_tcpip]: MBTK_AT_CIPOPEN_PROCESS info->ser_addr[%s] dstIPlen[%d].", info->ser_addr, dstIPlen);
info->ser_port = dstPort;
info->local_port = localport;
if(mbtk_tcpip_read_type_get(socketID) == MBTK_TCPIP_READ_AUTO)
{
info->read_cb = mbtk_at_tcpip_read_callback_func;
}
else
{
info->read_cb = NULL;
}
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPOPEN, info);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CIPCLOSE_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CIPCLOSE_PROCESS enter with command_op [%s].", op2str(op));
int link_num;
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
switch(op)
{
case TEL_EXT_GET_CMD:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_SET_CMD:
{
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(link_status[link_num] == false)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
int* info = NULL;
info = (int*)malloc(sizeof(int));
if(info == NULL)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPCLOSE_PROCESS malloc fail.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
*info = link_num;
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPCLOSE, info);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CIPSEND_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS enter with command_op [%s].", op2str(op));
int link_num = 0;
int length = 0;
int dstIPlen = 0;
int dstPort = 0;
int data_len = 0;
char dstIP[MAX_IP_LEN + 1] = {0};
char data[MAX_DATA_LEN + 1] = {0};
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
switch(op)
{
case TEL_EXT_GET_CMD:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_SET_CMD:
{
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(link_status[link_num] == false)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS link_num[%d] not open.", link_num);
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtString( parameter_values_p, 2, dstIP, MAX_IP_LEN, &dstIPlen, TEL_AT_IPV4_STR_DEFAULT ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 3, &dstPort, TEL_AT_NET_PORT_MIN, TEL_AT_NET_PORT_MAX, TEL_AT_NET_SRC_PORT_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(length > 0)
{
#ifdef MBTK_DATA_MODE_SUPPORT
if(!parameter_values_p[4].is_default)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS param error.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
data_mode_info.link_num = link_num;
data_mode_info.length = length;
memcpy(data_mode_info.ser_addr, dstIP, dstIPlen);
data_mode_info.ser_port = dstPort;
data_mode_atHandle = atHandle;
ret = mbtk_data_mode_enter(sAtp_index, tcpip_data_mode_callback_cb);
break;
#else
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
#endif
}
else
{
if(parameter_values_p[4].is_default)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS data is NULL.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtString( parameter_values_p, 4, data, MAX_DATA_LEN, &data_len, TEL_AT_TCPIP_STR_DEFAULT ) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
mbtk_tcpip_send_info_t* info = NULL;
info = (mbtk_tcpip_send_info_t*)malloc(sizeof(mbtk_tcpip_send_info_t));
if(info == NULL)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS malloc fail.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
LOG("[at_command_tcpip]: MBTK_AT_CIPSEND_PROCESS dstIPlen[%d] data_len[%d].", dstIPlen, data_len);
memset(info, 0x0, sizeof(mbtk_tcpip_send_info_t));
info->link_num = link_num;
info->length = length;
memcpy(info->ser_addr, dstIP, dstIPlen);
info->ser_port = dstPort;
memcpy(info->data, data, data_len);
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPSEND, info);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CIPRXGET_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CIPRXGET_PROCESS enter with command_op [%s].", op2str(op));
mbtk_tcpip_read_type_enum read_mode = MBTK_TCPIP_READ_AUTO;
int link_num = 0;
int read_len = 0;
mbtk_tcpip_result_enum tcpip_ret = MBTK_TCPIP_RESULT_SUCCESS;
switch(op)
{
case TEL_EXT_GET_CMD:
{
sprintf(resp_buf, "+CIPRXGET: %d,%d,%d,%d", read_type[0], read_type[1], read_type[2], read_type[3]);
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD:
{
if( getExtValue( parameter_values_p, 0, &read_mode, TEL_AT_READ_MODE_MIN, TEL_AT_READ_MODE_MAX, TEL_AT_READ_MODE_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(read_mode < MBTK_TCPIP_READ_MANUALLY_DATA && !parameter_values_p[2].is_default)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS param error.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(read_mode >= MBTK_TCPIP_READ_MANUALLY_DATA)
{
if(link_status[link_num] && !parameter_values_p[2].is_default)
{
if( getExtValue( parameter_values_p, 2, &read_len, TEL_AT_READ_DATA_MIN, TEL_AT_READ_DATA_MAX, TEL_AT_READ_DATA_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
else
{
LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS link not open or param is error.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
mbtk_tcpip_read_info_t* info = NULL;
info = (mbtk_tcpip_read_info_t*)malloc(sizeof(mbtk_tcpip_read_info_t));
if(info == NULL)
{
LOG("[at_command_tcpip]: MBTK_AT_CIPREGET_PROCESS malloc fail.");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
memset(info, 0x0, sizeof(mbtk_tcpip_read_info_t));
info->link_num = link_num;
info->read_mode = read_mode;
info->read_len = read_len;
tcpip_ret = mbtk_tcpip_sig_send(MBTK_TCPIP_SIG_CIPRXGET, info);
if(tcpip_ret)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_SUPPRESS, 0, NULL);
}
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_MCIPCFGPL_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_MCIPCFGPL_PROCESS enter with command_op [%s].", op2str(op));
int link_id = 0;
int hex_support;
int ack_support;
int ssl_support;
int ignore_cert;
int num_ret = 0;
int i = 0;
switch(op)
{
case TEL_EXT_GET_CMD:
{
num_ret = sprintf(resp_buf,"+MCIPCFGPL: ");
for(; i < MAX_LINK_NUM; i++)
{
num_ret += sprintf(resp_buf + num_ret,"%d,%d,%d,%d\r\n", 0,
mbtk_tcpipip_info[i].ack_support, mbtk_tcpipip_info[i].ssl_support, mbtk_tcpipip_info[i].ignore_cert);
}
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD:
{
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 )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 1, &hex_support, 0, 1, 0) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 2, &ack_support, 0, 1, 0) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 3, &ssl_support, 0, 1, 0) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 4, &ignore_cert, 0, 1, 0) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
LOG("[at_command_tcpip]: MBTK_AT_MCIPCFGPL_PROCESS link_num[%d].", link_id);
if(link_id != 0 && ssl_support == 1)
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
//mbtk_tcpipip_info[link_num].hex_support = hex_support;
mbtk_tcpipip_info[link_id].ack_support = (ack_support == 1 ? true : false);
mbtk_tcpipip_info[link_id].ssl_support = (ssl_support == 1 ? true : false);
mbtk_tcpipip_info[link_id].ignore_cert = (ignore_cert == 1 ? false : true);
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_MCIPCFG_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_MCIPCFG_PROCESS enter with command_op [%s].", op2str(op));
uint32 heartbeat_time;
uint32 delay_time;
switch(op)
{
case TEL_EXT_GET_CMD:
{
sprintf(resp_buf,"+MCIPCFG: %d,%d\r\n", mbtk_heartbeat_time, mbtk_delay_time);
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_SET_CMD:
{
if( getExtValue( parameter_values_p, 0, &heartbeat_time, TEL_AT_TIME_MIN, TEL_AT_TIME_MAX, TEL_AT_TIME_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if( getExtValue( parameter_values_p, 1, &delay_time, TEL_AT_TIME_MIN, TEL_AT_TIME_MAX, TEL_AT_TIME_DEFAULT) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
mbtk_heartbeat_time = heartbeat_time;
mbtk_delay_time = delay_time;
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_USEDDATA_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_USEDDATA_PROCESS enter with command_op [%s].", op2str(op));
int i = 0;
int data_size = 0;
int data_result = 0;
switch(op)
{
case TEL_EXT_ACTION_CMD:
{
for(;i < MAX_LINK_NUM; i++)
{
data_result = MBTK_FUNC(mbtk_tcpip_data_traffic_get)(i);
if(data_result > 0)
{
data_size += data_result;
}
}
sprintf(resp_buf, "+USEDDATA: %d", data_size);
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CLEARDATA_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CLEARDATA_PROCESS enter with command_op [%s].", op2str(op));
int i = 0;
switch(op)
{
case TEL_EXT_ACTION_CMD:
{
for(;i < MAX_LINK_NUM; i++)
{
MBTK_FUNC(mbtk_tcpip_data_traffic_reset)(i);
}
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_CIPOPQUERY_PROCESS( const utlAtParameterOp_T op,
const char *command_name_p,
const utlAtParameterValue_P2c parameter_values_p,
const size_t num_parameters,
const char *info_text_p,
unsigned int *xid_p,
void *arg_p)
{
UNUSEDPARAM(command_name_p);
UNUSEDPARAM(num_parameters);
UNUSEDPARAM(info_text_p);
utlReturnCode_T ret = utlFAILED;
TelAtParserID sAtp_index = *(TelAtParserID *)arg_p;
unsigned int atHandle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = atHandle;
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
LOG("[at_command_tcpip]: MBTK_AT_CIPOPQUERY_PROCESS enter with command_op [%s].", op2str(op));
int i = 0;
int link_num[MAX_LINK_NUM]={-1,-1,-1,-1};
int get_num = 0;
int num = 0;
int state = 0;
switch(op)
{
case TEL_EXT_GET_CMD:
{
state = MBTK_FUNC(mbtk_tcpip_link_state_get)(0);
num = sprintf(resp_buf, "+CIPOPQUERY: %d", state);
for(i = 1; i < MAX_LINK_NUM; i++)
{
state = MBTK_FUNC(mbtk_tcpip_link_state_get)(i);
num += sprintf(resp_buf + num, ",%d", state);
}
sprintf(resp_buf + num, "\r\n");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD:
{
for(i=0; i < MAX_LINK_NUM; i++)
{
if(!parameter_values_p[i].is_default)
{
if( getExtValue( parameter_values_p, i, &link_num[i], 0, 3, 0) == FALSE )
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
return ret;
}
}else
{
break;
}
}
get_num = i;
state = MBTK_FUNC(mbtk_tcpip_link_state_get)(link_num[0]);
num = sprintf(resp_buf, "+CIPOPQUERY: %d", state);
for(i = 1;i < get_num;i++)
{
state = MBTK_FUNC(mbtk_tcpip_link_state_get)(link_num[i]);
num += sprintf(resp_buf + num, ",%d", state);
}
sprintf(resp_buf + num, "\r\n");
ret = ATRESP(atHandle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
default:
{
ret = ATRESP(atHandle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
return ret;
}
#endif