Пример #1
0
boolean gprsSetCustomAPN(void *userData)
{
	LGPRSAttachContext *pCntx = (LGPRSAttachContext*)userData;
	VMUINT32 dtacct = 0;
	VMINT ret = 0;
	
	ret = vm_set_cust_apn_info(&pCntx->info, &dtacct);
	
	if(0 != ret)
	{
		vm_log_error("vm_set_cust_apn_info fails with %d", ret);
		pCntx->result = ret;
		return true;
	}

	// we have only 1 SIM card, note that it is index so we use 0, not define SIM
	ret = vm_dtacct_set(0, dtacct);
	if(0 != ret)
	{
		vm_log_error("vm_dtacct_set fails with %d", ret);
		pCntx->result = ret;
		return true;
	}
	
	pCntx->result = 0;
	return true;
}
Пример #2
0
boolean LTcpClient::wifiPeek(void *userData)
{
	LTcpClient *pThis = (LTcpClient*)userData;

	if(pThis->m_peekBuffered)
	{
		return true;
	}

	// read and store the peeked byte
	LTcpReadWriteContext cntx;
	cntx.buf = &pThis->m_peekByte;
	cntx.len = sizeof(pThis->m_peekByte);
	cntx.handle = pThis->m_handle.m_handle;
	cntx.serverHandle = pThis->m_handle.m_serverHandle;
	cntx.lenProcessed = 0;
	cntx.pInst = pThis;
	if(!wifiRead(&cntx))
	{
		vm_log_error("read fail in wifiPeek");
	}

	if (cntx.lenProcessed > 0)
	{
		pThis->m_peekBuffered = true;
	}
	else
	{
		pThis->m_peekBuffered = false;
	}

	return true;
}
Пример #3
0
vm_phb_req_error_enum vm_sal_phb_get_contact_syn(vm_phb_get_req_struct* req_info)
{
    srv_phb_sdk_get_req_struct  req;
    srv_phb_sdk_contact_struct * contact = NULL;
    VMINT result = -1;
    vm_phb_req_error_enum res = VM_PHB_REQ_ERROR;

    contact = vm_calloc(sizeof(srv_phb_sdk_contact_struct));
    if(contact == NULL)
    {
        vm_log_error("vm_sal_phb_get_contact_syn:contact == NULL");
        return VM_PHB_REQ_ERROR;	
    }

    memset(&req, 0, sizeof(req));	

    req.contact_ptr = contact;
    vm_phb_build_contact_pos(&req ,  req_info);

    result = srv_phb_sdk_get_contact(&req);
    if(result == SRV_PHB_NO_ERROR)  
    {
        vm_phb_build_contact_ptr(req_info->contact_ptr, req.contact_ptr);
        res = VM_PHB_REQ_NO_ERROR;
    }

    vm_log_debug("vm_sal_phb_get_contact_syn:vm_get_tick_count2()=%d",vm_get_tick_count()); 	
    vm_free(contact);
    vm_log_debug("vm_sal_phb_get_contact_syn:end");  

    return res;

}
Пример #4
0
VMINT vm_sal_phb_get_used_contacts(vm_phb_contact_pos_struct* pos_array,  vm_phb_storage_loc_enum storage)
{
    VMINT used_nums = 0;
    phb_storage_enum  storage_loc;
    srv_phb_contact_pos_struct  *contact_array = NULL;
    int i=0;
    VMINT nums = 0;

    storage_loc = vm_sal_phb_trans_storage(storage);
    used_nums = srv_phb_sdk_get_used_contacts(contact_array, storage_loc);

    if(used_nums < 0)  
    {
        vm_log_error("vm_sal_phb_get_used_contacts:used_nums < 0");
        return VM_PHB_REQ_ERROR;
    }

    if(pos_array == NULL)
    {
        vm_log_error("vm_sal_phb_get_used_contacts:pos_array == NULL");
        return used_nums;
    } 

    if(used_nums == 0)  
        return used_nums;

    contact_array = vm_calloc(sizeof(srv_phb_contact_pos_struct)*used_nums);
    if(contact_array == NULL)
    {
        vm_log_error("vm_sal_phb_get_used_contacts:contact_array == NULL");
        return VM_PHB_REQ_ERROR;	
    }

    storage_loc = vm_sal_phb_trans_storage(storage);
    nums = srv_phb_sdk_get_used_contacts(contact_array, storage_loc);
    if(nums > 0)
    {
        for(i=0; i < used_nums; i++ )
        {
            pos_array[i].index =contact_array[i].index;
            pos_array[i].storage=vm_sal_phb_trans_storage_ex(contact_array[i].storage);
        }
    }
    vm_free(contact_array);
    return used_nums;

}
Пример #5
0
static void onWifiUninitialized(void *userData, vm_wlan_req_res_enum result)
{
  if (result != VM_WLAN_REQ_RES_DONE)
  {
    vm_log_error("onWifiUninitialized: result error code %d", result);
  }
  LTask.post_signal();
}
Пример #6
0
boolean LUDP::udpSend(void* userdata)
{
	LUDPSendContext *pCntx = (LUDPSendContext*)userdata;
	LUDP* pThis = pCntx->pThis;
	VMINT remainBuffer = pThis->m_writePos;
	VMUINT8 *pBuf = &pThis->m_writeBuffer[0];

	vm_sockaddr_struct sendto = {0};
	sendto.addr[0] = pThis->m_sendToIP[0];
	sendto.addr[1] = pThis->m_sendToIP[1];
	sendto.addr[2] = pThis->m_sendToIP[2];
	sendto.addr[3] = pThis->m_sendToIP[3];
	sendto.addr_len = 4;
	sendto.port = pThis->m_sendToPort;

	vm_log_info("send packet len:%d to %d.%d.%d.%d:%d",
				remainBuffer,
				sendto.addr[0],
				sendto.addr[1],
				sendto.addr[2],
				sendto.addr[3],
				sendto.port);

	while(remainBuffer > 0)
	{
		VMINT sentBytes = 0;
		sentBytes = vm_udp_sendto(pThis->m_serverHandle,
								  pBuf,
								  remainBuffer,
								  &sendto);
		
		vm_log_info("vm_udp_sendto returns %d", sentBytes);


		if(sentBytes <= 0)
		{
			vm_log_error("vm_udp_sendto sent no content");
			break;
		}	

		pBuf += sentBytes;
		remainBuffer -= sentBytes;
	}

	// check if buffer is completely sent
	if(remainBuffer <= 0)
	{
		pCntx->sentComplete = 1;
	}
	else
	{
		pCntx->sentComplete = 0;
	}

	return true;
}
Пример #7
0
//-----------------------------------------------------------------------------------
static int linenoise_internal_addhistory( int id, const char *line, int force_empty ) 
{
  char *linecopy;
  const char *p;
  const int history_max_len = history_max_lengths[ id ];
         
  if ( history_max_len == 0 ) return 0;

  if ( histories[ id ] == NULL ) {
    if ( ( histories[ id ] = malloc( sizeof( char* ) * history_max_len ) ) == NULL ) {
      vm_log_error("out of memory in linenoise while trying to allocate history buffer." );
      return 0;
    }
    memset( histories[ id ], 0, ( sizeof( char* ) * history_max_len ) );
  }

  while( 1 )
  {
    if ( ( p = strchr( line, '\n' ) ) == NULL ) p = line + strlen( line );

    if ( p > line || force_empty == LINENOISE_PUSH_EMPTY ) {
      if ( ( linecopy = strndup( line, p - line ) ) == NULL ) {
        vm_log_error("out of memory in linenoise while trying to add a line to history.");
        return 0; 
      }

      if ( history_lengths[ id ] == history_max_len ) {
        free( histories[ id ][ 0 ] );
        memmove( histories[ id ], histories[ id ] + 1, sizeof( char* ) * ( history_max_len - 1 ) );
        history_lengths[ id ] --;
      }
      histories[ id ][history_lengths[ id ]] = linecopy;
      history_lengths[ id ] ++;
    }
    if ( *p == 0 ) break;
    line = p + 1;
    if ( *line == 0 ) break;
  }
  return 1;
}
Пример #8
0
void LUDP::udpCallback(VMINT hdl, VMINT event)
{
	switch(event)
	{
	case VM_UDP_EVT_WRITE:
		break;
	case VM_UDP_EVT_READ:
		break;
	case VM_UDP_EVT_PIPE_BROKEN:
	case VM_UDP_EVT_PIPE_CLOSED:
		vm_log_error("udpCallback error! evt=%d hdl=%d", event, hdl);
		break;
	}
}
Пример #9
0
VMINT vm_sal_phb_get_used_contacts_count(vm_phb_storage_loc_enum storage)
{
    VMINT used_nums;
    phb_storage_enum  storage_loc;

    storage_loc = vm_sal_phb_trans_storage(storage);
    used_nums = srv_phb_sdk_get_used_contacts(NULL, storage_loc);

    if(used_nums <0)  
    {
        vm_log_error("vm_sal_phb_get_used_contacts_count:used_nums <0");
        return VM_PHB_REQ_ERROR;
    }

    return used_nums;
}
Пример #10
0
vm_phb_req_error_enum vm_sal_phb_search_contact_syn(vm_phb_search_req_struct* req_info)
{
    srv_phb_sdk_search_req_struct  req;
    srv_phb_sdk_contact_struct * contact = NULL;
    VMINT result = -1;
    vm_phb_req_error_enum res = VM_PHB_REQ_ERROR;

    vm_log_debug("vm_sal_phb_search_contact_syn: start");

    contact = vm_calloc(sizeof(srv_phb_sdk_contact_struct));
    if(contact == NULL)
    {
        vm_log_error("vm_sal_phb_search_contact_syn:contact == NULL");
        return VM_PHB_REQ_ERROR;	
    }

    memset(&req, 0, sizeof(req));	  

    req.contact_ptr = contact;

    vm_wstrncpy((VMWSTR)req.pattern_ucs2, req_info->pattern_ucs2,  SRV_PHB_SEARCH_LENGTH-1);
    req.search_type = (srv_phb_search_type_enum)req_info->search_type;
      
    vm_log_debug("vm_sal_phb_search_contact_syn: req.search_type=%d,req.pattern_ucs2=%s", req.search_type, vm_gb2312_string((VMWSTR)req.pattern_ucs2));
    result = srv_phb_sdk_search_contact(&req);
    if(result == SRV_PHB_NO_ERROR)  
    {
        vm_phb_build_contact_ptr(req_info->contact_ptr, req.contact_ptr);
        res = VM_PHB_REQ_NO_ERROR;
    }

    vm_free(contact);
    vm_log_debug("vm_sal_phb_search_contact_syn:srv_phb_sdk_search_contact end");

    return res;

}
Пример #11
0
//-----------------------------------------------------------------
int _get_paramstr(char **param_buf, char **par_end, char **var_ptr)
{
	int psize, err = 0;

	psize = vm_fs_app_data_get_free_space();
	if (psize > MAX_SYSTEM_PARAMS_SIZE) {
		// no parameters
    	vm_log_debug("parameters not found");
		return -1;
	}

	char *parambuf = vm_calloc(MAX_SYSTEM_PARAMS_SIZE+1);
	if (parambuf == NULL) {
    	vm_log_error("error allocating buffer");
		return -2;
	}

	VM_FS_HANDLE phandle = vm_fs_app_data_open(VM_FS_MODE_READ, VM_FALSE);
	if (phandle < VM_FS_SUCCESS) {
    	vm_log_error("error opening params");
		return -3;
	}

	if (vm_fs_app_data_read(phandle, parambuf, MAX_SYSTEM_PARAMS_SIZE, &psize) < 0) {
    	vm_log_error("error reading params");
    	vm_fs_app_data_close(phandle);
		return -4;
	}

	vm_fs_app_data_close(phandle);

	parambuf[psize] = '\0';

	// === Check crc ===
	char *parend = strstr(parambuf, "\n__SYSVAR=\"");	// end of __SYSPAR table
	if (parend == NULL) {
		err = -5;
		goto exit;
	}

	char *varptr = parend + 11;					// start of __SSVAR
	char *varend = strstr(varptr, "\"");	// end of __SYSVAR
	if (varend == NULL){
		err = -6;
		goto exit;
	}
	if ((varend - varptr) != SYSVAR_SIZE) {
		err = -7;
		goto exit;
	}

	// calculate crc
	CRC16_Context contex;
	uint16_t parcrc;
	CRC16_Init( &contex );
	CRC16_Update( &contex, parambuf, (varptr - parambuf) + SYSVAR_SIZE - 4);
	CRC16_Final( &contex, &parcrc );
	// compare
	char crcstr[5] = {'\0'};
	memcpy(crcstr, varptr + SYSVAR_SIZE - 4, 4);
	uint16_t crc = (uint16_t)strtol(crcstr, NULL, 16);
	if (crc != parcrc) {
		err = -8;
	}
	else {
		*param_buf = parambuf;
		*par_end = parend;
		*var_ptr = varptr;
		return 0;
	}

exit:
	vm_log_error("SYSPAR wrong format");
	return err;
}
Пример #12
0
VMINT vm_sal_phb_search_contact_list(vm_phb_search_list_req_struct* req_info, vm_phb_contact_pos_struct* pos_array, VMINT post_array_len)
{
	srv_phb_contact_pos_struct  *contact_array = NULL;
	srv_phb_sdk_get_req_struct  req;
	srv_phb_sdk_contact_struct * contact = NULL;
	VMINT used_nums = 0;
	VMINT res = 0;
	VMINT j = 0;
	VMINT i = 0;

    used_nums = srv_phb_sdk_get_used_contacts(contact_array, vm_sal_phb_trans_storage(VM_PHB_STORAGE_LOC_BOTH));

    if(used_nums < 0)  
    {
        vm_log_error("vm_sal_phb_search_contact_list:used_nums < 0");
        return VM_PHB_REQ_ERROR;
    }

    if(used_nums == 0)  
        return used_nums;

    contact_array = vm_calloc(sizeof(srv_phb_contact_pos_struct)*used_nums);

    if(contact_array == NULL)
    {
        vm_log_error("vm_sal_phb_search_contact_list:contact_array == NULL");
        return VM_PHB_REQ_ERROR;	
    }
  
	used_nums = srv_phb_sdk_get_used_contacts(contact_array, vm_sal_phb_trans_storage(VM_PHB_STORAGE_LOC_BOTH));
	
	vm_log_debug("vm_sal_phb_search_contact_list:used_nums=%d", used_nums);

	contact = vm_calloc(sizeof(srv_phb_sdk_contact_struct));
	if(contact == NULL)
	{
		vm_free(contact_array);
		vm_log_error("vm_sal_phb_search_contact_list:contact == NULL");
		return VM_PHB_REQ_ERROR;	
      }
	
       for(i=0; i< used_nums; i++)
       {
       	memset(&req, 0, sizeof(srv_phb_sdk_get_req_struct));
		memset(contact, 0, sizeof(srv_phb_sdk_contact_struct));
		req.contact_ptr = contact;
		req.pos.index= contact_array[i].index;
		req.pos.storage= contact_array[i].storage;	  
		contact->pos.index = contact_array[i].index;
		contact->pos.storage = contact_array[i].storage;	  
		  
		vm_log_debug("vm_sal_phb_search_contact_list  contact_array[%d].index=%d",  i, contact_array[i].index);
		vm_log_debug("vm_sal_phb_search_contact_list  contact_array[%d].storage=%d", i, contact_array[i].storage);
		res = srv_phb_sdk_get_contact(&req);
		if(res == SRV_PHB_NO_ERROR)
		{
			if(contact != NULL )
			{
				vm_log_debug("vm_sal_phb_search_contact_list:search_req->search_type=%d",req_info->search_type);
			
				if(req_info->search_type == VM_PHB_SEARCH_TYPE_NAME)
				{
					vm_log_debug("vm_sal_phb_search_contact_list:search_req->pattern_ucs2=%s",vm_gb2312_string(req_info->pattern_ucs2));
					vm_log_debug("vm_sal_phb_search_contact_list:contact_ptr->name=%s",vm_gb2312_string((VMWSTR)contact->name));
					if(vm_wstrcmp((VMWSTR)req_info->pattern_ucs2, (VMWSTR)&contact->name) == 0)
					{
						pos_array[j].index = 	contact->pos.index;
						pos_array[j].storage = vm_sal_phb_trans_storage_ex(contact->pos.storage);
						j++;
						
					}
				}  
		   		else if(req_info->search_type == VM_PHB_SEARCH_TYPE_NUM)
				{
					vm_log_debug("vm_sal_phb_search_contact_list:search_req->pattern_ucs2=%s",vm_gb2312_string(req_info->pattern_ucs2));
					vm_log_debug("vm_sal_phb_search_contact_list:contact_ptr->number=%s",vm_gb2312_string((VMWSTR)contact->number));
					if(vm_wstrcmp((VMWSTR)req_info->pattern_ucs2, (VMWSTR)&contact->number) == 0)
					{
						pos_array[j].index = 	contact->pos.index;
						pos_array[j].storage = vm_sal_phb_trans_storage_ex(contact->pos.storage);
						j++;
					}
				} 
				else
				{
					vm_log_error("vm_sal_phb_search_contact_list: req_info->search_type =%d",req_info->search_type);
				}
			}
			
			if(j == post_array_len)
			{
				break;
			}
		}
		
       }
	   
	vm_free(contact_array);
	vm_free(contact);

	return j;     
	 
}