void set(iXY map_loc, int ID, int type)
 {
     this->map_loc_x = htol32(map_loc.x);
     this->map_loc_y = htol32(map_loc.y);
     this->ID = htol32(ID);
     this->type = htol32(type);
 }
 SystemSetPlayerView(Sint32 x, Sint32 y)
 {
     message_class = _net_message_class_system;
     message_id = _net_message_id_system_set_view;
     camera_loc_x = htol32(x);
     camera_loc_y = htol32(y);
 }
 void set(iXY map_loc, PowerUpID ID, int type)
 {
     this->map_loc_x = htol32(map_loc.x);
     this->map_loc_y = htol32(map_loc.y);
     this->ID = PowerUpID_toPortable(ID); // XXX protocol
     this->type = htol32(type);
 }
 void setManualFire(const iXY& target)
 {
     message_id = _umesg_ai_command;
     command = _command_manual_fire;
     target_loc_x = htol32(target.x);
     target_loc_y = htol32(target.y);
     manual_move_orientation = 0;
 }
 void setMoveToLoc(const iXY& goal)
 {
     message_id = _umesg_ai_command;
     command = _command_move_to_loc;
     goal_loc_x = htol32(goal.x);
     goal_loc_y = htol32(goal.y);
     manual_move_orientation = 0;
 }
 UnitRemoteCreate(PlayerID player_id, UnitID id,
         Uint32 x, Uint32 y, Uint8 type)
 {
     message_class = _net_message_class_unit;
     message_id = _net_message_id_create_unit;
     this->player_id = player_id;
     new_unit_id = htol16(id);
     location_x = htol32(x);
     location_y = htol32(y);
     unit_type = type;
 }
Пример #7
0
/* Return a CDC type buffer */
int
remote_CDC_rx(void *wl, rem_ioctl_t *rem_ptr, uchar *readbuf, uint buflen, int debug)
{
	uint numread = 0;

#ifdef RWL_SOCKET
	int ret;
#endif

#ifdef RWL_WIFI
	UNUSED_PARAMETER(wl);
	UNUSED_PARAMETER(readbuf);
	UNUSED_PARAMETER(numread);
#endif /* RWL_WIFI */
	UNUSED_PARAMETER(buflen);
	UNUSED_PARAMETER(debug);
	UNUSED_PARAMETER(numread);

	if (rem_ptr->data_len > rem_ptr->msg.len) {
		DPRINT_ERR(ERR, "remote_CDC_rx: remote data len (%d) > msg len (%d)\n",
			rem_ptr->data_len, rem_ptr->msg.len);
		return (FAIL);
	}


#if defined(RWL_DONGLE) || defined(RWL_SERIAL)
	if ((remote_type == REMOTE_DONGLE) || (remote_type == REMOTE_SERIAL)) {
		if (rwl_read_serial_port(wl, (char*)readbuf, rem_ptr->data_len,
			&numread) < 0) {
			DPRINT_ERR(ERR, "remote_CDC_rx_hdr: Data Receivefailed \n");
			return (FAIL);
		}
	}
#endif /* RWL_DONGLE || RWL_SERIAL */

#ifdef RWL_SOCKET
	if (remote_type == REMOTE_SOCKET) {
		if (((ret = rwl_receive_from_streamsocket(*(int*)wl, (char*)readbuf,
		rem_ptr->data_len, 0)) == -1)) {
				DPRINT_ERR(ERR, "remote_CDC_rx:Data Receive failed\n");
				return (FAIL);
		}
	}
#endif /* RWL_SOCKET */
	return (SUCCESS);
}
#ifdef RWL_SOCKET
int
rwl_sockconnect(int SockDes, struct sockaddr *servAddr, int size)
{
	DPRINT_DBG(OUTPUT, "sockconnet SockDes=%d\n", SockDes);
	if (rwl_connectsocket(SockDes, servAddr, size) < 0) {
			DPRINT_ERR(ERR, "\n Server is not running\n");
			return FAIL;
	}
	return SUCCESS;
}
#endif /* RWL_SOCKET */
void
rwl_swap_header(rem_ioctl_t *rem_ptr, bool host_to_network)
{
	rem_ptr->msg.cmd = host_to_network?(htol32(rem_ptr->msg.cmd)):(ltoh32(rem_ptr->msg.cmd));
	rem_ptr->msg.len = host_to_network?(htol32(rem_ptr->msg.len)):(ltoh32(rem_ptr->msg.len));
	rem_ptr->msg.flags = host_to_network?(htol32(rem_ptr->msg.flags)):
		(ltoh32(rem_ptr->msg.flags));
	rem_ptr->msg.status = host_to_network?(htol32(rem_ptr->msg.status)):
		(ltoh32(rem_ptr->msg.status));
	rem_ptr->data_len = host_to_network?(htol32(rem_ptr->data_len)):(ltoh32(rem_ptr->data_len));
}
 UnitIniSyncMessage(Uint8 unit_type, PlayerID player_id, UnitID unit_id,
     Uint32 location_x, Uint32 location_y)
 {
     message_class = _net_message_class_unit;
     message_id = _net_message_id_ini_sync_mesg;
     this->unit_type = unit_type;
     //this->player_id = htol16(player_id);
     this->player_id = player_id;
     this->unit_id = htol16(unit_id);
     this->location_x = htol32(location_x);
     this->location_y = htol32(location_y);
 }
Пример #9
0
int
dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len)
{
	dhd_prot_t *prot = dhd->prot;
	cdc_ioctl_t *msg = &prot->msg;
	int ret = 0;
	uint32 flags, id;

	DHD_TRACE(("%s: Enter\n", __FUNCTION__));
	DHD_CTL(("%s: cmd %d len %d\n", __FUNCTION__, cmd, len));

	if (prot == 0) {
		DHD_ERROR(("dhdcdc_set_ioctl: dhd->prot NULL. idx=%d, cmd=0x%x", ifidx, cmd));
		goto done;
	}
	memset(msg, 0, sizeof(cdc_ioctl_t));

	msg->cmd = htol32(cmd);
	msg->len = htol32(len);
	msg->flags = (++prot->reqid << CDCF_IOC_ID_SHIFT) | CDCF_IOC_SET;
	CDC_SET_IF_IDX(msg, ifidx);
	msg->flags |= htol32(msg->flags);

	if (buf)
		memcpy(prot->buf, buf, len);

	if ((ret = dhdcdc_msg(dhd)) < 0)
		goto done;

	if ((ret = dhdcdc_cmplt(dhd, prot->reqid, len)) < 0)
		goto done;

	flags = ltoh32(msg->flags);
	id = (flags & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT;

	if (id != prot->reqid) {
		DHD_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
		           dhd_ifname(dhd, ifidx), __FUNCTION__, id, prot->reqid));
		ret = -EINVAL;
		goto done;
	}

	/* Check the ERROR flag */
	if (flags & CDCF_IOC_ERROR)
	{
		ret = ltoh32(msg->status);
		/* Cache error from dongle */
		dhd->dongle_error = ret;
	}

done:
	return ret;
}
Пример #10
0
/* Regenerate NVRAM. Should be locked. */
int _nvram_commit(struct nvram_header *header)
{
//      char *init, *config, *refresh, *ncdl;
	char *ptr, *end;
	int i;
	struct nvram_tuple *t;
	struct nvram_header tmp;
	uint8 crc;

	/* Regenerate header */
	header->magic = NVRAM_MAGIC;
	header->crc_ver_init = NVRAM_DEFAULT << NVRAM_OPT_SHIFT | NVRAM_VERSION << NVRAM_VER_SHIFT;

	/* Clear data area */
	ptr = (char *)header + sizeof(struct nvram_header);
	bzero(ptr, NVRAM_SPACE - sizeof(struct nvram_header));

	/* Leave space for a double NUL at the end */
	end = (char *)header + NVRAM_SPACE - 2;

	/* Write out all tuples */
	for (i = 0; i < ARRAYSIZE(nvram_hash); i++) {
		for (t = nvram_hash[i]; t; t = t->next) {
			if ((ptr + strlen(t->name) + 1 + strlen(t->value) + 1) > end)
				break;
			ptr += sprintf(ptr, "%s=%s", t->name, t->value) + 1;
		}
	}

	/* End with a double NUL */
	ptr += 2;

	/* Set new length */
	header->len = ROUNDUP(ptr - (char *)header, 4);

	/* Little-endian CRC8 over the last 11 bytes of the header */
	tmp.crc_ver_init = htol32(header->crc_ver_init);
	tmp.config_refresh = htol32(header->config_refresh);
	tmp.config_ncdl = htol32(header->config_ncdl);
	crc = crc8((char *)&tmp + 12, sizeof(struct nvram_header) - 12, CRC8_INIT_VALUE);

	/* Continue CRC8 over data bytes */
	crc = crc8((char *)&header[1], header->len - sizeof(struct nvram_header), crc);

	/* Set new CRC8 */
	header->crc_ver_init |= crc;

	/* Reinitialize hash table */
	return nvram_rehash(header);
}
Пример #11
0
NetworkUnitState UnitState::getNetworkUnitState() const
{
    NetworkUnitState state;

    state.unit_type = unit_type;
    state.location_x = htol32(location.x);
    state.location_y = htol32(location.y);
    state.bbox_min_x = htol32(bbox.min.x);
    state.bbox_min_y = htol32(bbox.min.y);
    state.bbox_max_x = htol32(bbox.max.x);
    state.bbox_max_y = htol32(bbox.max.y);

    state.body_angle = body_angle.getNetworkAngleInt();
    state.turret_angle = turret_angle.getNetworkAngleInt();
    state.orientation = htol16(orientation);
    state.speed_rate = htol16(speed_rate);
    state.speed_factor = htol16(speed_factor);
    
    state.reload_time = htol16(reload_time);
    state.max_hit_points = htol16(max_hit_points);
    state.hit_points = htol16(hit_points);
    state.damage_factor = htol16(damage_factor);
    state.weapon_range = htol32(weapon_range);
    state.defend_range = htol32(defend_range);
    
    state.threat_level = threat_level;
    state.lifecycle_state = lifecycle_state;

    return state;
}
Пример #12
0
void cfe_update(const char *keyword, const char *value)
{
        unsigned long i, offset;
        struct nvram_header tmp, *header;
        uint8 crc;
//        int ret;
        int found = 0;

        if(!cfe_buf||!cfe_mtd)
                cfe_init();

        if (!cfe_buf||!cfe_mtd) return;

        header = cfe_nvram_header;

        printk("before: %x %x\n", header->len,  cfe_nvram_header->crc_ver_init&0xff); 

        for(i=CFE_NVRAM_START;i<=CFE_NVRAM_END;i++)
        {
                if(strncmp(&cfe_buf[i], keyword, strlen(keyword))==0)
                {
                        printk("before: %s\n", cfe_buf+i); 
                        offset=strlen(keyword);
                        memcpy(cfe_buf+i+offset+1, value, strlen(value));
                        printk("after: %s\n", cfe_buf+i); 
                        found = 1;
                }
        }

        if(!found)
        {
                char *tmp_buf = (char *)cfe_nvram_header;

                /* printk("header len: %x\n", header->len); */
                sprintf(tmp_buf+header->len, "%s=%s", keyword, value);
                header->len = header->len + strlen(keyword) + strlen(value) + 2;
                /* printk("header len: %x\n", header->len); */
        }

        tmp.crc_ver_init = htol32(header->crc_ver_init);
        tmp.config_refresh = htol32(header->config_refresh);
        tmp.config_ncdl = htol32(header->config_ncdl);
        crc = hndcrc8((char *) &tmp + 9, sizeof(struct nvram_header) - 9, CRC8_INIT_VALUE);

        /* Continue CRC8 over data bytes */
        crc = hndcrc8((char *) &header[1], header->len - sizeof(struct nvram_header), crc);
        header->crc_ver_init = (header->crc_ver_init&0xFFFFFF00)|crc;
        printk("after: %x %x\n", header->crc_ver_init&0xFF, crc); 
}
Пример #13
0
wwd_result_t wwd_bus_write_wifi_nvram_image( void )
{
    uint32_t varsize, varaddr, ramsz, phys_size, varsizew;
    uint32_t wlan_mem_start_addr;

    /* RAM size is 512K */
    ramsz = RAM_SZ;
    wlan_mem_start_addr = 0x680000;
    varsize = ROUNDUP(sizeof(wifi_nvram_image), 4);

    varaddr = (ramsz - 4) - varsize;

    varaddr += wlan_mem_start_addr;

    /* write Vars into WLAN RAM */
    memcpy((uint8_t *)varaddr, wifi_nvram_image, varsize);

    phys_size = ramsz;

    phys_size += wlan_mem_start_addr;

    varsize = ((phys_size - 4) - varaddr);
    varsizew = varsize / 4;
    varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF);
    varsizew = htol32(varsizew);
    memcpy((uint8_t *)(phys_size - 4), (uint8_t*)&varsizew, 4);

    return WWD_SUCCESS;
}
Пример #14
0
int
BCMINITFN(nvram_commit_internal)(bool nvram_corrupt)
{
	struct nvram_header *header;
	int ret;
	uint32 *src, *dst;
	uint i;

	if (!(header = (struct nvram_header *) MALLOC(NULL, MAX_NVRAM_SPACE))) {
		printf("nvram_commit: out of memory\n");
		return -12; /* -ENOMEM */
	}

	NVRAM_LOCK();

	/* Regenerate NVRAM */
	ret = _nvram_commit(header);
	if (ret)
		goto done;

	src = (uint32 *) &header[1];
	dst = src;

	for (i = sizeof(struct nvram_header); i < header->len && i < MAX_NVRAM_SPACE; i += 4)
		*dst++ = htol32(*src++);

#ifdef _CFE_
	if ((ret = cfe_open(flashdrv_nvram)) >= 0) {
		if (nvram_corrupt) {
			printf("Corrupting NVRAM...\n");
			header->magic = NVRAM_INVALID_MAGIC;
		}
		cfe_writeblk(ret, 0, (unsigned char *) header, header->len);
		cfe_close(ret);
	}
#else
	if (sysFlashInit(NULL) == 0) {
		/* set/write invalid MAGIC # (in case writing image fails/is interrupted)
		 * write the NVRAM image to flash(with invalid magic)
		 * set/write valid MAGIC #
		 */
		header->magic = NVRAM_CLEAR_MAGIC;
		nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic));

		header->magic = NVRAM_INVALID_MAGIC;
		nvWrite((unsigned short *) header, MAX_NVRAM_SPACE);

		header->magic = NVRAM_MAGIC;
		nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic));
	}
#endif /* ifdef _CFE_ */

done:
	NVRAM_UNLOCK();
	MFREE(NULL, header, MAX_NVRAM_SPACE);
	return ret;
}
Пример #15
0
static void
bcm_rpc_tp_tx_encap(rpc_tp_info_t * rpcb, rpc_buf_t *b)
{
	uint32 *tp_lenp;
	uint32 rpc_len;

	rpc_len = pkttotlen(rpcb->osh, b);
	tp_lenp = (uint32*)bcm_rpc_buf_push(rpcb, b, BCM_RPC_TP_ENCAP_LEN);
	*tp_lenp = htol32(rpc_len);
}
Пример #16
0
/* returns the CRC8 of the nvram */
uint8
BCMINITFN(nvram_calc_crc)(struct nvram_header *nvh)
{
	struct nvram_header tmp;
	uint8 crc;

	/* Little-endian CRC8 over the last 11 bytes of the header */
	tmp.crc_ver_init = htol32((nvh->crc_ver_init & NVRAM_CRC_VER_MASK));
	tmp.config_refresh = htol32(nvh->config_refresh);
	tmp.config_ncdl = htol32(nvh->config_ncdl);

	crc = hndcrc8((uint8 *) &tmp + NVRAM_CRC_START_POSITION,
		sizeof(struct nvram_header) - NVRAM_CRC_START_POSITION,
		CRC8_INIT_VALUE);

	/* Continue CRC8 over data bytes */
	crc = hndcrc8((uint8 *) &nvh[1], nvh->len - sizeof(struct nvram_header), crc);

	return crc;
}
Пример #17
0
int
bcm_xdr_pack_uint32(bcm_xdr_buf_t *b, uint32 val)
{
	if (b->size < 4)
		return -1;

	*(uint32*)(b->buf) = htol32((uint32)val);
	b->size -= 4;
	b->buf += 4;

	return 0;
}
Пример #18
0
static int
dhdusb_downloadvars(usb_info_t *bus, void *arg, int len)
{
    int bcmerror = 0;
    uint32 varsize;
    uint32 varaddr;
    uint32 varsizew;

    if (!len) {
        bcmerror = BCME_BUFTOOSHORT;
        goto err;
    }

    /* RAM size is not set. Set it at dbus_usb_dlneeded */
    if (!bus->rdlram_size)
        bcmerror = BCME_ERROR;

    /* Even if there are no vars are to be written, we still need to set the ramsize. */
    varsize = len ? ROUNDUP(len, 4) : 0;
    varaddr = (bus->rdlram_size - 4) - varsize;

    /* Write the vars list */
    DBUSTRACE(("WriteVars: @%x varsize=%d\n", varaddr, varsize));
    bcmerror = dbus_write_membytes(bus->usbosl_info, TRUE, (varaddr + bus->rdlram_size),
                                   arg, varsize);

    /* adjust to the user specified RAM */
    DBUSTRACE(("Usable memory size: %d\n", bus->rdlram_size));
    DBUSTRACE(("Vars are at %d, orig varsize is %d\n", varaddr, varsize));

    varsize = ((bus->rdlram_size - 4) - varaddr);

    /*
     * Determine the length token:
     * Varsize, converted to words, in lower 16-bits, checksum in upper 16-bits.
     */
    if (bcmerror) {
        varsizew = 0;
    } else {
        varsizew = varsize / 4;
        varsizew = (~varsizew << 16) | (varsizew & 0x0000FFFF);
        varsizew = htol32(varsizew);
    }

    DBUSTRACE(("New varsize is %d, length token=0x%08x\n", varsize, varsizew));

    /* Write the length token to the last word */
    bcmerror = dbus_write_membytes(bus->usbosl_info, TRUE, ((bus->rdlram_size - 4) +
                                   bus->rdlram_size), (uint8*)&varsizew, 4);
err:
    return bcmerror;
}
Пример #19
0
static void
bcm_rpc_tp_buf_pad(rpc_tp_info_t * rpcb, rpc_buf_t *bb, uint padbytes)
{
	uint32 *tp_lenp = (uint32 *)bcm_rpc_buf_data(rpcb, bb);
	uint32 tp_len = ltoh32(*tp_lenp);
	uint32 pktlen = bcm_rpc_buf_len_get(rpcb, bb);
	ASSERT(tp_len + BCM_RPC_TP_ENCAP_LEN == pktlen);

	tp_len += padbytes;
	pktlen += padbytes;
	*tp_lenp = htol32(tp_len);
	bcm_rpc_buf_len_set(rpcb, bb, pktlen);
}
Пример #20
0
int
nvram_commit(void)
{
    struct nvram_header *header;
    int ret;
    uint32 *src, *dst;
    uint i;
    uint32 err_addr;
    
    if (!(header = (struct nvram_header *) MALLOC(NULL, NVRAM_SPACE))) {
        printf("nvram_commit: out of memory\n");
        return -12;
    }
    
    NVRAM_LOCK();
    ret = _nvram_commit(header);
    
    if (ret)
        goto done;
    
    src = (uint32 *) &header[1];
    dst = src;
    
    for (i = sizeof(struct nvram_header); i < header->len && i < NVRAM_SPACE;
         i += 4)
        *dst++ = htol32(*src++);
    
    
    if (sysFlashInit(NULL) == 0) {
        /* set/write invalid MAGIC # (in case writing image fails/is interrupted)
         * write the NVRAM image to flash(with invalid magic)
         * set/write valid MAGIC #
         */
        header->magic = NVRAM_CLEAR_MAGIC;
        nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic));
        
        header->magic = NVRAM_INVALID_MAGIC;
        nvWrite((unsigned short *) header, NVRAM_SPACE);
        
        header->magic = NVRAM_MAGIC;
        nvWriteChars((unsigned char *)&header->magic, sizeof(header->magic));
    }
    
done:
    NVRAM_UNLOCK();
    MFREE(NULL, header, NVRAM_SPACE);
    return ret;
}
Пример #21
0
NetworkPlayerState PlayerState::getNetworkPlayerState() const
{
    NetworkPlayerState state;

    memset(state.name, 0, sizeof(state.name));
    strncpy(state.name, name.c_str(), sizeof(state.name)-1);
    state.flag = flag;
    state.playerindex_id = htol16(player_index);
    state.status = status;
    state.kills = htol16(kills);
    state.kill_points = htol16(kill_points);
    state.losses = htol16(losses);
    state.loss_points = htol16(loss_points);
    state.total = htol16(total);
    state.objectives_held = htol16(objectives_held);
    state.colorIndex = htol32(colorIndex);
    
    return state;
}
Пример #22
0
/* Pack 32-bit vectors */
int
bcm_xdr_pack_uint32_vec(bcm_xdr_buf_t *b, uint len, void *vec)
{
	int i;
	uint32	*vec32 = (uint32*)vec, *buf32 = (uint32*)b->buf;
	ASSERT((len % sizeof(uint32)) == 0);

	if (b->size < len)
		return -1;

	/* Do the 32 bit swap and copy */
	for (i = 0; i < (int)(len/sizeof(uint32)); i++)
		buf32[i] = htol32(vec32[i]);

	b->size -= len;
	b->buf += len;

	return 0;
}
Пример #23
0
int
nvram_commit(void)
{
	struct nvram_header *header;
	int ret;
	uint32 *src, *dst;
	uint i;

	if (!(header = (struct nvram_header *) MALLOC(NVRAM_SPACE))) {
		printf("nvram_commit: out of memory\n");
		return -12; /* -ENOMEM */
	}

	NVRAM_LOCK();

	/* Regenerate NVRAM */
	ret = _nvram_commit(header);
	if (ret)
		goto done;
	
	src = (uint32 *) &header[1];
	dst = src;

	for (i = sizeof(struct nvram_header); i < header->len && i < NVRAM_SPACE; i += 4)
		*dst++ = htol32(*src++);
#ifdef ASUS
#else
#ifdef _CFE_
	if ((ret = cfe_open("flash0.nvram")) >= 0) {
		cfe_writeblk(ret, 0, (unsigned char *) header, NVRAM_SPACE);
		cfe_close(ret);
	}
#else
	if (flash_init((void *) FLASH_BASE, NULL) == 0)
		nvWrite((unsigned short *) header, NVRAM_SPACE);
#endif
#endif

 done:
	NVRAM_UNLOCK();
	MFREE(header, NVRAM_SPACE);
	return ret;
}
void ConnectMesgServerGameSettings::setTimeLimit(Sint32 timeLimit)
{
    time_limit = htol32(timeLimit);
}
void ConnectMesgServerGameSettings::setElapsedTime(time_t elapsedTime)
{
    elapsed_time = (time_t)htol32((Uint32)elapsedTime);
}
void ClientConnectJoinRequest::setProtocolVersion(Uint32 version)
{
    protocol_version = htol32(version);
}
void ClientConnectJoinRequestAck::setResultCode(Sint32 result)
{
    result_code = htol32(result);
}
void ClientConnectJoinRequestAck::setServerProtocolVersion(Uint32 protocol_version)
{
    server_protocol_version = htol32(protocol_version);
}
void ConnectProcessUpdate::setQueuePosition(Uint32 position)
{
    queue_position = htol32(position);
}
void ConnectProcessStateMessage::setMessageEnum(Uint32 message)
{
    message_enum = htol32(message);
}