Exemplo n.º 1
0
u8 *getHead()
{

    // check over
    if(textBuf.uOverFlag > 0 && textBuf.lostTextAdr == textBuf.head)
    {
        Ql_strcpy((char *)textBuf.temp_out_buff, "[@OVF] ");
        Ql_UART_Write(_DEBUG_UART_PORT, textBuf.temp_out_buff, _PREFIX_LEN);

        _RESET_DBG_BUFFER

        return NULL;
    }
Exemplo n.º 2
0
bool createDirRecursively(char *dirName)
{
    OUT_DEBUG_2("createDirRecursively(\"%s\")\r\n", dirName);

    if (!Ql_strlen(dirName)) {
        OUT_DEBUG_1("Directory name is empty\r\n");
        return FALSE;
    }

    // -- create dirs hierarchy
    char parted_dir_name[255] = {0};
    Ql_strcpy(parted_dir_name, dirName);

    s16 nPathParts = 0;
    char *temp_str = parted_dir_name;
    const char path_separator = '\\';

    do {
        temp_str = Ql_strchr(temp_str, path_separator);
        if (temp_str) *temp_str++ = 0;
        ++nPathParts;
    } while (temp_str);

    while (nPathParts) {
        if (nPathParts-- > 1) {  // if not last iteration
            s32 ret = Ql_FS_CheckDir(parted_dir_name);
            if (ret < QL_RET_OK && QL_RET_ERR_FILENOTFOUND != ret) // if an error occured
            {
                OUT_DEBUG_1("Error %d occured while checking directory \"%s\".\r\n",
                            ret, parted_dir_name);
                return FALSE;
            }
            else if (QL_RET_OK == ret) // if the dir was found
            {
                OUT_DEBUG_3("Directory \"%s\" already exists. Creation skipped\r\n", parted_dir_name);
                char *end = Ql_strchr(parted_dir_name, 0);  // find the end of the dir name's part
                *end = path_separator;
                continue;
            }
        }

        // -- create dest dir
        if (!createDir(parted_dir_name))
            return FALSE;

        char *end = Ql_strchr(parted_dir_name, 0);  // find the end of the dir name's part
        *end = path_separator;
    }

    return TRUE;
}
Exemplo n.º 3
0
void CallBack_socket_read(u8 contexid, s8 sock, bool result, s32 error){
    u8 len=0;
    s32 index=0;
    s32 ret=0;
    //OUTLOG("resive from socket:%d",sock);
    //Ql_memset(__socketBuffer,0,LEN_SOCKET_BUFFER);
    //len=Ql_SocketRecv(sock,(u8*)&__socketBuffer[0],LEN_SOCKET_BUFFER);
	//if (len>0) {
		if (sock==__est_connector_socket) {
            Ql_memset(__socketBuffer,0,LEN_SOCKET_BUFFER);
            len=Ql_SocketRecv(sock,(u8*)&__socketBuffer[0],LEN_SOCKET_BUFFER);
            if (len>0) {
                unreplace(&__socketBuffer[0],len);
                if (!__waitConfirm){
                    nSTATE = STATE_SOCKET_SEND; 
                    __toSend=0;
                  Ql_StopGPTimer();
                }
                 __countRepeat=0;
                 __start_empty_tmr=Ql_GetRelativeTime();
            }
         }
        else{
           // __socketBuffer[len] = '\0'; 
           //read_request((char*)__socketBuffer, sock); 
            index=findClientBySockid(sock);

            ret=__client[index].read_handle_callback(contexid,sock,result,error,index);
            //OUTD("size recive:%d",ret);
            if (ret>0) {
                  if (__client[index].protocol==HTTP) {
                    if (parse_header((char*)__client[index].recvBuffer,(u32)__client[index].pRecvCurrentPos)) {
                        //OUTD("header:%s",__client[index].recvBuffer);
                        if (__header.method==GET) {
                           if (!__header.authorization) {
                                    Ql_strcpy(__header.action,"autorize");
                           }
                           page_response(); 
                            __client[index].send_handle(sock,__s_buf);
                        }
                        else if (__header.method==POST) {
                                OUTD("len:%d",__header.length);
                          }
                      }
                   }
                   else if (__client[index].protocol==STREAM) {
                       OUTD("stream",NULL);
                        Ql_SendToUart(ql_uart_port3,__client[index].recvBuffer,ret);
                    }
                   else if ( __client[index].protocol==UPGRADE) {
                        s32 init=0;
                        int pp=(u16)(__client[index].pRecvCurrentPos);
                        if (Ql_strstr((char*)&__client[index].recvBuffer[pp-3],"END")) {
                            OUTD("end file is:%s",&__client[index].recvBuffer[pp]);
                            init = Ql_Fota_App_Write_Data(ret-3, (s8 *)__client[index].recvBuffer);
                            OUTD("write fota:%d", init); 
                            init=Ql_Fota_App_Finish();
                            __client[index].send_handle(sock,init==0 ? "0":"1");
                            OUTD("finish write:%d", init); 
                            if (init==0) {
                                init=Ql_Fota_Update();
                            }
                        }
                        else{
                            init = Ql_Fota_App_Write_Data(ret, (s8 *)__client[index].recvBuffer);
                            __client[index].send_handle(sock,init==0 ? "0":"1");
                            OUTD("fota write:%d", init); 
                        }
                }
            }
        }
}
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara)
{
    //APP_DEBUG("CallBack_UART_Hdlr: port=%d, event=%d, level=%d, p=%x\r\n", port, msg, level, customizedPara);
    u32 rdLen=0;
    s32 ret;
    char *pData= NULL;
    char *p=NULL;
    char *p1=NULL;
    char *p2=NULL;
    bool    bRet = FALSE;
    
    switch (msg)
    {
        case EVENT_UART_READY_TO_READ:
        {
            if(UART_PORT1 == port)
            {  
                do
                {                   
                    Ql_memset(m_RxBuf_mcuUart, 0x0, sizeof(m_RxBuf_mcuUart));
                    rdLen = Ql_UART_Read(port, m_RxBuf_mcuUart, sizeof(m_RxBuf_mcuUart));
                    pData = m_RxBuf_mcuUart;
                    /*set last tail data eq 0*/
                    pData[rdLen + 1] = '\0';                    
                   
                    /*cmd: DEPO*/
                    p = Ql_strstr(pData,"DEPO");                    
                    if (p)
                    {
                        APP_DEBUG(textBuf,"\r\nDEPO \r\n");
                        bRet = SendMtkBinCmd("$PMTK253,1,0*37");
                        if(!bRet)
                        {
                            APP_DEBUG(textBuf,"\r\n Send $PMTK Error \r\n");
                            break;
                        }
                        else
                        {
                            bRet = VerifyFileAndSendFirstEpoPacket(s_s8FilePath);
                             if(!bRet)
                            {
                                APP_DEBUG(textBuf,"\r\n VerifyFile Error \r\n");                                
                                break;
                            }
                             else
                             {
                                APP_DEBUG(textBuf,"Update EPO Progress Start £º\r\n");
                             }
                        }
                        break;
                    }

                    
                    /*cmd:  QueryAvailableStorage=UFS*/
                    p = Ql_strstr(pData,"QueryAvailableStorage");
                    if (p)
                    {
                        if(Ql_strstr(pData,"=UFS"))
                        {
                            s64 size;
                            size = Ql_FS_GetFreeSpace(1);        // UFS
                            APP_DEBUG(textBuf,"QueryAvailableStorage=%lld\r\n",size);   
                                    
                        }else if(Ql_strstr(pData,"=SD"))
                        {
                            s64 size;
                            size = Ql_FS_GetFreeSpace(2);  //SD
                            APP_DEBUG(textBuf,"QueryAvailableStorage=%lld\r\n",size); 
                        }else if(Ql_strstr(pData,"=RAM"))
                        {
                            s64 size;
                            size = Ql_FS_GetFreeSpace(3);  //RAM
                            APP_DEBUG(textBuf,"QueryAvailableStorage=%lld\r\n",size); 
                        }else
                        {
                            APP_DEBUG(textBuf,"QueryAvailableStorage param error!\r\n"); 
                        }
                        break;
                    }
                    
                    /*cmd: WriteFile=password.txt*/
                    p = Ql_strstr(pData,"WriteFile=");
                    if (p)
                    {
                        s32 s32Res = -1;
                        u32 uiFlag = 0;
                        u32 i=0;
                        char stmpdir[100],dir[100];
                        char *p1[100];
                        //u32 filesize = 10240;
                        u32 filesize = 276480;

                        p = Ql_strstr(pData, "=");
                        (*p) = '\0';
                        p++;

                        Ql_memset(s_s8FilePath, 0, sizeof(s_s8FilePath));  //File Name
                        Ql_strcpy((char *)s_s8FilePath, p);

                        uiFlag |= QL_FS_READ_WRITE;
                        uiFlag |= QL_FS_CREATE;

                        flag = 1;                     

                        if(Ql_strncmp((char*)s_s8FilePath,"RAM:",4))
                        {
                            ret = Ql_FS_Open((u8*)s_s8FilePath, uiFlag);
                            
                        }
                        else
                        {
                           ret = Ql_FS_OpenRAMFile((u8*)s_s8FilePath, uiFlag,filesize); 
                        }
                        if(ret >= QL_RET_OK)
                        {
                            filehandle = ret;
                        }

                        APP_DEBUG(textBuf,"filehandle=%d\r\n",filehandle);

                        break;
                    }


                    //Receiving data and StopWrite
                    if (flag)
                    {

                        u32 writeedlen;
                        p = Ql_strstr(pData,"StopWrite");
                        if (p)
                        {
                            Ql_FS_Close(filehandle);
                            filehandle = -1;
                            flag =0;
                            APP_DEBUG(textBuf,"Ql_WriteFinish()\r\n");

                            break;
                        }
                        ret = Ql_FS_Write(filehandle, (u8*)pData, rdLen, &writeedlen);
                        if(ret== QL_RET_OK)
                        {
                            //APP_DEBUG(textBuf,"Ql_File()=%d: writeedlen=%d,Download times=%d\r\n",ret, writeedlen,flag++);

                        }else if(ret == QL_RET_ERR_FILEDISKFULL)
                        {
                            Ql_FS_Close(filehandle);
                            filehandle = -1;
                            flag =0;
                            APP_DEBUG(textBuf,"Storage Full,close file! ret=%d\r\n",ret);
                            break;
                        }else
                        {
                            Ql_FS_Close(filehandle);
                            filehandle = -1;
                            flag =0;
                            APP_DEBUG(textBuf,"write error,close file!ret=%d \r\n",ret);
                            break;
                        }
                    }                                
                   

                    /*cmd: AT Command*/

                    if (Ql_strstr(pData,"AT")||Ql_strstr(pData,"at") || Ql_strstr(pData,"At") || Ql_strstr(pData,"aT"))
                    {
                        //APP_DEBUG(textBuf,"%s", pData);
                        Ql_UART_Write(VIRTUAL_PORT1,(u8*)pData,rdLen);
                        
                        break;
                    }
                    
                }while(rdLen > 0);

            }
            else if(UART_PORT3 == port)
            {
                s32 totalBytes = ReadSerialPort(port, m_RxBuf_gnssUART, sizeof(m_RxBuf_gnssUART));                
                if (totalBytes <= 0)
                {
                    APP_DEBUG("<-- No data in gnssUART buffer! -->\r\n");
                    return;
                }
                
                 ReadAckAndSendEpoPacket(m_RxBuf_gnssUART,totalBytes);

            }   
           else if((VIRTUAL_PORT1 == port) || (VIRTUAL_PORT2 == port))
            {
                s32 ret,totalBytes;

                totalBytes = ReadSerialPort(port, m_RxBuf_VirtualPort, sizeof(m_RxBuf_VirtualPort));
                if (totalBytes <= 0)
                {
                    APP_DEBUG("<-- No data in virtural UART buffer! -->\r\n");
                    return;
                }
                Ql_UART_Write(UART_PORT1,(u8*)m_RxBuf_VirtualPort,totalBytes);

            }
            
            break;
        }
        default:
            break;
    }
}
Exemplo n.º 5
0
void setCommand(char* command){
    char* cmd = NULL;
    char idx=0;
    char* pch=NULL;
	cmd = Ql_strstr(command, "DEBUG=");
	if (cmd){
		cmd += 6;
		if (Ql_strstr(cmd, "TRUE")){
            __debug=TRUE;
        }
        else{
            __debug=FALSE;
        }
        Ql_strcpy(&__settings.Debug[0],cmd);
	}
    cmd = Ql_strstr(command, "LOG=");
	if (cmd){
		cmd += 4;
		if (Ql_strstr(cmd, "TRUE")){
            __log=TRUE;
        }
        else{
            __log=FALSE;
        }
        Ql_strcpy(&__settings.Log[0],cmd);
	}
	cmd = Ql_strstr(command, "TCP=");
	if (cmd){
		cmd += 4;
        __settings.TCP=Ql_atoi(cmd);
	}
	cmd = Ql_strstr(command, "IP=");
	if (cmd){
		cmd += 3;
       
        pch = strtok(cmd, ".");
		while (pch != NULL)
		{
			__settings.IP[idx] = Ql_atoi(pch);   
			pch = strtok(NULL, ".");
			idx++;
		}
        //OUTD("Set IP:%d.%d.%d.%d\r\n",__settings.IP[0],__settings.IP[1],__settings.IP[2],__settings.IP[3]);
		
	}
	cmd = Ql_strstr(command, "APN=");
	if (cmd){
		cmd += 4;
		Ql_strcpy(&__settings.APN[0],cmd);
        
	}
	cmd = Ql_strstr(command, "PASS="******"NUM=");
	if (cmd){
		cmd += 4;
		__settings.Num=Ql_atoi(cmd);
	}
    /*cmd = Ql_strstr(command, "PWD=");
	if (cmd){
		cmd += 4;
		Ql_strcpy(&__settings.Pwd[0],cmd);
        
	}*/
     cmd = Ql_strstr(command, "USER="******"TIME=");
	if (cmd){
        char* last;
        QlSysTimer tm;
        Ql_GetLocalTime(&tm);
        cmd+=5;
        if (Ql_strlen(cmd)==8) {
        tm.hour = Ql_atoi(strtok_r(cmd, ":",&last));
		tm.minute = Ql_atoi(strtok_r(last, ":",&last));
        tm.second = Ql_atoi(strtok_r(last, ":",&last));
        Ql_SetLocalTime(&tm);
     }
	}
    cmd = Ql_strstr(command, "DATE=");
	if (cmd){
		char* last;
        QlSysTimer tm;
        Ql_GetLocalTime(&tm);
        cmd+=5;
        if (Ql_strlen(cmd)==8) {
        tm.day = Ql_atoi(strtok_r(cmd, ".",&last));
		tm.month = Ql_atoi(strtok_r(last, ".",&last));
        tm.year = Ql_atoi(strtok_r(last, ".",&last));
        Ql_SetLocalTime(&tm);
        }
	}
    cmd = Ql_strstr(command, "REBOOT");
	if (cmd){
        OUTD("!-----Get command to reboot..-----",NULL);
        Ql_Sleep(100);
		Ql_Reset(0);
	}

     cmd = Ql_strstr(command, "TSEND=");
	if (cmd){
        s32 tsend;
        cmd+=6;
        tsend=Ql_atoi(cmd);
        if (tsend>10 && tsend<60) {
            __settings.TSend = tsend;
        }
        
    }

    cmd = Ql_strstr(command, "DEBOUNCE=");
	if (cmd){
        s32 deboung;
        cmd+=9;
        deboung=Ql_atoi(cmd);
        //OUTD("set debounce ok:%d",deboung);
        if (deboung>=100 && deboung<=1000) {
            //OUTD("set debounce ok:%d",deboung);
            __settings.Deboung = deboung;
        }
        
    }
    cmd = Ql_strstr(command, "WUser="******"WPass="******"?");
	if (cmd){
        PrintSettings();
	}
}
Exemplo n.º 6
0
s32 rx_handler_saveTableSegment(PultMessageRx *pMsg)
{
    OUT_DEBUG_2("rx_handler_saveTableSegment\r\n");
    OUT_DEBUG_2("pMsg->part_len = %d\r\n", pMsg->part_len);
    if(4 == pMsg->part_len){
        return RETURN_NO_ERRORS;
    }


    RxConfiguratorPkt pkt;

    pkt.dataType=pMsg->complex_msg_part[0];
    pkt.data=&pMsg->complex_msg_part[4];


    pkt.datalen= pMsg->part_len-4;

    pkt.marker=CONFIGURATION_AUTOSYNC_PACKET_MARKER;
    pkt.pktIdx=0;
    pkt.repeatCounter=0;
    pkt.sessionKey=0;
    pkt.bAppend=TRUE;


    char name[30] = {0};

    switch (pkt.dataType) {
    case OBJ_PHONELIST_SIM1:
        Ql_strcpy(name, FILENAME_PATTERN_PHONELIST_SIM1);
        break;
    case OBJ_PHONELIST_SIM2:
        Ql_strcpy(name, FILENAME_PATTERN_PHONELIST_SIM2);
        break;
    case OBJ_IPLIST_SIM1:
        Ql_strcpy(name, FILENAME_PATTERN_IPLIST_SIM1);
        break;
    case OBJ_IPLIST_SIM2:
        Ql_strcpy(name, FILENAME_PATTERN_IPLIST_SIM2);
        break;
    default:
        break;
    }

    //===================================
    // PREPARE Empty file
    if(0 == pMsg->complex_msg_part[1])
    {
        s32 ret = prepareEmptyDbFileInAutosyncTemporaryDB(name);
        if(ret < RETURN_NO_ERRORS)
        {
            OUT_DEBUG_1("prepareEmptyDbFileInAutosyncTemporaryDB() = %d error. File not create.\r\n", ret);
            return ret;
        }
    }

    //===================================
    // SAVE to AutosyncTemporaryDB
    s32 ret = saveSettingsToAutosyncTemporaryDB(&pkt);
    if(ret < RETURN_NO_ERRORS)
    {
        OUT_DEBUG_1("saveSettingsToAutosyncTemporaryDB() = %d error\r\n", ret);
        return ret;
    }


    //===================================
    // MOVE to work file
    if(pMsg->complex_msg_part[1] == pMsg->complex_msg_part[2])
    {
        if(!copyFilleFromAutosyncTemporaryDBToWorkDB(name))
        {
            OUT_DEBUG_1("copyFilleFromAutosyncTemporaryDBToWorkDB() = %d error. File not move.\r\n");
            return ERR_DB_SAVING_FAILED;
        }

        // ACTUALIZATION
        ret = actualizationSIMCardLists(pkt.dataType);
        if(ret < RETURN_NO_ERRORS)
        {
            OUT_DEBUG_1("actualizationSIMCardLists() = %d error. Actualize error.\r\n", ret);
            return ret;
        }

        SystemInfo *pSysInfo = getSystemInfo(NULL);
        pSysInfo->settings_signature_autosync = pMsg->complex_msg_part[3];

        // save to DB signature autosync
        ret = saveToDbFile(DBFILE(FILENAME_PATTERN_SYSTEMINFO), pSysInfo, sizeof(SystemInfo), FALSE);
        if(ret < RETURN_NO_ERRORS)
        {
            OUT_DEBUG_1("saveToDbFile() = %d error. Save signature autosynce error.\r\n", ret);
            return ret;
        }
        OUT_DEBUG_7("SystemInfo settings_signature_autosync = %d.\r\n", pSysInfo->settings_signature_autosync);
    }

    return RETURN_NO_ERRORS;
}
Exemplo n.º 7
0
static void Callback_Timer(u32 timerId, void* param)
{
    if (TIMEOUT_90S_TIMER_ID == timerId)
    {
        APP_DEBUG("<--90s time out!!!-->\r\n");
        APP_DEBUG("<-- Close socket.-->\r\n");
        
        Ql_SOC_Close(m_socketid);
        m_socketid = -1;

        m_tcp_state = STATE_GPRS_DEACTIVATE;

        timeout_90S_monitor = FALSE;
    }
    else if (TCP_TIMER_ID == timerId)
    {
        //APP_DEBUG("<--...........m_tcp_state=%d..................-->\r\n",m_tcp_state);
        switch (m_tcp_state)
        {
            case STATE_NW_GET_SIMSTATE:
            {
                s32 simStat = 0;
                //if (Ql_NW_GetSIMCardState()== Ql_SIM_NORMAL)
                RIL_NW_GetSIMCardState(&simStat);
                if (simStat == SIM_STAT_READY)
                {
                    m_tcp_state = STATE_NW_QUERY_STATE;
                    APP_DEBUG("<--SIM card status is normal!-->\r\n");
                }else
                {
                //    Ql_Timer_Stop(TCP_TIMER_ID);
                    APP_DEBUG("<--SIM card status is unnormal!-->\r\n");
                }
                break;
            }        
            case STATE_NW_QUERY_STATE:
            {
                s32 creg = 0;
                s32 cgreg = 0;
                //Ql_NW_GetNetworkState(&creg, &cgreg);
                ret = RIL_NW_GetGSMState(&creg);
                ret = RIL_NW_GetGPRSState(&cgreg);
                APP_DEBUG("<--Network State:creg=%d,cgreg=%d-->\r\n",creg,cgreg);
                if((cgreg == NW_STAT_REGISTERED)||(cgreg == NW_STAT_REGISTERED_ROAMING))
                {
                    m_tcp_state = STATE_GPRS_REGISTER;
                }
                break;
            }
            case STATE_GPRS_REGISTER:
            {
                ret = Ql_GPRS_Register(0, &callback_gprs_func, NULL);
                if (GPRS_PDP_SUCCESS == ret)
                {
                    APP_DEBUG("<--Register GPRS callback function successfully.-->\r\n");
                    m_tcp_state = STATE_GPRS_CONFIG;
                }else if (GPRS_PDP_ALREADY == ret)
                {
                    APP_DEBUG("<--GPRS callback function has already been registered,ret=%d.-->\r\n",ret);
                    m_tcp_state = STATE_GPRS_CONFIG;
                }else
                {
                    APP_DEBUG("<--Register GPRS callback function failure,ret=%d.-->\r\n",ret);
                }
                break;
            }
            case STATE_GPRS_CONFIG:
            {
                Ql_strcpy(m_gprsCfg.apnName, m_apn);
                Ql_strcpy(m_gprsCfg.apnUserId, m_userid);
                Ql_strcpy(m_gprsCfg.apnPasswd, m_passwd);
                m_gprsCfg.authtype = 0;
                ret = Ql_GPRS_Config(0, &m_gprsCfg);
                if (GPRS_PDP_SUCCESS == ret)
                {
                    APP_DEBUG("<--configure GPRS param successfully.-->\r\n");
                }else
                {
                    APP_DEBUG("<--configure GPRS param failure,ret=%d.-->\r\n",ret);
                }
                
                m_tcp_state = STATE_GPRS_ACTIVATE;
                break;
            }
            case STATE_GPRS_ACTIVATE:
            {
                m_tcp_state = STATE_GPRS_ACTIVATING;
                ret = Ql_GPRS_Activate(0);
                if (ret == GPRS_PDP_SUCCESS)
                {
                    APP_DEBUG("<--Activate GPRS successfully.-->\r\n");
                    m_tcp_state = STATE_GPRS_GET_DNSADDRESS;
                }else if (ret == GPRS_PDP_WOULDBLOCK)
                {
                     APP_DEBUG("<--Waiting for the result of GPRS activated.,ret=%d.-->\r\n",ret);
                    //waiting Callback_GPRS_Actived
                }else if (ret == GPRS_PDP_ALREADY)
                {
                    APP_DEBUG("<--GPRS has already been activated,ret=%d.-->\r\n",ret);
                    m_tcp_state = STATE_GPRS_GET_DNSADDRESS;
                }else//error
                {
                    APP_DEBUG("<--Activate GPRS failure,ret=%d.-->\r\n",ret);
                    m_tcp_state = STATE_GPRS_ACTIVATE;
                }
                break;
            }
            case STATE_GPRS_GET_DNSADDRESS:
            {            
                u8 primaryAddr[16] = {0};
                u8 bkAddr[16] = {0};
                ret =Ql_GPRS_GetDNSAddress(0, (u32*)primaryAddr,  (u32*)bkAddr);
                if (ret == GPRS_PDP_SUCCESS)
                {
                    APP_DEBUG("<--Get DNS address successfully,primaryAddr=%d.%d.%d.%d,bkAddr=%d.%d.%d.%d-->\r\n",primaryAddr[0],primaryAddr[1],primaryAddr[2],primaryAddr[3],bkAddr[0],bkAddr[1],bkAddr[2],bkAddr[3]);            
                    m_tcp_state = STATE_GPRS_GET_LOCALIP;
                }else
                {
                     APP_DEBUG("<--Get DNS address failure,ret=%d.-->\r\n",ret);
                    m_tcp_state = STATE_GPRS_DEACTIVATE;
                }
                break;
            }
            case STATE_GPRS_GET_LOCALIP:
            {
                u8 ip_addr[5];
                Ql_memset(ip_addr, 0, 5);
                ret = Ql_GPRS_GetLocalIPAddress(0, (u32 *)ip_addr);
                if (ret == GPRS_PDP_SUCCESS)
                {
                    APP_DEBUG("<--Get Local Ip successfully,Local Ip=%d.%d.%d.%d-->\r\n",ip_addr[0],ip_addr[1],ip_addr[2],ip_addr[3]);
                    m_tcp_state = STATE_CHACK_SRVADDR;
                }else
                {
                    APP_DEBUG("<--Get Local Ip failure,ret=%d.-->\r\n",ret);
                }
                break;
            }
            case STATE_CHACK_SRVADDR:
            {
                Ql_memset(m_ipaddress,0,5);
                ret = Ql_IpHelper_ConvertIpAddr(m_SrvADDR, (u32 *)m_ipaddress);
                if(ret == SOC_SUCCESS) // ip address, xxx.xxx.xxx.xxx
                {
                    APP_DEBUG("<--Convert Ip Address successfully,m_ipaddress=%d,%d,%d,%d-->\r\n",m_ipaddress[0],m_ipaddress[1],m_ipaddress[2],m_ipaddress[3]);
                    m_tcp_state = STATE_SOC_REGISTER;
                    
                }else  //domain name
                {
                    ret = Ql_IpHelper_GetIPByHostName(0, 0, m_SrvADDR, Callback_GetIpByName);
                    if(ret == SOC_SUCCESS)
                    {
                        APP_DEBUG("<--Get ip by hostname successfully.-->\r\n");
                    }
                    else if(ret == SOC_WOULDBLOCK)
                    {
                        APP_DEBUG("<--Waiting for the result of Getting ip by hostname,ret=%d.-->\r\n",ret);
                        //waiting CallBack_getipbyname
                    }
                    else
                    {
                        APP_DEBUG("<--Get ip by hostname failure:ret=%d-->\r\n",ret);
                        if(ret == SOC_BEARER_FAIL)  
                        {
                             m_tcp_state = STATE_GPRS_DEACTIVATE;
                        }
                        else
                        {
                             m_tcp_state = STATE_GPRS_GET_DNSADDRESS;
                        } 
                    }
                }
                break;
            }
            case STATE_SOC_REGISTER:
            {
                ret = Ql_SOC_Register(callback_soc_func, NULL);
                if (SOC_SUCCESS == ret)
                {
                    APP_DEBUG("<--Register socket callback function successfully.-->\r\n");
                    m_tcp_state = STATE_SOC_CREATE;
                }else if (SOC_ALREADY == ret)
                {
                    APP_DEBUG("<--Socket callback function has already been registered,ret=%d.-->\r\n",ret);
                    m_tcp_state = STATE_SOC_CREATE;
                }else
                {
                    APP_DEBUG("<--Register Socket callback function failure,ret=%d.-->\r\n",ret);
                }
                break;
            }
            case STATE_SOC_CREATE:
            {
                m_socketid = Ql_SOC_Create(0, SOC_TYPE_TCP);
                if (m_socketid >= 0)
                {
                    APP_DEBUG("<--Create socket id successfully,socketid=%d.-->\r\n",m_socketid);
                    m_tcp_state = STATE_SOC_CONNECT;
                }else
                {
                    APP_DEBUG("<--Create socket id failure,error=%d.-->\r\n",m_socketid);
                }
                break;
            }
            case STATE_SOC_CONNECT:
            {
                m_tcp_state = STATE_SOC_CONNECTING;
                ret = Ql_SOC_Connect(m_socketid,(u32) m_ipaddress, m_SrvPort);
                if(ret == SOC_SUCCESS)
                {
                    APP_DEBUG("<--The socket is already connected.-->\r\n");
                    m_tcp_state = STATE_SOC_SEND;
                    
                }else if(ret == SOC_WOULDBLOCK)
                {
                      if (!timeout_90S_monitor)//start timeout monitor
                      {
                        Ql_Timer_Start(TIMEOUT_90S_TIMER_ID, TIMEOUT_90S_PERIOD, FALSE);
                        timeout_90S_monitor = TRUE;
                      }
                      APP_DEBUG("<--Waiting for the result of socket connection,ret=%d.-->\r\n",ret);
                      //waiting CallBack_getipbyname
                      
                }else //error
                {
                    APP_DEBUG("<--Socket Connect failure,ret=%d.-->\r\n",ret);
                    APP_DEBUG("<-- Close socket.-->\r\n");
                    Ql_SOC_Close(m_socketid);
                    m_socketid = -1;
                    
                    if(ret == SOC_BEARER_FAIL)  
                    {
                        m_tcp_state = STATE_GPRS_DEACTIVATE;
                    }
                    else
                    {
                        m_tcp_state = STATE_GPRS_GET_DNSADDRESS;
                    }
                }
                break;
            }
            case STATE_SOC_SEND:
            {
                if (!Ql_strlen(m_send_buf))//no data need to send
                    break;
                
                m_tcp_state = STATE_SOC_SENDING;
                
                do
                {
                    ret = Ql_SOC_Send(m_socketid, m_pCurrentPos, m_remain_len);
                    APP_DEBUG("<--Send data,socketid=%d,number of bytes sent=%d-->\r\n",m_socketid,ret);
                    if(ret == m_remain_len)//send compelete
                    {
                        m_remain_len = 0;
                        m_pCurrentPos = NULL;
                        m_nSentLen += ret;
                        m_tcp_state = STATE_SOC_ACK;
                        break;
                    }
                    else if((ret <= 0) && (ret == SOC_WOULDBLOCK)) 
                    {
                        //waiting CallBack_socket_write, then send data;     
                        break;
                    }
                    else if(ret <= 0)
                    {
                        APP_DEBUG("<--Send data failure,ret=%d.-->\r\n",ret);
                        APP_DEBUG("<-- Close socket.-->\r\n");
                        Ql_SOC_Close(m_socketid);//error , Ql_SOC_Close
                        m_socketid = -1;

                        m_remain_len = 0;
                        m_pCurrentPos = NULL; 
                        if(ret == SOC_BEARER_FAIL)  
                        {
                            m_tcp_state = STATE_GPRS_DEACTIVATE;
                        }
                        else
                        {
                            m_tcp_state = STATE_GPRS_GET_DNSADDRESS;
                        }
                        break;
                    }
                    else if(ret < m_remain_len)//continue send, do not send all data
                    {
                        m_remain_len -= ret;
                        m_pCurrentPos += ret; 
                        m_nSentLen += ret;
                    }
                }while(1);
                break;
            }
            case STATE_SOC_ACK:
            {
                u64 ackedNumCurr;
                ret = Ql_SOC_GetAckNumber(m_socketid, &ackedNumCurr);
                if (ret < 0)
                {
                    checkErr_AckNumber(ret);
                }
                if (m_nSentLen == ackedNumCurr)
                {
                    if (timeout_90S_monitor) //stop timeout monitor
                    {
                        Ql_Timer_Stop(TIMEOUT_90S_TIMER_ID);
                        timeout_90S_monitor = FALSE;
                    }
                    
                    APP_DEBUG("<-- ACK Number:%llu/%llu. Server has received all data. -->\r\n\r\n", m_nSentLen, ackedNumCurr);

                    Ql_memset(m_send_buf,0,SEND_BUFFER_LEN);
                    m_tcp_state = STATE_SOC_SEND;
                }
                else
                {
                    if (!timeout_90S_monitor)//start timeout monitor
                    {
                        Ql_Timer_Start(TIMEOUT_90S_TIMER_ID, TIMEOUT_90S_PERIOD, FALSE);
                        timeout_90S_monitor = TRUE;
                    }
                    
                    APP_DEBUG("<-- ACK Number:%llu/%llu from socket[%d] -->\r\n", ackedNumCurr, m_nSentLen, m_socketid);
                }
                break;
            }
            case STATE_GPRS_DEACTIVATE:
            {
                APP_DEBUG("<--Deactivate GPRS.-->\r\n");
                Ql_GPRS_Deactivate(0);
                break;
            }
            default:
                break;
        }    
    }
}
Exemplo n.º 8
0
static void proc_handle(char *pData,s32 len)
{
    char *p = NULL;
    s32 iret;
    u8 srvport[10];

    //command: Set_APN_Param=<APN>,<username>,<password>
    p = Ql_strstr(pData,"Set_APN_Param=");
    if (p)
    {
        Ql_memset(m_apn, 0, 10);
        if (Analyse_Command(pData, 1, '>', m_apn))
        {
            APP_DEBUG("<--APN Parameter Error.-->\r\n");
            return;
        }
        Ql_memset(m_userid, 0, 10);
        if (Analyse_Command(pData, 2, '>', m_userid))
        {
            APP_DEBUG("<--APN Username Parameter Error.-->\r\n");
            return;
        }
        Ql_memset(m_passwd, 0, 10);
        if (Analyse_Command(pData, 3, '>', m_passwd))
        {
            APP_DEBUG("<--APN Password Parameter Error.-->\r\n");
            return;
        }
        
        APP_DEBUG("<--Set APN Parameter Successfully<%s>,<%s>,<%s>.-->\r\n",m_apn,m_userid,m_passwd);

        return;
    }
    
    //command: Set_Srv_Param=<srv ip>,<srv port>
    p = Ql_strstr(pData,"Set_Srv_Param=");
    if (p)
    {
        Ql_memset(m_SrvADDR, 0, SRVADDR_BUFFER_LEN);
        if (Analyse_Command(pData, 1, '>', m_SrvADDR))
        {
            APP_DEBUG("<--Server Address Parameter Error.-->\r\n");
            return;
        }
        Ql_memset(srvport, 0, 10);
        if (Analyse_Command(pData, 2, '>', srvport))
        {
            APP_DEBUG("<--Server Port Parameter Error.-->\r\n");
            return;
        }
        m_SrvPort = Ql_atoi(srvport);
        APP_DEBUG("<--Set TCP Server Parameter Successfully<%s>,<%d>.-->\r\n",m_SrvADDR,m_SrvPort);

        m_tcp_state = STATE_NW_GET_SIMSTATE;
        APP_DEBUG("<--Restart the TCP connection process.-->\r\n");

        return;
    }

    //if not command,send it to server
    m_pCurrentPos = m_send_buf;
    Ql_strcpy(m_pCurrentPos + m_remain_len, pData);
    
    m_remain_len = Ql_strlen(m_pCurrentPos);
    
}
Exemplo n.º 9
0
bool parse_header(void *clients,HttpHeader *http_header){
	char *param;
	char *value;
	char *last;
	char *ph;
	char* bon_val = NULL;
	char header[1024 * 2];
    char*lens=NULL;
    QlClient *client=(QlClient*)clients;
	char* head = Ql_strstr((char*)client->recvBuffer, "\r\n\r\n");
	if (head) {
       
        http_header->set_cookie=FALSE;
        http_header->authorization=FALSE;
        Ql_memset(http_header->action,0,100);
        Ql_memset(http_header->boundary,0,200);
        Ql_memset(http_header->cookie,0,200);
        Ql_memset(http_header->data,0,10 * 1024);
        http_header->length=0;
         Ql_strcpy(http_header->cookie, "NONE"); 
		int head_len = (char*)head - ((char*)client->recvBuffer);
		int body_len = (int)(client->pRecvCurrentPos) - head_len - 4;
		Ql_memcpy(header, client->recvBuffer, head_len);
		ph = strtok_r(header, "\r\n", &last);
		char* lst;
		if (Ql_strstr(ph, "GET")!=NULL)
		{
			char* act = strtok_r(ph+4, " ", &lst);
			if (Ql_strlen(act)>1) 
                Ql_strcpy(http_header->action, act+1); 
            else
                Ql_strcpy(http_header->action, act); 
			http_header->method = GET;
            OUTD("action:%s",http_header->action);
		}
		if (Ql_strstr(ph, "POST")!=NULL) {
			http_header->method = POST;
			char* act = strtok_r(ph+5, " ", &lst);
            if (Ql_strlen(act)>1) 
                Ql_strcpy(http_header->action, act+1); 
            else
                Ql_strcpy(http_header->action, act); 
		}
		while (1)
		{
			ph = strtok_r(NULL, "\r", &last);
			if (ph == NULL) {
				return TRUE;
			}
			param = strtok_r(ph + 1, ":", &value);
			if (Ql_strstr(param, "Content-Type")) {
				char* bon = Ql_strstr(value, "boundary");
				bon_val = bon + 9;
				Ql_strcpy(http_header->boundary, bon_val);
			}
			else if ((lens = Ql_strstr(param, "Cookie"))!=NULL)
			{
                char* cookie;
                if ((cookie=Ql_strstr(value,"__ztp"))!=NULL) {
                    Ql_strcpy(http_header->cookie, cookie+6); 
                    http_header->authorization=TRUE;
                    http_header->set_cookie=FALSE;
                }
			}
			else if ((lens = Ql_strstr(param, "Content-Length"))!=NULL) {
				char* slen = lens + 16;
				int len_head = Ql_atoi(slen);
				http_header->length = len_head;
				if (len_head == body_len){
					OUTD("data full",NULL);
                }
                else
                {
                    OUTD("not full data.wait:%d have:%d", len_head, body_len);
                    return FALSE;
                }
              }
            else if ((lens = Ql_strstr(param, "Authorization"))!=NULL) {
                /*char* slen = lens + 21;
                unsigned char dbuf[50];
                Ql_memset(dbuf,0,50);
                decode_b64((unsigned char*)slen,dbuf);
                OUTD("decode buf:%s",dbuf);
                param = strtok_r((char*)dbuf, ":", &value);
                if (Ql_strstr(param,"admin") && Ql_strstr(value,"admin")) {
                    OUTD("Autorization user:%s pswd:%s",param,value);
                    http_header->authorization=TRUE;
                    http_header->set_cookie=TRUE;
                }*/
            }
        }
		}
	else
	{
        return FALSE;
	}
}
Exemplo n.º 10
0
void page_response(HttpHeader *header){
	bool reset=FALSE;
	bool prepare=TRUE;
    char* action=header->action;
    OUTD("action=%s",action);
	Ql_memset(__data_buf,0,4096);
	Ql_memset(__s_buf,0,10240);
    
    if (Ql_strstr(header->action, "/")) {
		get_main_page( __est_connection ? "System state is start":"System state stop");
        OUTD("main page",NULL);
	}
	else if (Ql_strstr(action,"reboot")) {
		get_rebot_page();
		reset=TRUE;
	}
	else if (Ql_strstr(action,"settings?")) {
		char* pch=NULL;
		char* last=NULL;
		//OUTD("parse setting action:%s",pch);
		pch=strtok_r(action+9,"&",&last);
	  //OUTD("parse command:%s",pch);
     while (pch!=NULL) {
        setCommand(pch);
        pch=strtok_r(NULL,"&",&last);
		//OUTD("parse command:%s",pch);
    }
	
     WriteSettings();
	 ReadSettings();
	 get_main_page("Save settings controller is OK");
	}
	else if (Ql_strstr(action,"date?")) {
		bool sdt=SetLocDate(action+5);
		get_main_page(sdt ? "Set date and time is OK":"Error set date and time");
	}
	else if (Ql_strstr(action,"stop")) {
		StopEstConnection();
		get_main_page("Recive command Stop");
	}
	else if (Ql_strstr(action,"run")) {
		nSTATE=STATE_EST_SOCKET_CREATE;
		get_main_page("Recive command Start");
	}
	else if (Ql_strstr(action,"log")) {
		u16 size=0;
		ReadLogFile(&size);
		Ql_sprintf(__s_buf,__download_page,size);
		//Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log);
		
		Ql_memcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log,size);
		OUTD("__download_page:%d file size:%d buffer-len:%d",Ql_strlen(__download_page),size,Ql_strlen(__s_buf));
		
		prepare=FALSE;
	}
    else if (Ql_strstr(action, "autorize")) {
        Ql_sprintf(__s_buf,__autorize,0);
        prepare=FALSE;
        OUTD("set autorize",NULL);
    }
    else {
		get_error_page();
		Ql_sprintf(__s_buf,__error_page,0);
		prepare=FALSE;
	}
	if (prepare) {
        //if (header->set_cookie) {
          //   Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf),"\r\nSet-Cookie: __ztp=987654321\r\n"); 
        //}
        Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf)); 
		Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__data_buf);
        OUTD("sbuf:%d dbuf:%d",Ql_strlen(__s_buf),Ql_strlen(__data_buf));
        
	}
	if (reset) {
		Ql_Sleep(10000);
		Ql_Reset(0);
	}
}