blob: aee2bb9aff8b62dffdca639140b47f3d439b080e [file] [log] [blame]
#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 "atcmdsvr_ubus.h"
int http_handle = -1;
int http_session = -1;
int http_type = 0;
int file_fd = -1;
#define MODEM_FACTORY_TEST_TERM_DEVICE "/dev/ttyGS0"
typedef struct mbtk_http_header {
char name[30];
char *value;
} mbtk_http_header_t;
mbtk_http_header_t req_h[30] ={0};
typedef enum {
MBTK_HTTP_DATA_NON = 0,
MBTK_HTTP_DATA_HEADER,
MBTK_HTTP_DATA_CONTENT,
MBTK_HTTP_DATA_COMPLETE
} mbtk_http_data_type_enum;
typedef enum {
MBTK_HTTP_DATA_EFS_BUF = 0,
MBTK_HTTP_DATA_EFS_SIZE,
MBTK_HTTP_DATA_EFS_BUF_SIZE
} mbtk_http_data_file_type_enum;
typedef enum {
HTTP_VERSION_1_0 = 0,
HTTP_VERSION_1_1,
HTTP_VERSION_2,
HTTP_VERSION_3
} mbtk_http_version_enum;
typedef enum {
HTTP_OPTION_HEAD = 0,
HTTP_OPTION_GET,
HTTP_OPTION_POST,
HTTP_OPTION_PUT,
HTTP_OPTION_DELETE,
HTTP_OPTION_OPTIONS,
HTTP_OPTION_TRACE,
HTTP_OPTION_CONNECT,
HTTP_OPTION_LINK,
HTTP_OPTION_UNLINK
} mbtk_http_option_enum;
typedef enum {
HTTP_TYPE_URC = 0,
HTTP_TYPE_EFS
} mbtk_http_type_enum;
typedef enum {
HTTP_SESSION_STATE_NON = 0,
HTTP_SESSION_STATE_CONN,
HTTP_SESSION_STATE_WRITE_HEADER,
HTTP_SESSION_STATE_WRITE_CONTENT,
HTTP_SESSION_STATE_WRITE_END,
HTTP_SESSION_STATE_READ_HEADER,
HTTP_SESSION_STATE_READ_CONTENT,
HTTP_SESSION_STATE_READ_END
} http_session_state_e;
typedef struct {
int header_cnt;
mbtk_http_header_t *req_h[30];
int content_len; // Post content lenght
int content_len_send; // Post content lenght for send.
char *content;
} mbtk_http_session_req_t;
typedef struct {
int state_code;
mbtk_http_version_enum version;
int content_length;
bool is_chunked;
int header_cnt;
mbtk_http_header_t *rsp_h[30];
} mbtk_http_session_rsp_t;
typedef struct mbtk_http_session{
int handle_id;
int id;
int sock_fd;
int file_fd;
http_session_state_e state;
char host[50 + 1];
mbtk_http_option_enum option;
mbtk_http_type_enum type;
mbtk_http_version_enum version;
char uri[205 + 1];
int port;
bool is_ssl;
mbtk_http_session_req_t req;
mbtk_http_session_rsp_t rsp;
} mbtk_http_session_t;
#define CS8 0000060
#define B115200 0010002
#define DATABITS CS8
#define BAUD B115200
#define STOPBITS 0
#define PARITYON 0
#define PARITY 0
#define FILTER_INFO_NUM 12
#define CRTSCTS 020000000000 /* flow control */
#define VERASE 2
#define VEOF 4
#define VMIN 6
#define VEOL 11
#define IGNPAR 0000004
#define CREAD 0000200
#define CLOCAL 0004000
#define TCSANOW 0
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
/* tcflush() and TCFLSH use these */
#define TCIFLUSH 0
#define TCOFLUSH 1
#define TCIOFLUSH 2
#define NCCS 19
struct termios {
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
};
int mbtk_http_port_fd = -1;
static int mbtk_http_open_device(int *fd_ptr, const char *file_path, int flag, int tty)
{
int fd = -1;
if((fd = open(file_path, flag)) < 0)
{
LOG("Open %s fail.", file_path);
return -1;
}
LOG("Open %s success.", file_path);
if (tty) {
/* set newtio */
struct termios newtio;
memset(&newtio, 0, sizeof(newtio));
//(void)fcntl(fd, F_SETFL, 0);
#ifdef UART2_AT
/* no flow control for uart by default */
newtio.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
#else
newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
#endif
newtio.c_iflag = IGNPAR;
//newtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
newtio.c_oflag = 0;
newtio.c_lflag = 0; /* disable ECHO, ICANON, etc... */
newtio.c_cc[VERASE] = 0x8; /* del */
newtio.c_cc[VEOF] = 4; /* Ctrl-d */
newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */
newtio.c_cc[VEOL] = 0xD; /* '\0' */
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
}
*fd_ptr = fd;
return 0;
}
int mbtk_http_open_port(void)
{
if(mbtk_http_port_fd < 0)
{
return mbtk_http_open_device(&mbtk_http_port_fd, MODEM_FACTORY_TEST_TERM_DEVICE, O_RDWR | O_NONBLOCK | O_NOCTTY, 0);
}
return 0;
}
void mbtk_http_close_port(void)
{
if(mbtk_http_port_fd >= 0)
{
tcflush(mbtk_http_port_fd, TCIOFLUSH);
close(mbtk_http_port_fd);
mbtk_http_port_fd = -1;
}
}
int mbtk_http_write_data(void *data,int data_len)
{
int ret = write(mbtk_http_port_fd, data, data_len);
if(ret < 0)
{
LOG("gnss_factory_test_port_fd write fail");
return -1;
}
return 0;
}
static void http_data_cb_func(
int session_id, mbtk_http_data_type_enum type,
void *data,int data_len)
{
LOG("2type:%d,data_len:%d,data:%s ",type, data_len, data);
if(http_type)
{
if(type == MBTK_HTTP_DATA_HEADER) {
} else if(type == MBTK_HTTP_DATA_CONTENT){
if(file_fd >= 0)
{
int write_len = write(file_fd, data, data_len);
if(write_len < data_len) {
LOG("write() fail.");
// return -1;
}
}
} else {
LOG(">>>>>Complete<<<<<\n");
}
}
else
{
char buf[50]={0};
sprintf(buf, "$HTTPRECV: DATA,%d",data_len);
mbtk_http_write_data("\r\n", strlen("\r\n"));
mbtk_http_write_data(buf, strlen(buf));
mbtk_http_write_data("\r\n", strlen("\r\n"));
if(type == MBTK_HTTP_DATA_HEADER) {
mbtk_http_write_data(data, data_len);
LOG("Header(%d):%s\n",data_len,(char*)data);
} else if(type == MBTK_HTTP_DATA_CONTENT) {
mbtk_http_write_data(data, data_len);
} else {
LOG(">>>>>Complete<<<<<\n");
}
}
}
static void http_data_file_cb_func(mbtk_http_data_file_type_enum type,void *data,int data_len)
{
if(type == MBTK_HTTP_DATA_EFS_BUF) { //read file data
char buf[50]={0};
sprintf(buf, "$HTTPRECV: DATA,%d",data_len);
mbtk_http_write_data("\r\n", strlen("\r\n"));
mbtk_http_write_data(buf, strlen(buf));
mbtk_http_write_data("\r\n", strlen("\r\n"));
mbtk_http_write_data(data, data_len);
LOG("Header(%d):%s\n",data_len,(char*)data);
} else if(type == MBTK_HTTP_DATA_EFS_SIZE) { //read file size
char buf[50]={0};
sprintf(buf, "$HTTPREAD:%d",data_len);
ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, buf);
LOG("mbtk data_len(%d)\n",data_len);
} else {
LOG(">>>>>Complete<<<<<\n");
}
}
static int http_header_value_get(mbtk_http_header_t *header,char *header_str,int header_str_len)
{
if(header == NULL || header->value == NULL
|| header_str == NULL)
return 0;
int len = 0;
len = snprintf(header_str,header_str_len,"%s: %s",
header->name, header->value);
return len;
}
int mbtk_http_get_file_size(char *file_name)
{
int ret;
int fd = -1;
struct stat file_stat;
LOG("mbtk_http_get_file_size() start\n");
fd = open(file_name, O_RDONLY);
if (fd == -1) {
printf("Open file %s failed\n", file_name);
return -1;
}
ret = fstat(fd, &file_stat);
if (ret == -1) {
printf("Get file %s stat failed\n", file_name);
close(fd);
return -1;
}
close(fd);
LOG("mbtk_http_get_file_size() end\n");
return file_stat.st_size;
}
int mbtk_http_read_file_data1(mbtk_http_data_file_type_enum type,int offset)
{
if(type) //1 read file size
{
int size = mbtk_http_get_file_size("/http_test.txt");
http_data_file_cb_func(MBTK_HTTP_DATA_EFS_SIZE, NULL, size);
}else //read file data
{
char buf[1024+1] = {0};
int ret = 0;
int fd = open("/http_test.txt", O_RDONLY);
if (fd == -1) {
printf("Open file %s failed\n", "/http_test.txt");
return -1;
}
if(offset)
{
lseek(fd, offset, SEEK_SET);
}
// usleep(500000);
int index = 0;
while(1)
{
memset(buf,0, sizeof(buf));
ret = read(fd, buf, 1024);
printf("ret = %d , ", ret);
usleep(100000);
LOG("mbtk, read file:%s\n", buf);
if(ret <= 0)
break;
http_data_file_cb_func(MBTK_HTTP_DATA_EFS_BUF, buf, ret);
index++;
}
close(fd);
printf("%d\n", index);
LOG("read()end index;:%d, ret:%d",index,ret);
}
return 0;
}
utlReturnCode_T MBTK_AT_HTTPOPEN_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", command_name_p, op2str(op));
switch(op)
{
case TEL_EXT_ACTION_CMD :
{
if(http_handle >= 0)
{
LOG("http is open");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
if(mbtk_http_open_port())
{
LOG("http open device port fail\n");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
http_handle = MBTK_FUNC(mbtk_http_handle_get)(TRUE, http_data_cb_func);
if(http_handle < 0)
{
LOG("mbtk_http_handle_get() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
case TEL_EXT_GET_CMD :
{
char resp_buf[50] ={0};
if(http_handle < 0)
{
sprintf(resp_buf, "$HTTPOPEN:%d", 0);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
}else{
sprintf(resp_buf, "$HTTPOPEN:%d", 1);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
};
break;
}
default:
{
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_HTTPCLOSE_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", command_name_p, op2str(op));
switch(op)
{
case TEL_EXT_ACTION_CMD :
{
int i = 0;
if(http_handle < 0)
{
LOG("http close handle is < 0");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
mbtk_http_close_port();
for(i = 0; i < 30; i++)
{
if(req_h[i].value)
{
free(req_h[i].value);
req_h[i].value = NULL;
}
}
ret = MBTK_FUNC(mbtk_http_handle_free)(http_handle);
if(ret )
{
LOG("mbtk_http_handle_free() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
http_handle = -1;
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
case TEL_EXT_GET_CMD :
{
char resp_buf[50] ={0};
if(http_handle >= 0)
{
sprintf(resp_buf, "$HTTPCLOSE:%d", 1);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
}else{
sprintf(resp_buf, "$HTTPCLOSE:%d", 0);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
};
break;
}
default:
{
break;
}
}
return ret;
}
//$HTTPPARA="",(0-65535),(0-1), (0-1)
utlReturnCode_T MBTK_AT_HTTPPARA_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", command_name_p, op2str(op));
switch(op)
{
case TEL_EXT_SET_CMD :
{
const static int cmd_len_max = MBTK_AT_RESP_LEN_MAX;
static char cmd[MBTK_AT_RESP_LEN_MAX] ={0};
char url[255] ={0};
char resp_buf[100] = {0};
bool ingnore_cert = TRUE;
int arg3 = 0, port = 0, is_ssl = 0;
int len = 0;
if(!getExtString(parameter_values_p, 0, cmd, cmd_len_max, &len, ""))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(!getExtValue(parameter_values_p, 1, &port, 0, 65535, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(!getExtValue(parameter_values_p, 2, &is_ssl, 0, 2, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(!getExtValue(parameter_values_p, 3, &arg3, 0, 2, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(is_ssl)
{
if(!memcmp(cmd,"https://",8))
{
sprintf(url, "%s:%d", cmd, port);
}
else if(!memcmp(cmd,"http://",7))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
else
{
sprintf(url, "https://%s:%d", cmd, port);
}
}
else
{
sprintf(url, "%s:%d", cmd, port);
}
if(http_handle < 0)
{
LOG("http is not open");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
http_session = MBTK_FUNC(mbtk_http_session_create)(http_handle,1,1);
if(http_session < 0)
{
LOG("mbtk_http_handle_get() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
else
{
ret = MBTK_FUNC(mbtk_http_session_url_set)(http_handle,http_session,url);
if(ret )
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
if(arg3)
ingnore_cert = FALSE;
if(!ingnore_cert)
{
ret = MBTK_FUNC(mbtk_http_session_ingnore_cert_set)(http_handle,http_session,ingnore_cert);
if(ret)
{
LOG("mbtk_http_session_ingnore_cert_set() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
}
break;
}
case TEL_EXT_GET_CMD :
{
char resp_buf[1024] ={0};
const mbtk_http_session_t* session = MBTK_FUNC(mbtk_http_session_get)(http_handle, http_session);
if(session != NULL)
{
sprintf(resp_buf, "Host:\"%s\"\r\nURI:\"%s\"\r\nport:%d\r\nCert:%d",\
session->host,session->uri, session->port,session->is_ssl);
}
ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, resp_buf);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_TEST_CMD :
{
char resp_buf[50] ={0};
memcpy(resp_buf, "$HTTPPARA=\"\",(0-65535),(0-1), (0-1)", strlen("$HTTPPARA=\"\",(0-65535),(0-1), (0-1)"));
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
default:
{
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_HTTPSEND_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", command_name_p, op2str(op));
switch(op)
{
case TEL_EXT_ACTION_CMD :
{
printf("MBTK HTTP Version 1.1");
char resp_buf[150] ={0};
if(http_handle < 0)
{
printf("mbtk_http_handle_get() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_HTTPRQH_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
*xid_p = at_handle;
LOG("%s 11111111111111enter with command_op [%s]", command_name_p, op2str(op));
switch(op)
{
case TEL_EXT_SET_CMD :
{
const static int rqh_head_len_max = MBTK_AT_RESP_LEN_MAX;
static char rqh_head[MBTK_AT_RESP_LEN_MAX];
char rqh_buf[100] = {0};
char buf_test[100] ={0};
char *p = buf_test;
int len = 0;
memset(rqh_head, 0x0, MBTK_AT_RESP_LEN_MAX);
if(!getExtString(parameter_values_p, 0, rqh_head, rqh_head_len_max, &len, ""))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, "MBTK_AT_HTTPRQH_PROCESS1");
LOG("Get CMD Fail.");
break;
}
else{
memcpy(buf_test,rqh_head, strlen(rqh_head) );
}
len = 0;
if(!getExtString(parameter_values_p, 1, rqh_buf, rqh_head_len_max, &len, ""))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, "MBTK_AT_HTTPRQH_PROCESS1_buf");
LOG("Get CMD Fail.");
break;
}
if(http_handle < 0)
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
ret = MBTK_FUNC(mbtk_http_session_head_add)(http_handle, http_session, rqh_head, rqh_buf);
if(ret)
{
LOG("mbtk_http_handle_get() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
int i = 0;
for(i = 0; i < 30; i++)
{
if( !strcmp(req_h[i].name, rqh_head) )
{
if(req_h[i].value)
{
free(req_h[i].value);
}
req_h[i].value = (char*)malloc(strlen(rqh_buf) + 1);
if(req_h[i].value == NULL)
{
return -1;
}
memset(req_h[i].value, 0x0, strlen(rqh_buf) + 1);
memcpy(req_h[i].value, rqh_buf, strlen(rqh_buf));
}
}
for(i = 0; i < 30; i++)
{
if(req_h[i].value == NULL)
{
break;
}
}
memcpy(req_h[i].name, rqh_head, strlen(rqh_head));
req_h[i].value = (char*)malloc(strlen(rqh_buf) + 1);
if(req_h[i].value == NULL)
{
// return -1;
break;
}
memset(req_h[i].value, 0x0, strlen(rqh_buf) + 1);
memcpy(req_h[i].value, rqh_buf, strlen(rqh_buf));
}
break;
}
case TEL_EXT_GET_CMD :
{
char resp_buf[1024] ={0};
int index = 0;
int len = 0;
int i = 0;
for(i = 0; i < 30; i++)
{
if(req_h[i].value == NULL)
{
break;
}
sprintf(resp_buf, "%s:%s\n", req_h[i].name, req_h[i].value);
ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, resp_buf);
memset(resp_buf, 0, sizeof(resp_buf));
}
if(i == 0)
{
ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPRQH: \"\"");
}
else
{
ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_HTTPACTION_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
int arg1 = 0;
int type = 0;
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op));
switch(op)
{
case TEL_EXT_TEST_CMD :
{
char resp_buf[50] ={0};
memcpy(resp_buf, "$HTTPACTION: (0-3) ", strlen("$HTTPACTION: (0-3) "));
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD :
{
int gnss_ret;
if(!getExtValue(parameter_values_p, 0, &arg1, 0, 3, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(arg1 == 0){ type = 1;}
else if(arg1== 2){type = 0; }
else if(arg1== 3){type = 2; }
else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
ret = MBTK_FUNC(mbtk_http_session_option_reset)(http_handle,http_session,type);
if(ret)
{
LOG("mbtk_http_handle_get() fail.");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
if(http_type)
{
file_fd = open("/http_test.txt", O_WRONLY|O_TRUNC|O_CREAT|O_APPEND, 0666);
if(file_fd < 0)
{
LOG("mbtk_http_session_type_set fail");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
}
ret = MBTK_FUNC(mbtk_http_session_start)(http_handle, http_session);
if(ret)
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
if(file_fd >= 0)
{
if(close(file_fd))
{
LOG("close() fail file_fd:%d",file_fd);
}
file_fd = -1;
}
// mbtk_http_close_port();
}
break;
}
default:
{
break;
}
}
return ret;
}
utlReturnCode_T MBTK_AT_HTTPTYPE_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
int arg1 = 0;
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op));
switch(op)
{
case TEL_EXT_TEST_CMD :
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPTYPE: (0-1)");
break;
}
case TEL_EXT_GET_CMD :
{
char resp_buf[50] ={0};
const mbtk_http_session_t* session = MBTK_FUNC(mbtk_http_session_get)(http_handle, http_session);
if(session != NULL)
{
sprintf(resp_buf, "$HTTPTYPE:%d",session->type);
}
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD :
{
int gnss_ret;
if(!getExtValue(parameter_values_p, 0, &arg1, 0, 1, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
http_type = arg1;
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
default:
{
break;
}
}
return ret;
}
//$HTTPDATAEX: (0-500) ,""
utlReturnCode_T MBTK_AT_HTTPDATAEX_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
int arg1 = 0, arg2 = 0;
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op));
switch(op)
{
case TEL_EXT_TEST_CMD :
{
char resp_buf[50] ={0};
memcpy(resp_buf, "$HTTPDATAEX: (0-500) ,\"\"",strlen("$HTTPDATAEX: (0-500) ,\"\""));
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf);
break;
}
case TEL_EXT_SET_CMD :
{
int gnss_ret;
const static int cmd_len_max = MBTK_AT_RESP_LEN_MAX;
static char cmd[MBTK_AT_RESP_LEN_MAX];
int len = 0;
if(!getExtValue(parameter_values_p, 0, &arg1, 0, 501, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
memset(cmd, 0x0, MBTK_AT_RESP_LEN_MAX);
if(!getExtString(parameter_values_p, 1, cmd, cmd_len_max, &len, ""))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
LOG("Get CMD Fail.");
break;
}
ret = MBTK_FUNC(mbtk_http_session_option_reset)(http_handle,http_session,2);
if(ret)
{
LOG("mbtk_http_session_option_reset fail");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = MBTK_FUNC(mbtk_http_session_content_set)(http_handle,http_session,cmd,arg1);
if(ret)
{
sprintf(resp_buf, "mbtk_http_session_content_set fail,arg1:%d, len:%d, cmd:%s\r\n", arg1,len, cmd);
LOG(resp_buf);
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}
else
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
}
break;
}
default:
{
break;
}
}
return ret;
}
//$HTTPREAD: (0-1),(0-512000)
utlReturnCode_T MBTK_AT_HTTPREAD_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 at_handle = MAKE_AT_HANDLE(sAtp_index);
char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0};
int arg1 = 0, arg2 = 0;
*xid_p = at_handle;
LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op));
switch(op)
{
case TEL_EXT_TEST_CMD :
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPREAD: (0-1),(0-512000) ");
break;
}
case TEL_EXT_GET_CMD:
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
break;
}
case TEL_EXT_SET_CMD :
{
int gnss_ret;
if(!getExtValue(parameter_values_p, 0, &arg1, 0, 2, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
if(!getExtValue(parameter_values_p, 1, &arg2, 0, 512001, 0))
{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
// char buf[100] ={0};
// sprintf(buf, "arg1:%d, arg2%d\n", arg1, arg2);
// ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, buf);
if(arg1 == 0) // read data
{
if(arg2 < 1)
arg2 = 0;
}
else if(arg1 == 1){ // read file size
arg2 = 0;
}
else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
break;
}
ret = mbtk_http_read_file_data1(arg1,arg2);
if(ret)
{
LOG("mbtk_http_read_file_data fail");
ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL);
}else{
ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL);
}
break;
}
default:
{
break;
}
}
return ret;
}