Exemplo n.º 1
0
void client_loop(void)
{
    int i = 0;  //loop iterator
    if (socket_conneted())
    {
        if (client_logined())
        {
            if (data.isGpsFixed)
            {
                MSG_GPS* msg = alloc_msg(CMD_GPS, sizeof(MSG_GPS));

                if (!msg)
                {
                    LOG_ERROR("alloc message failed");
                }

                msg->gps = data.gps;
                socket_sendData(msg, sizeof(MSG_GPS));
                LOG_DEBUG("send GPS message");
            }
            else
            {
                size_t msgLen = sizeof(MSG_HEADER) + sizeof(CGI) + sizeof(CELL) * data.cellNum;
                MSG_HEADER* msg = alloc_msg(CMD_CELL, msgLen);
                CGI* cgi = (CGI*) msg + 1;
                CELL* cell = (CELL*)cgi + 1;
                if (!msg)
                {
                    LOG_ERROR("alloc message failed");
                }

                memcpy(cgi, &(data.cgi), sizeof(CGI));
                for (i = 0; i < data.cellNum; i++)
                {
                    memcpy(cell + i, data.cells + i, sizeof(CELL));
                }
                socket_sendData(msg, msgLen);
                LOG_DEBUG("send CELL message");
            }
        }
        else
        {
            MSG_LOGIN_REQ* msg = alloc_msg(CMD_LOGIN, sizeof(MSG_LOGIN_REQ));
            u8 imei[16] = {0};

            eat_get_imei(imei, 15);

            if (!msg)
            {
                LOG_ERROR("alloc message failed");
            }

            memcpy(msg->IMEI, imei, 16);
            socket_sendData(msg, sizeof(MSG_LOGIN_REQ));
            LOG_DEBUG("send login message");
        }

    }

}
Exemplo n.º 2
0
static int threadCmd_Location(const MSG_THREAD* msg)
{
    LOCAL_GPS* gps = (LOCAL_GPS*) msg->data;

    if (msg->length < sizeof(LOCAL_GPS)  || !gps)
    {
        LOG_ERROR("msg from THREAD_GPS error!");
        return -1;
    }

    if (gps->isGps)             //update the local GPS data
    {
        MSG_GPSLOCATION_RSP* msg = alloc_msg(CMD_LOCATE, sizeof(MSG_GPSLOCATION_RSP));
        if (!msg)
        {
            LOG_ERROR("alloc message failed!");
            return -1;
        }
        msg->isGps= gps->isGps;
        memcpy(&msg->gps, &gps->gps, sizeof(GPS));

        msg->gps.timestamp = htonl(gps->gps.timestamp);
        msg->gps.course = htons(gps->gps.course);

        LOG_DEBUG("send GPS_LOCATION message.");
        socket_sendDataDirectly(msg, sizeof(MSG_GPSLOCATION_RSP));
    }
    else                //update local cell info
    {
        size_t msgLen = sizeof(MSG_CELLLOCATION_HEADER) + sizeof(CGI) + sizeof(CELL) * gps->cellInfo.cellNo;
        MSG_CELLLOCATION_HEADER* msg = alloc_msg(CMD_LOCATE, msgLen);
        CGI* cgi = (CGI*)(msg + 1);
        CELL* cell = (CELL*)(cgi + 1);
        int i = 0;

        if (!msg)
        {
            LOG_ERROR("alloc message failed!");
            return -1;
        }
        msg->isGps = gps->isGps;

        cgi->mcc = htons(gps->cellInfo.mcc);
        cgi->mnc = htons(gps->cellInfo.mnc);
        cgi->cellNo = gps->cellInfo.cellNo;
        for (i = 0; i < gps->cellInfo.cellNo; i++)
        {
            cell[i].lac = htons(gps->cellInfo.cell[i].lac);
            cell[i].cellid = htons(gps->cellInfo.cell[i].cellid);
            cell[i].rxl= htons(gps->cellInfo.cell[i].rxl);
        }

        LOG_DEBUG("send CELL_LOCATION message.");
        socket_sendDataDirectly(msg, msgLen);
    }

    return 0;
}
Exemplo n.º 3
0
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
	arch_message *MsgPkt;
	MsgPkt=alloc_msg();
	MsgPkt->sys_msg = msg;
	SendMbx(*mbox, (iop_message_t *)MsgPkt);
}
Exemplo n.º 4
0
Arquivo: msgutil.c Projeto: mbgg/linux
struct msg_msg *load_msg(const void __user *src, int len)
{
	struct msg_msg *msg;
	struct msg_msgseg *seg;
	int err = -EFAULT;
	int alen;

	msg = alloc_msg(len);
	if (msg == NULL)
		return ERR_PTR(-ENOMEM);

	alen = min(len, DATALEN_MSG);
	if (copy_from_user(msg + 1, src, alen))
		goto out_err;

	for (seg = msg->next; seg != NULL; seg = seg->next) {
		len -= alen;
		src = (char __user *)src + alen;
		alen = min(len, DATALEN_SEG);
		if (copy_from_user(seg + 1, src, alen))
			goto out_err;
	}

	err = security_msg_msg_alloc(msg);
	if (err)
		goto out_err;

	return msg;

out_err:
	free_msg(msg);
	return ERR_PTR(err);
}
Exemplo n.º 5
0
/*
*fun: receive msg from GPS_Thread and send GPSSignal msg to server
*/
static int threadCmd_GPSHdop(const MSG_THREAD* msg)
{
    GPS_HDOP_INFO* msg_data = (GPS_HDOP_INFO*) msg->data;
    MSG_GET_GPS_RSP* hdop_msg;
    u8 msgLen = 0;
    char buf[MAX_DEBUG_BUF_LEN] = {0};

    if (msg->length < sizeof(GPS_HDOP_INFO) || !msg_data)
    {
         LOG_ERROR("msg from THREAD_GPS error!");
         return -1;
    }

    if(!msg_data->satellites)
    {
        snprintf(buf,MAX_DEBUG_BUF_LEN,"GPS not fixed,hdop:%f;satellites:%d",msg_data->hdop,msg_data->satellites);
    }
    else
    {
        snprintf(buf,MAX_DEBUG_BUF_LEN,"GPS fixed,hdop:%f;satellites:%d",msg_data->hdop,msg_data->satellites);
    }

    msgLen = sizeof(MSG_GET_HEADER) + strlen(buf) + 1;
    hdop_msg = alloc_msg(CMD_GET_GPS,msgLen);
    if (!hdop_msg)
    {
        LOG_ERROR("alloc LogInfo rsp message failed!");
        return -1;
    }
    hdop_msg->managerSeq = msg_data->managerSeq;
    strncpy(hdop_msg->data,buf,strlen(buf)+1);
    socket_sendDataDirectly(hdop_msg, msgLen);

    return 0;
}
Exemplo n.º 6
0
int set_gai_errno(int no) {
    errno = no;
    if (no != 0) {
        ErrorMessage * m = alloc_msg(SRC_GAI);
        m->error = no;
    }
    return errno;
}
Exemplo n.º 7
0
err_t
ps2ip_input(PBuf* pInput,NetIF* pNetIF)
{

	//When ps2smap receive data, it invokes this function. It'll be called directly by the interrupthandler, which means we are
	//running in an interrupt-context. We'll pass on the data to the tcpip message-thread by adding a callback message. If the
	//messagebox is full, we can't wait for the tcpip-thread to process a message to make room for our message, since we're in an
	//interrupt-context. If the messagebox or messagequeue is full, drop the packet.

	InputMSG*				pIMSG;
	struct tcpip_msg*		pMSG;
	sys_mbox_t				pMBox=tcpip_getmbox();
	arch_message *          msg;

	//Is the messagequeue full?

	if(IsMSGQueueFull() || ((msg = alloc_msg()) == NULL))
	{

		//Yes, silently drop the packet!

		dbgprintf("ps2ip_input: MessageQueue or MessagePool full, dropping packet\n");
		pbuf_free(pInput);
		return	ERR_OK;
	}

	//Allocate messagequeue entry.

	pIMSG=&aMSGs[u8LastMSG];
	u8LastMSG=GetNextMSGQueueIndex(u8LastMSG);

	//Initialize the InputMSG.

	pIMSG->pInput=pInput;
	pIMSG->pNetIF=pNetIF;

	//Allocate memory for the tcpip-message.

	pMSG=(struct tcpip_msg*)memp_malloc(MEMP_TCPIP_MSG);
	if	(pMSG==NULL)
	{
		//Memory allocation failed, drop packet!

		dbgprintf("ps2ip_input: Failed to allocate memory for tcpip_msg, dropping packet\n");
		pbuf_free(pInput);
		free_msg(msg);
		return	ERR_MEM;  
	}
	pMSG->type=TCPIP_MSG_CALLBACK;
	pMSG->msg.cb.f=InputCB;
	pMSG->msg.cb.ctx=pIMSG;

	//Post the message in the tcpip-thread's messagebox.

    msg->sys_msg = pMSG;
	PostInputMSG(pMBox, msg);
	return	ERR_OK;
}
Exemplo n.º 8
0
int set_error_report_errno(ErrorReport * r) {
    errno = 0;
    if (r != NULL) {
        ReportBuffer * report = (ReportBuffer *)((char *)r - offsetof(ReportBuffer, pub));
        ErrorMessage * m = alloc_msg(SRC_REPORT);
        m->error = report->pub.code + STD_ERR_BASE;
        m->report = report;
        report->refs++;
    }
    return errno;
}
Exemplo n.º 9
0
void sys_mbox_post(sys_mbox_t mbid, void *sys_msg)
{
	arch_message *msg;
	//This function should only be invoked by ps2ip_input. It'll be invoked from an interrupt-context and the pMBox is non-full.

    // FIXME: Not sure if this is the best thing to do, will this lock up the only thread which will free up a message??
    while((msg = alloc_msg()) == NULL) { DelayThread(100); }

    msg->sys_msg = sys_msg;
    SendMbx(mbid, (iop_message_t *) msg);
}
Exemplo n.º 10
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
 * alloc_msg_locking():									    *
 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
struct msg *alloc_msg_locking(void)
{
    struct msg *ret;

    pthread_mutex_lock(&heap_msg_mutex);

    ret = alloc_msg();

    pthread_mutex_unlock(&heap_msg_mutex);
    return ret;
}
Exemplo n.º 11
0
PMSG push_msg(PMSG pmsg)
{
	PMSG ret = alloc_msg();
	if (ret != NULL)
	{
		*ret = *pmsg;
		ENTER_DISP_LEVEL();
		{
			if (QUEBUF_LEN(MSG) != QUEBUF_SIZE(MSG))
				_QUEBUF_PUSH(MSG, ret);
		} // Disp-level
		LEAVE_DISP_LEVEL();
	}
	return( ret );
}
Exemplo n.º 12
0
static int threadCmd_AutolockState(const MSG_THREAD* msg)
{
    AUTOLOCK_INFO* msg_state = (AUTOLOCK_INFO*) msg->data;
    MSG_AUTODEFEND_STATE_REQ* autolock_msg;

    if (msg->length < sizeof(AUTOLOCK_INFO) || !msg_state)
    {
         LOG_ERROR("msg from THREAD_VIBRATION error!");
         return -1;
    }
    autolock_msg = alloc_msg(CMD_DEFEND_NOTIFY, sizeof(MSG_AUTODEFEND_STATE_REQ));
    autolock_msg->state = msg_state->state;

    LOG_DEBUG("send auto lock state change message: %d", msg_state->state);
    socket_sendDataDirectly(autolock_msg, sizeof(MSG_AUTODEFEND_STATE_REQ));

    return 0;
}
Exemplo n.º 13
0
Arquivo: msg.c Projeto: bdidemus/wine
static HRESULT create_msg( WS_ENVELOPE_VERSION env_version, WS_ADDRESSING_VERSION addr_version,
                           const WS_MESSAGE_PROPERTY *properties, ULONG count, WS_MESSAGE **handle )
{
    struct msg *msg;
    HRESULT hr;
    ULONG i;

    if (!(msg = alloc_msg())) return E_OUTOFMEMORY;

    for (i = 0; i < count; i++)
    {
        if (properties[i].id == WS_MESSAGE_PROPERTY_ENVELOPE_VERSION ||
            properties[i].id == WS_MESSAGE_PROPERTY_ADDRESSING_VERSION)
        {
            free_msg( msg );
            return E_INVALIDARG;
        }
        hr = prop_set( msg->prop, msg->prop_count, properties[i].id, properties[i].value,
                       properties[i].valueSize );
        if (hr != S_OK)
        {
            free_msg( msg );
            return hr;
        }
    }

    if ((hr = WsCreateHeap( HEAP_MAX_SIZE, 0, NULL, 0, &msg->heap, NULL )) != S_OK)
    {
        free_msg( msg );
        return hr;
    }
    if ((hr = WsCreateXmlBuffer( msg->heap, NULL, 0, &msg->buf, NULL )) != S_OK)
    {
        free_msg( msg );
        return hr;
    }

    UuidCreate( &msg->id );
    msg->version_env  = env_version;
    msg->version_addr = addr_version;

    *handle = (WS_MESSAGE *)msg;
    return S_OK;
}
Exemplo n.º 14
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
 * alloc_msg_queue()									    *
 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
size_t alloc_msg_queue (struct msg_queue *queue, size_t len)
{
    struct msg *mp;
    size_t i;

    init_msg_queue(queue);

    if (!len)
	return 0;

    for (i = 0; i < len; i++) {
	mp = alloc_msg();
	if (mp) 
	    msg_enqueue(queue, mp);
	else
	    break;
    }
    return i;
}
Exemplo n.º 15
0
static void
send_uframe(layer2_t *l2, msg_t *msg, u_char cmd, u_char cr)
{
	u_char tmp[MAX_HEADER_LEN];
	int i;

	i = sethdraddr(l2, tmp, cr);
	tmp[i++] = cmd;
	if (msg)
		msg_trim(msg, 0);
	else if ((msg = alloc_msg(i + mISDNUSER_HEAD_SIZE)))
		msg_reserve(msg, mISDNUSER_HEAD_SIZE);
	else {
		dprint(DBGM_L2, l2->nst->cardnr,"%s: can't alloc msguff\n", __FUNCTION__);
		return;
	}
	memcpy(msg_put(msg, i), tmp, i);
	msg_push(msg, mISDNUSER_HEAD_SIZE);
	enqueue_super(l2, msg);
}
Exemplo n.º 16
0
static int cmd_get_AT(char *data)
{
    MSG_GET_AT_RSP* msg;
    u8 msgLen = 0;
    char buf[MAX_DEBUG_BUF_LEN] = {0};

    snprintf(buf,MAX_DEBUG_BUF_LEN,"%s",data);

    msgLen = sizeof(MSG_GET_HEADER) + strlen(buf) + 1;
    msg = alloc_msg(CMD_GET_AT,msgLen);
    if (!msg)
    {
        LOG_ERROR("alloc LogInfo rsp message failed!");
        return -1;
    }
    msg->managerSeq = get_manager_seq();
    strncpy(msg->data,buf,strlen(buf)+1);
    socket_sendDataDirectly(msg, msgLen);

    return 0;
}
Exemplo n.º 17
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
 * alloc_msg_chain()									    *
 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
size_t alloc_msg_chain( struct msg_queue *queue, size_t len)
{
    struct msg *p_buff;
    size_t i;

    pthread_mutex_lock(&heap_msg_mutex);

    for ( i = 0; i <= len -1; i++ ) {
	p_buff = alloc_msg();
	if ( p_buff != NULL ) {
	    p_buff->p_next = NULL;
	    p_buff->mb.mbp = NULL;
	    msg_enqueue(queue, p_buff);
	}
	else
	    break;
    }
    
    pthread_mutex_unlock(&heap_msg_mutex);
    return i;
}
Exemplo n.º 18
0
void
enquiry_cr(layer2_t *l2, u_char typ, u_char cr, u_char pf)
{
	msg_t *msg;
	u_char tmp[MAX_HEADER_LEN];
	int i;

	i = sethdraddr(l2, tmp, cr);
	if (test_bit(FLG_MOD128, &l2->flag)) {
		tmp[i++] = typ;
		tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0);
	} else
		tmp[i++] = (l2->vr << 5) | typ | (pf ? 0x10 : 0);
	if (!(msg = alloc_msg(i + mISDNUSER_HEAD_SIZE))) {
		dprint(DBGM_L2, l2->nst->cardnr, "isdnl2 can't alloc sbbuff for enquiry_cr\n");
		return;
	} else
		msg_reserve(msg, mISDNUSER_HEAD_SIZE);
	memcpy(msg_put(msg, i), tmp, i);
	msg_push(msg, mISDNUSER_HEAD_SIZE);
	enqueue_super(l2, msg);
}
Exemplo n.º 19
0
int set_errno(int no, const char * msg) {
    errno = no;
    if (no != 0 && msg != NULL) {
        ErrorMessage * m = alloc_msg(SRC_MESSAGE);
        /* alloc_msg() assigns new value to 'errno',
         * need to be sure it does not change until this function exits.
         */
        int err = errno;
        m->error = get_error_code(no);
        if (no == ERR_OTHER) {
            m->text = loc_strdup(msg);
        }
        else {
            size_t msg_len = strlen(msg);
            if (msg_len == 0) {
                m->text = loc_strdup(errno_to_str(no));
            }
            else {
                const char * text0 = tmp_strdup(msg);
                const char * text1 = errno_to_str(no);
                if (text0[msg_len - 1] == '.' || text0[msg_len - 1] == '\n') {
                    size_t len = msg_len + strlen(text1) + 2;
                    char * text2 = (char *)loc_alloc(len);
                    snprintf(text2, len, "%s %s", text0, text1);
                    m->text = text2;
                }
                else {
                    size_t len = msg_len + strlen(text1) + 3;
                    char * text2 = (char *)loc_alloc(len);
                    snprintf(text2, len, "%s. %s", text0, text1);
                    m->text = text2;
                }
            }
        }
        errno = err;
    }
    return errno;
}
Exemplo n.º 20
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
 * alloc_mbuff_chain()									    *
 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
size_t alloc_mbuff_chain( struct msg_queue *queue, size_t len)
{
    struct msg	 *p_buff;
    struct mbuff *m_buff;
    size_t i;
    /*
     * 1- Block mutex msg
     * 2- Block mutex mbuff
     * 3- Create n mbuff elements
     * 4- Create n pkbuff elements
     * 5- Unblock mutex mbuff
     * 6- Unblock mutex msg
     */
    pthread_mutex_lock(&heap_msg_mutex);
    pthread_mutex_lock(&heap_mbuff_mutex);

    for ( i = 0; i <= len-1 ; i++ ) {
	m_buff = alloc_mbuff();
	if (m_buff != NULL) {
	    p_buff = alloc_msg();
	    if (p_buff != NULL) {
		p_buff->p_next = NULL;
	        p_buff->mb.mbp = m_buff;
		msg_enqueue(queue, p_buff);
	    }
	    else {
		free_mbuff(m_buff);
		break;
	    }
	}
	else
	    break;
    }
    pthread_mutex_unlock(&heap_mbuff_mutex);
    pthread_mutex_unlock(&heap_msg_mutex);

    return i;
}
Exemplo n.º 21
0
static void sendGPS2Server(LOCAL_GPS* gps)
{

    if (gps->isGps)
    {
        cmd_GPS(&gps->gps);
    }
#if 0
    else
    {
        size_t msgLen = sizeof(MSG_HEADER) + sizeof(CGI) + sizeof(CELL) * gps->cellInfo.cellNo;
        MSG_HEADER* msg = alloc_msg(CMD_CELL, msgLen);
        CGI* cgi = (CGI*)(msg + 1);
        CELL* cell = (CELL*)(cgi + 1);
        int i = 0;
        if (!msg)
        {
            LOG_ERROR("alloc CELL message failed!");
            return;
        }

        cgi->mcc = htons(gps->cellInfo.mcc);
        cgi->mnc = htons(gps->cellInfo.mnc);
        cgi->cellNo = gps->cellInfo.cellNo;
        for (i = 0; i < gps->cellInfo.cellNo; i++)
        {
            cell[i].lac = htons(gps->cellInfo.cell[i].lac);
            cell[i].cellid = htons(gps->cellInfo.cell[i].cellid);
            cell[i].rxl= htons(gps->cellInfo.cell[i].rxl);
        }

        LOG_DEBUG("send CELL message.");
        socket_sendDataDirectly(msg, msgLen);

        data.isCellGet = EAT_FALSE;
    }
#endif
}