Beispiel #1
0
int check_uCimage (uCimage_header *header, FILE *handle)
{
	int i;

	/* Check magic in header */
	for (i=0;i<sizeof(header->magic);i++) {
		if (header->magic[i] != UCHEADER_MAGIC[i]) {
			if (opt_debug)
				fprintf (stderr, "Header magic[%d] not: \"%s\" instead: \"%s\"\n",
					 i, UCHEADER_MAGIC, header->magic);
			fprintf (stderr, "uCimage header not detected.\n");
			rewind (handle);
			return (1); /* header not found */
		}
	}

	header_present = 1;

	/* TODO: check reported header size, seek to data */

	/* Convert from little-endian to host byte order *in place*
	 * in the header: */

	header->header_size = ltoh32(header->header_size);
	DBG ("header_size reported as: %10d\n", header->header_size);

	/* image size: */
	header->data_size   = ltoh32(header->data_size);
	fprintf (stdout, "data_size reported as:   %10d\n", header->data_size);

	/* header date code */
	fprintf (stdout, "date code reported as:    \"%s\"\n", header->datecode);

	/* header name */
	fprintf (stdout, "name reported as:         \"%s\"\n", header->name);

	/* MD5: */
	fprintf (stdout, "MD5 digest reported as:   ");
	for (i=0;i<16;i++)
		fprintf (stdout, "%02x", header->md5sum[i]);
	fprintf (stdout, "\n");

#if 0
	/* read image and do MD5: */
	while (!feof(infile)) {
		n = fread (buf, 1, BUFFERSIZE, infile);
		size += n;
		MD5Update (&md5c, buf, n);
	}
	/* save MD5: */
	MD5Final (digest, &md5c);
#endif

	return (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));
}
Beispiel #3
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;
}
Beispiel #4
0
image_texture* image_totexture(uint8_t* data)
{
	bmpfile_header* header = (void*)data + 2;
	bmpfile_infoheader* infoheader = (void*)data + 14;
	uint8_t* bmpdata = data + ltoh32(header->bmp_offset), * flipped;
	image_texture* ret = malloc(sizeof(image_texture));
	long i, width, height;
	
	if (data[0] != 'B' || data[1] != 'M')
		return 0;
	
	width = ltoh32(infoheader->width);
	height = ltoh32(infoheader->height);
	
	if (ltoh32(infoheader->header_sz) < 40 || ltoh16(infoheader->nplanes) > 1 || ltoh16(infoheader->bitspp) != 32 || ltoh32(infoheader->compress_type) != 0
		|| !width || height <= 0)
		return 0;
	
	glGenTextures(1, &ret->texture);
	glBindTexture(GL_TEXTURE_2D, ret->texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	
	if (width > 0)
	{
		unsigned long pitch = width * 4;
		
		flipped = malloc(height * pitch);
		for (i = height * pitch - pitch; i >= 0; i -= pitch, bmpdata += pitch)
			memcpy(flipped + i, bmpdata, pitch);
	}
	
	ret->refs = 1;
	ret->width = width;
	ret->height = height;
	ret->texwidth = width;
	ret->texheight = height;
	ret->ratx = 1.0;
	ret->raty = 1.0;
	
	if (width > 0)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, 4, ret->texwidth, ret->texheight, 0, GL_BGRA, GL_UNSIGNED_BYTE, flipped);
		free(flipped);
	}
	else
		glTexImage2D(GL_TEXTURE_2D, 0, 4, ret->texwidth, ret->texheight, 0, GL_BGRA, GL_UNSIGNED_BYTE, bmpdata);
	
	return ret;
}
void UnitState::setFromNetworkUnitState(const NetworkUnitState& state)
{
    select = false;

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

    body_angle.setFromNetworkAngleInt(state.body_angle);
    turret_angle.setFromNetworkAngleInt(state.turret_angle);

    orientation = ltoh16(state.orientation);
    speed_rate = ltoh16(state.speed_rate);
    speed_factor = ltoh16(state.speed_factor);
    
    reload_time = ltoh16(state.reload_time);
    max_hit_points = ltoh16(state.max_hit_points);
    hit_points = ltoh16(state.hit_points);
    damage_factor = ltoh16(state.damage_factor);
    weapon_range = ltoh32(state.weapon_range);
    defend_range = ltoh32(state.defend_range);

    threat_level = state.threat_level;
    lifecycle_state = state.lifecycle_state;
}
static int
dbus_usb_dlrun(void *bus)
{
    usb_info_t *usbinfo = BUS_INFO(bus, usb_info_t);
    void *osinfo;
    rdl_state_t state;
    int err = DBUS_OK;

    DBUSTRACE(("%s\n", __FUNCTION__));

    if (usbinfo == NULL)
        return DBUS_ERR;

    if (USB_DEV_ISBAD(usbinfo))
        return DBUS_ERR;

    osinfo = usbinfo->usbosl_info;
    ASSERT(osinfo);

    /* Check we are runnable */
    dbus_usbos_dl_cmd(osinfo, DL_GETSTATE, &state, sizeof(rdl_state_t));

    state.state = ltoh32(state.state);
    state.bytes = ltoh32(state.bytes);

    /* Start the image */
    if (state.state == DL_RUNNABLE) {
        DBUSTRACE(("%s: Issue DL_GO\n", __FUNCTION__));
        dbus_usbos_dl_cmd(osinfo, DL_GO, &state, sizeof(rdl_state_t));

        /* FIX: Need this for 4326 for some reason
         * Same issue under both Linux/Windows
         */
        if (usbinfo->pub->attrib.devid == TEST_CHIP)
            dbus_usbos_wait(osinfo, USB_DLGO_SPINWAIT);

        dbus_usb_resetcfg(usbinfo);
        /* The Donlge may go for re-enumeration. */
    } else {
        DBUSERR(("%s: Dongle not runnable\n", __FUNCTION__));
        err = DBUS_ERR;
    }

    return err;
}
static bool
dbus_usb_dlneeded(void *bus)
{
    usb_info_t *usbinfo = BUS_INFO(bus, usb_info_t);
    void *osinfo;
    bootrom_id_t id;
    bool dl_needed = TRUE;

    DBUSTRACE(("%s\n", __FUNCTION__));

    if (usbinfo == NULL)
        return FALSE;

    osinfo = usbinfo->usbosl_info;
    ASSERT(osinfo);

    /* Check if firmware downloaded already by querying runtime ID */
    id.chip = 0xDEAD;
    dbus_usbos_dl_cmd(osinfo, DL_GETVER, &id, sizeof(bootrom_id_t));

    id.chip = ltoh32(id.chip);
    id.chiprev = ltoh32(id.chiprev);

    if (FALSE == dbus_usb_update_chipinfo(usbinfo, id.chip)) {
        dl_needed = FALSE;
        goto exit;
    }

    DBUSERR(("%s: chip 0x%x rev 0x%x\n", __FUNCTION__, id.chip, id.chiprev));
    if (id.chip == POSTBOOT_ID) {
        /* This code is  needed to support two enumerations on USB1.1 scenario */
        DBUSERR(("%s: Firmware already downloaded\n", __FUNCTION__));

        dbus_usbos_dl_cmd(osinfo, DL_RESETCFG, &id, sizeof(bootrom_id_t));
        dl_needed = FALSE;
        if (usbinfo->pub->busstate == DBUS_STATE_DL_PENDING)
            usbinfo->pub->busstate = DBUS_STATE_DL_DONE;
    } else {
        usbinfo->pub->attrib.devid = id.chip;
        usbinfo->pub->attrib.chiprev = id.chiprev;
    }

exit:
    return dl_needed;
}
Beispiel #8
0
int
bcm_xdr_unpack_uint32(bcm_xdr_buf_t *b, uint32 *pval)
{
	if (b->size < 4)
		return -1;

	*pval = ltoh32(*(uint32*)(b->buf));

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

	return 0;
}
Beispiel #9
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);
}
static int
dbus_usb_rdl_dwnld_state(usb_info_t *usbinfo)
{
    void *osinfo = usbinfo->usbosl_info;
    rdl_state_t state;
    int err = DBUS_OK;

    /* 1) Prepare USB boot loader for runtime image */
    dbus_usbos_dl_cmd(osinfo, DL_START, &state, sizeof(rdl_state_t));

    state.state = ltoh32(state.state);
    state.bytes = ltoh32(state.bytes);

    /* 2) Check we are in the Waiting state */
    if (state.state != DL_WAITING) {
        DBUSERR(("%s: Failed to DL_START\n", __FUNCTION__));
        err = DBUS_ERR;
        goto fail;
    }

fail:
    return err;
}
Beispiel #11
0
/* Unpack 32-bit vectors */
int
bcm_xdr_unpack_uint32_vec(bcm_xdr_buf_t *b, uint len, void *vec)
{
	int err = 0, i;
	uint32	*vec32 = (uint32*)vec;
	ASSERT((len % sizeof(uint32)) == 0);

	err = bcm_xdr_unpack_opaque_cpy(b, len, vec);

	/* Do the 32 bit swapping in the copied buffer */
	for (i = 0; i < (int)(len/sizeof(uint32)); i++)
		vec32[i] = ltoh32(vec32[i]);

	return err;
}
Beispiel #12
0
static int
dhdcdc_cmplt(dhd_pub_t *dhd, uint32 id, uint32 len)
{
	int ret;
	dhd_prot_t *prot = dhd->prot;

	DHD_TRACE(("%s: Enter\n", __FUNCTION__));

	do {
		ret = dhd_bus_rxctl(dhd->bus, (uchar*)&prot->msg, len+sizeof(cdc_ioctl_t));
		if (ret < 0)
			break;
	} while (CDC_IOC_ID(ltoh32(prot->msg.flags)) != id);

	return ret;
}
static int
dbus_usb_resetcfg(usb_info_t *usbinfo)
{
    void *osinfo;
    bootrom_id_t id;
    uint16 wait = 0, wait_time;

    DBUSTRACE(("%s\n", __FUNCTION__));

    if (usbinfo == NULL)
        return DBUS_ERR;

    osinfo = usbinfo->usbosl_info;
    ASSERT(osinfo);

    /* Give dongle chance to boot */
    wait_time = USB_SFLASH_DLIMAGE_SPINWAIT;
    while (wait < USB_SFLASH_DLIMAGE_LIMIT) {
        dbus_usbos_wait(osinfo, wait_time);

        wait += wait_time;

        id.chip = 0xDEAD;       /* Get the ID */
        dbus_usbos_dl_cmd(osinfo, DL_GETVER, &id, sizeof(bootrom_id_t));
        id.chip = ltoh32(id.chip);

        if (id.chip == POSTBOOT_ID)
            break;
    }

    if (id.chip == POSTBOOT_ID) {
        DBUSERR(("%s: download done %d ms postboot chip 0x%x/rev 0x%x\n",
                 __FUNCTION__, wait, id.chip, id.chiprev));

        dbus_usbos_dl_cmd(osinfo, DL_RESETCFG, &id, sizeof(bootrom_id_t));

        dbus_usbos_wait(osinfo, USB_RESETCFG_SPINWAIT);
        return DBUS_OK;
    } else {
        DBUSERR(("%s: Cannot talk to Dongle. Firmware is not UP, %d ms \n",
                 __FUNCTION__, wait));
        return DBUS_ERR;
    }

    return DBUS_OK;
}
Beispiel #14
0
static int
dhdcdc_msg(dhd_pub_t *dhd)
{
	dhd_prot_t *prot = dhd->prot;
	int len = ltoh32(prot->msg.len) + sizeof(cdc_ioctl_t);

	DHD_TRACE(("%s: Enter\n", __FUNCTION__));

	/* NOTE : cdc->msg.len holds the desired length of the buffer to be
	 *        returned. Only up to CDC_MAX_MSG_SIZE of this buffer area
	 *	  is actually sent to the dongle
	 */
	if (len > CDC_MAX_MSG_SIZE)
		len = CDC_MAX_MSG_SIZE;

	/* Send request */
	return dhd_bus_txctl(dhd->bus, (uchar*)&prot->msg, len);
}
Beispiel #15
0
int
_nvram_read(void *buf)
{
	uint32 *src, *dst;
	uint i;

	if (!nvram_header)
		return -19; /* -ENODEV */

	src = (uint32 *) nvram_header;
	dst = (uint32 *) buf;

	for (i = 0; i < sizeof(struct nvram_header); i += 4)
		*dst++ = *src++;

	for (; i < nvram_header->len && i < NVRAM_SPACE; i += 4)
		*dst++ = ltoh32(*src++);

	return 0;
}
void PlayerState::setFromNetworkPlayerState(const NetworkPlayerState* state)
{
    char tmp[64];
    memcpy(tmp, state->name, 64); 
    tmp[63] = 0;
    name = tmp;
    flag = state->flag;
    if ( ! ResourceManager::isFlagActive(flag) ) 
    {
        LOGGER.warning("Received flag is not registered: %u", flag);
    }
    
    player_index = ltoh16(state->playerindex_id);
    status = state->status;
    kills = ltoh16(state->kills);
    kill_points = ltoh16(state->kill_points);
    losses = ltoh16(state->losses);
    loss_points = ltoh16(state->loss_points);
    total = ltoh16(state->total);
    objectives_held = ltoh16(state->objectives_held);
    setColor(ltoh32(state->colorIndex));
}
Beispiel #17
0
/* buffer length (n) specified in bytes */
void
BCMROMFN(tkip_mic)(uint32 k0, uint32 k1, int n, uint8 *m, uint32 *left, uint32 *right)
{
	uint32 l = k0;
	uint32 r = k1;

	if (((uintptr)m & 3) == 0) {
		for (; n > 0; n -= 4) {
			l ^= ltoh32(*(uint *)m);
			m += 4;
			tkip_micblock(&l, &r);
		}
	} else {
		for (; n > 0; n -= 4) {
			l ^= ltoh32_ua(m);
			m += 4;
			tkip_micblock(&l, &r);
		}
	}
	*left = l;
	*right = r;
}
Beispiel #18
0
int _nvram_read(void *buf)
{
    volatile uint32 *src, *dst;
    uint i;
    
    src = (uint32 *) nvram_header;
    dst = (uint32 *) buf;
    
    printf ("_nvram_read: source address is 0x%x 0x%x\n", src, dst);
    
    NVRAM_LOCK();
    for (i=0; i< sizeof(struct nvram_header); i +=4) {
        *dst++ = *src++;
    }
    
    for (;i < nvram_header->len && i < NVRAM_SPACE; i+= 4)
        *dst++ = ltoh32(*src++);
    
    NVRAM_UNLOCK();
    
    return 0;
}
Beispiel #19
0
static int
sb_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
{
	pci_config_regs *cfg;

	if (dev >= SB_MAXCORES || (off + len) > sizeof(pci_config_regs))
		return -1;
	cfg = &sb_config_regs[dev];

	ASSERT(ISALIGNED(off, len));
	ASSERT(ISALIGNED((uintptr)buf, len));

	if (len == 4)
		*((uint32 *) buf) = ltoh32(*((uint32 *)((ulong) cfg + off)));
	else if (len == 2)
		*((uint16 *) buf) = ltoh16(*((uint16 *)((ulong) cfg + off)));
	else if (len == 1)
		*((uint8 *) buf) = *((uint8 *)((ulong) cfg + off));
	else
		return -1;

	return 0;
}
Uint32 ClientConnectJoinRequestAck::getServerProtocolVersion() const
{
    return ltoh32(server_protocol_version);
}
Uint32 ConnectProcessStateMessage::getMessageEnum() const
{
    return ltoh32(message_enum);
}
Beispiel #22
0
void __init
prom_init(void)
{
    unsigned long extmem = 0, off, data;
    static unsigned long mem;
    unsigned long off1, data1;
    struct nvram_header *header;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
    /* These are not really being used anywhere - LR */
    mips_machgroup = MACH_GROUP_BRCM;
    mips_machtype = MACH_BCM947XX;
#endif

    off = (unsigned long)prom_init;
    data = *(unsigned long *)prom_init;
    off1 = off + 4;
    data1 = *(unsigned long *)off1;

    /* Figure out memory size by finding aliases */
    for (mem = (1 MB); mem < (128 MB); mem <<= 1) {
        if ((*(unsigned long *)(off + mem) == data) &&
                (*(unsigned long *)(off1 + mem) == data1))
            break;
    }
    detectmem = mem;
#if 0// defined(CONFIG_HIGHMEM) && !defined(CONFIG_BCM80211AC)
    if (mem == 128 MB) {

        early_tlb_init();
        /* Add one temporary TLB entries to map SDRAM Region 2.
        *      Physical        Virtual
        *      0x80000000      0xc0000000      (1st: 256MB)
        *      0x90000000      0xd0000000      (2nd: 256MB)
        */
        add_tmptlb_entry(ENTRYLO(SI_SDRAM_R2),
                         ENTRYLO(SI_SDRAM_R2 + (256 MB)),
                         EXTVBASE, PM_256M);

        off = EXTVBASE + __pa(off);
        for (extmem = (128 MB); extmem < (512 MB); extmem <<= 1) {
            if (*(unsigned long *)(off + extmem) == data)
                break;
        }

        extmem -= mem;
        /* Keep tlb entries back in consistent state */
        early_tlb_init();
    }
#endif  /* CONFIG_HIGHMEM */
    /* Ignoring the last page when ddr size is 128M. Cached
     * accesses to last page is causing the processor to prefetch
     * using address above 128M stepping out of the ddr address
     * space.
     */
    if (MIPS74K(current_cpu_data.processor_id) && (mem == (128 MB)))
        mem -= 0x1000;

    /* CFE could have loaded nvram during netboot
     * to top 32KB of RAM, Just check for nvram signature
     * and copy it to nvram space embedded in linux
     * image for later use by nvram driver.
     */
    header = (struct nvram_header *)(KSEG0ADDR(mem - NVRAM_SPACE));
    if (ltoh32(header->magic) == NVRAM_MAGIC) {
        uint32 *src = (uint32 *)header;
        uint32 *dst = (uint32 *)ram_nvram_buf;
        uint32 i;

        printk("Copying NVRAM bytes: %d from: 0x%p To: 0x%p\n", ltoh32(header->len),
               src, dst);
        for (i = 0; i < ltoh32(header->len) && i < NVRAM_SPACE; i += 4)
            *dst++ = ltoh32(*src++);
    }

    add_memory_region(SI_SDRAM_BASE, mem, BOOT_MEM_RAM);

#if 0// defined(CONFIG_HIGHMEM) && !defined(CONFIG_BCM80211AC)
    if (extmem) {
        /* We should deduct 0x1000 from the second memory
         * region, because of the fact that processor does prefetch.
         * Now that we are deducting a page from second memory
         * region, we could add the earlier deducted 4KB (from first bank)
         * to the second region (the fact that 0x80000000 -> 0x88000000
         * shadows 0x0 -> 0x8000000)
         */
        if (MIPS74K(current_cpu_data.processor_id) && (mem == (128 MB)))
            extmem -= 0x1000;
        add_memory_region(SI_SDRAM_R2 + (128 MB) - 0x1000, extmem, BOOT_MEM_RAM);
    }
#endif  /* CONFIG_HIGHMEM */
}
Uint32 ConnectProcessUpdate::getQueuePosition() const
{
    return ltoh32(queue_position);
}
 Sint32 getCameraLocX() const
 {
     return ltoh32(camera_loc_x);
 }
 Sint32 getCameraLocY() const
 {
     return ltoh32(camera_loc_y);
 }
static int
remote_CDC_tx_dongle(void *wl, rem_ioctl_t *rem_ptr, uchar *buf)
{
	unsigned long numwritten;
	char end_of_packet[END_OF_PACK_SEP_LEN] = "\n\n";
	uchar loc_buf[UART_FIFO_LEN];
	uint len = END_OF_PACK_SEP_LEN;
	uint noframes, frame_count, rem_bytes;
	uint n_bytes;
	uint data_len;

	/* Converting the CDC header with keyword 'rwl ' in ascii format
	 * as dongle UART understands only ascii format.
	 * In dongle UART driver CDC structure is made from the ascii data
	 * it received.
	 */
	sprintf((char*)loc_buf, "rwl %d %d %d %d ", rem_ptr->msg.cmd, rem_ptr->msg.len,
		rem_ptr->msg.flags, rem_ptr->data_len);
	n_bytes = strlen((char*)loc_buf);

	data_len = ltoh32(rem_ptr->data_len);
	DPRINT_DBG(OUTPUT, "rwl %x %d %d %d ", ltoh32(rem_ptr->msg.cmd), ltoh32(rem_ptr->msg.len),
		ltoh32(rem_ptr->msg.flags), data_len);
	DPRINT_DBG(OUTPUT, "CDC Header:No of bytes to be sent=%d\n", n_bytes);
	DPRINT_DBG(OUTPUT, "Data:No of bytes to be sent=%d\n", data_len);

	/* Send the CDC Header */
	if (rwl_write_serial_port(wl, (char*)loc_buf, n_bytes, &numwritten) < 0) {
		DPRINT_ERR(ERR, "CDC_Tx: Header: Write failed\n");
		DPRINT_ERR(ERR, "CDC_Tx: Header: numwritten %ld != n_bytes %d\n",
			numwritten, n_bytes);
		return (FAIL);
	}

	/* Dongle UART FIFO len is 64 bytes and flow control is absent.
	 * While transmitting large chunk of data the data was getting lost
	 * at UART driver so for large chunk of data 64 bytes are sent at a time
	 * folowed by delay and then next set of 64 bytes and so on.
	 * For data which is less than 64 bytes it is sent in one shot
	 */

	noframes = rem_ptr->data_len/UART_FIFO_LEN;
	if (noframes == 0) {
		/* Send the data now */
		if (rwl_write_serial_port(wl, (char*)buf, rem_ptr->data_len, &numwritten) < 0) {
			DPRINT_ERR(ERR, "Data_Tx: Header: Write failed\n");
			DPRINT_ERR(ERR, "Data_Tx: Header: numwritten %ld != len %d\n",
			numwritten, rem_ptr->data_len);
			return (FAIL);
		}

	} else {
		if (rem_ptr->data_len % UART_FIFO_LEN == 0) {
			rem_bytes = UART_FIFO_LEN;
		} else {
			rem_bytes = rem_ptr->data_len % UART_FIFO_LEN;
			noframes += 1;
		}

		for (frame_count = 0; frame_count < noframes; frame_count++) {
			if (frame_count != noframes-1) {
				memcpy(loc_buf, (char*)(&buf[frame_count*UART_FIFO_LEN]),
				UART_FIFO_LEN);
				/* Send the data now */
				if (rwl_write_serial_port(wl, (char*)loc_buf, UART_FIFO_LEN,
				&numwritten) == -1) {
					DPRINT_ERR(ERR, "Data_Tx: Header: Write failed\n");
					return (-1);
				}

			} else {
				memcpy(loc_buf, (char*)(&buf[frame_count*UART_FIFO_LEN]),
				rem_bytes);

				if (rwl_write_serial_port(wl, (char*)loc_buf, rem_bytes,
				&numwritten) == -1) {
					DPRINT_ERR(ERR, "Data_Tx: Header: Write failed\n");
					return (-1);
				}

			}
			rwl_sleep(SYNC_TIME);
		}
	}

	/* Send end of packet now */
	if (rwl_write_serial_port(wl, end_of_packet, len, &numwritten) == -1) {
		DPRINT_ERR(ERR, "CDC_Tx: Header: Write failed\n");
		DPRINT_ERR(ERR, "CDC_Tx: Header: numwritten %ld != len %d\n",
			numwritten, len);
		return (FAIL);
	}

	DPRINT_DBG(OUTPUT, "Packet sent!\n");

	/* Return size of actual buffer to satisfy accounting going on above this level */
	return (ltoh32(rem_ptr->msg.len));
}
 Uint32 getLocY() const
 {
     return ltoh32(location_y);
 }
 Uint32 getLocX() const
 {
     return ltoh32(location_x);
 }
Beispiel #29
0
/* Probe for NVRAM header */
static int
early_nvram_init(void)
{
	struct nvram_header *header;
	chipcregs_t *cc;
	int i;
	uint32 base, off, lim;
	u32 *src, *dst;
	uint32 fltype;
	char *nvram_space_str;
#ifdef NFLASH_SUPPORT
	hndnand_t *nfl_info = NULL;
	uint32 blocksize;
#endif
	hndsflash_t *sfl_info = NULL;

	header = (struct nvram_header *)ram_nvram_buf;
	if (header->magic == NVRAM_MAGIC) {
		if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) {
			nvram_inram = TRUE;
			goto found;
		}
	}

	if ((cc = si_setcore(sih, CC_CORE_ID, 0)) != NULL) {
#ifdef NFLASH_SUPPORT
		if ((sih->ccrev == 38) && ((sih->chipst & (1 << 4)) != 0)) {
			fltype = NFLASH;
			base = KSEG1ADDR(SI_FLASH1);
		} else
#endif
		{
			fltype = readl(&cc->capabilities) & CC_CAP_FLASH_MASK;
			base = KSEG1ADDR(SI_FLASH2);
		}
		switch (fltype) {
		case PFLASH:
			lim = SI_FLASH2_SZ;
			break;

		case SFLASH_ST:
		case SFLASH_AT:
			if ((sfl_info = hndsflash_init(sih)) == NULL)
				return -1;
			lim = sfl_info->size;
			break;
#ifdef NFLASH_SUPPORT
		case NFLASH:
			if ((nfl_info = hndnand_init(sih)) == NULL)
				return -1;
			lim = SI_FLASH1_SZ;
			break;
#endif
		case FLASH_NONE:
		default:
			return -1;
		}
	} else {
		/* extif assumed, Stop at 4 MB */
		base = KSEG1ADDR(SI_FLASH1);
		lim = SI_FLASH1_SZ;
	}
#ifdef NFLASH_SUPPORT
	if (nfl_info != NULL) {
		blocksize = nfl_info->blocksize;
		off = blocksize;
		for (; off < NFL_BOOT_SIZE; off += blocksize) {
			if (hndnand_checkbadb(nfl_info, off) != 0)
				continue;
			header = (struct nvram_header *) KSEG1ADDR(base + off);
			if (header->magic != NVRAM_MAGIC)
				continue;

			/* Read into the nand_nvram */
			if ((header = nand_find_nvram(nfl_info, off)) == NULL)
				continue;
			if (nvram_calc_crc(header) == (uint8)header->crc_ver_init)
				goto found;
		}
	} else
#endif /* NFLASH_SUPPORT */
	{
		off = FLASH_MIN;

#ifdef RTN66U_NVRAM_64K_SUPPORT
		header = (struct nvram_header *) KSEG1ADDR(base + lim - 0x8000);
		if(header->magic==0xffffffff) {
			header = (struct nvram_header *) KSEG1ADDR(base + 1 KB);
			if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) {
				nvram_32_reset=1;
				goto found;
			}
		}
#endif

		while (off <= lim) {
			/* Windowed flash access */
			header = (struct nvram_header *) KSEG1ADDR(base + off - MAX_NVRAM_SPACE);
			if (header->magic == NVRAM_MAGIC)
				if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) {
					goto found;
				}
			off += DEF_NVRAM_SPACE;
		}
	}

	/* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
	header = (struct nvram_header *) KSEG1ADDR(base + 4 KB);
	if (header->magic == NVRAM_MAGIC)
		if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) {
			goto found;
		}

	header = (struct nvram_header *) KSEG1ADDR(base + 1 KB);
	if (header->magic == NVRAM_MAGIC)
		if (nvram_calc_crc(header) == (uint8) header->crc_ver_init) {
			goto found;
		}

	return -1;

found:
	src = (u32 *) header;
	dst = (u32 *) nvram_buf;
	for (i = 0; i < sizeof(struct nvram_header); i += 4)
		*dst++ = *src++;
	for (; i < header->len && i < MAX_NVRAM_SPACE; i += 4)
		*dst++ = ltoh32(*src++);

	nvram_space_str = early_nvram_get("nvram_space");
	if (nvram_space_str)
		nvram_space = bcm_strtoul(nvram_space_str, NULL, 0);

	return 0;
}
Beispiel #30
0
void
bcm_rpc_tp_rx_from_dnglbus(rpc_tp_info_t *rpc_th, struct lbuf *lb)
{
	void *orig_p, *p;
	void *rpc_p, *rpc_prev;
	uint pktlen, tp_len, iter = 0;
	osl_t *osh;
	bool dbg_agg;
	uint dbg_data[16], i;	/* must fit host agg limit BCM_RPC_TP_HOST_AGG_MAX_SFRAME+1 */

	dbg_agg = FALSE;

	rpc_th->rx_cnt++;

	if (rpc_th->rx_pkt == NULL) {
		RPC_TP_ERR(("%s: no rpc rx fn, dropping\n", __FUNCTION__));
		rpc_th->rxdrop_cnt++;
		lb_free(lb);
		return;
	}
	orig_p = PKTFRMNATIVE(rpc_th->osh, lb);


	osh = rpc_th->osh;

	/* take ownership of the dnglbus packet chain
	 * since it will be freed by bcm_rpc_tp_buf_free()
	 */
	rpc_th->buf_cnt_inuse += pktsegcnt(rpc_th->osh, orig_p);

	dbg_data[0] = pktsegcnt(rpc_th->osh, orig_p);

	pktlen = PKTLEN(osh, orig_p);

	p = orig_p;

	/* while we have more data in the TP frame's packet chain,
	 *   create a packet chain(could be cloned) for the next RPC frame
	 *   then give it away to high layer for process(buffer not freed)
	 */
	while (p != NULL) {
		iter++;

		/* read TP_HDR(len of rpc frame) and pull the data pointer past the length word */
		if (pktlen >= BCM_RPC_TP_ENCAP_LEN) {
			ASSERT(((uint)PKTDATA(osh, p) & 0x3) == 0); /* ensure aligned word read */
			tp_len = ltoh32(*(uint32*)PKTDATA(osh, p));
			PKTPULL(osh, p, BCM_RPC_TP_ENCAP_LEN);
			pktlen -= BCM_RPC_TP_ENCAP_LEN;
		} else {
			/* error case: less data than the encapsulation size
			 * treat as an empty tp buffer, at end of current buffer
			 */
			tp_len = 0;
			pktlen = 0;

			rpc_th->tp_dngl_deagg_cnt_badsflen++;	/* bad sf len */
		}

		/* if TP header finished a buffer(rpc header in next chained buffer), open next */
		if (pktlen == 0) {
			void *next_p = PKTNEXT(osh, p);
			PKTSETNEXT(osh, p, NULL);
			rpc_th->buf_cnt_inuse--;
			PKTFREE(osh, p, FALSE);
			p = next_p;
			if (p)
				pktlen = PKTLEN(osh, p);
		}

		dbg_data[iter] = tp_len;

		if (tp_len < pktlen || dbg_agg) {
			dbg_agg = TRUE;
			RPC_TP_DEAGG(("DEAGG: [%d] p %p data %p pktlen %d tp_len %d\n",
				iter, p, PKTDATA(osh, p), pktlen, tp_len));
			rpc_th->tp_dngl_deagg_cnt_sf++;
			rpc_th->tp_dngl_deagg_cnt_bytes += tp_len;
		}

		/* empty TP buffer (special case: use tp_len to pad for some USB pktsize bugs) */
		if (tp_len == 0) {
			rpc_th->tp_dngl_deagg_cnt_pass++;
			continue;
		} else if (tp_len > 10000 ) {	/* something is wrong */
			/* print out msgs according to value of p  -- in case it is NULL */
			if (p != NULL) {
				RPC_TP_ERR(("DEAGG: iter %d, p(%p data %p pktlen %d)\n",
					iter, p, PKTDATA(osh, p), PKTLEN(osh, p)));
			} else {
				RPC_TP_ERR(("DEAGG: iter %d, p is NULL", iter));
			}
		}

		/* ========= For this TP subframe, find the end, build a chain, sendup ========= */

		/* RPC frame packet chain starts with this packet */
		rpc_prev = NULL;
		rpc_p = p;
		ASSERT(p != NULL);

		/* find the last frag in this rpc chain */
		while ((tp_len >= pktlen) && p) {
			if (dbg_agg)
				RPC_TP_DEAGG(("DEAGG: tp_len %d consumes p(%p pktlen %d)\n", tp_len,
					p, pktlen));
			rpc_prev = p;
			p = PKTNEXT(osh, p);
			tp_len -= pktlen;

			if (p != NULL) {
				pktlen = PKTLEN(osh, p);
			} else {
				if (tp_len != 0) {
					uint totlen, seg;
					totlen = pkttotlen(osh, rpc_p);
					seg = pktsegcnt(rpc_th->osh, rpc_p);

					RPC_TP_ERR(("DEAGG, toss[%d], orig_p %p segcnt %d",
					       iter, orig_p, dbg_data[0]));
					RPC_TP_ERR(("DEAGG,rpc_p %p totlen %d pktl %d tp_len %d\n",
					       rpc_p, totlen, pktlen, tp_len));
					for (i = 1; i <= iter; i++)
						RPC_TP_ERR(("tplen[%d] = %d  ", i, dbg_data[i]));
					RPC_TP_ERR(("\n"));
					p = rpc_p;
					while (p != NULL) {
						RPC_TP_ERR(("this seg len %d\n", PKTLEN(osh, p)));
						p = PKTNEXT(osh, p);
					}

					rpc_th->buf_cnt_inuse -= seg;
					PKTFREE(osh, rpc_p, FALSE);
					rpc_th->tp_dngl_deagg_cnt_badfmt++;

					/* big hammer to recover USB
					 * extern void dngl_reboot(void); dngl_reboot();
					 */
					goto end;
				}
				pktlen = 0;
				break;
			}
		}

		/* fix up the last frag */
		if (tp_len == 0) {
			/* if the whole RPC buffer chain ended at the end of the prev TP buffer,
			 *    end the RPC buffer chain. we are done
			 */
			if (dbg_agg)
				RPC_TP_DEAGG(("DEAGG: END rpc chain p %p len %d\n\n", rpc_prev,
					pktlen));

			PKTSETNEXT(osh, rpc_prev, NULL);
			if (iter > 1) {
				rpc_th->tp_dngl_deagg_cnt_chain++;
				RPC_TP_DEAGG(("this frag %d totlen %d\n", pktlen,
					pkttotlen(osh, orig_p)));
			}

		} else {
			/* if pktlen has more bytes than tp_len, another tp frame must follow
			 *   create a clone of the sub-range of the current TP buffer covered
			 *   by the RPC buffer, attach to the end of the RPC buffer chain
			 *   (cut off the original chain link)
			 *   continue chain looping(p != NULL)
			 */
			void *new_p;
			ASSERT(p != NULL);

			RPC_TP_DEAGG(("DEAGG: cloning %d bytes out of p(%p data %p) len %d\n",
				tp_len, p, PKTDATA(osh, p), pktlen));

			new_p = osl_pktclone(osh, p, 0, tp_len);
			rpc_th->buf_cnt_inuse++;
			rpc_th->tp_dngl_deagg_cnt_clone++;

			RPC_TP_DEAGG(("DEAGG: after clone, newp(%p data %p pktlen %d)\n",
				new_p, PKTDATA(osh, new_p), PKTLEN(osh, new_p)));

			if (rpc_prev) {
				RPC_TP_DEAGG(("DEAGG: chaining: %p->%p(clone)\n", rpc_prev,
					new_p));
				PKTSETNEXT(osh, rpc_prev, new_p);
			} else {
				RPC_TP_DEAGG(("DEAGG: clone %p is a complete rpc pkt\n", new_p));
				rpc_p = new_p;
			}

			PKTPULL(osh, p, tp_len);
			pktlen -= tp_len;
			RPC_TP_DEAGG(("DEAGG: remainder packet p %p data %p pktlen %d\n",
				p, PKTDATA(osh, p), PKTLEN(osh, p)));
		}

		/* !! send up */
		(rpc_th->rx_pkt)(rpc_th->rx_context, rpc_p);
	}

end:
	ASSERT(p == NULL);
}