Beispiel #1
0
void arp_get_ip(struct net_device *ndev)
{
	printk("Using ARP to find IP address!\n");
	struct arp_packet *arp = malloc(60);
	arp->hlen = 6;
	arp->plen = 4;
	arp->htype = __swap16(0x01);
	arp->ptype = __swap16(0x0800);

	arp->opcode = __swap16(0x0001);

	uint8_t mac[6];
	net_query_mac(mac);
	arp->srchw[0] = mac[5];
	arp->srchw[1] = mac[4];
	arp->srchw[2] = mac[3];
	arp->srchw[3] = mac[2];
	arp->srchw[4] = mac[1];
	arp->srchw[5] = mac[0];
	memset(arp->srcpr, 0, arp->plen);
	memset(arp->dstpr, 0, arp->plen);
	memset(arp->dsthw, 0, arp->hlen);

	struct packet pk = {
		.len = 60,
		.payload = arp,
	};

	ndev->send_packet(ndev, &pk);

	free(arp);
}
Beispiel #2
0
static void susb_issue_call(struct aura_node *node, struct aura_buffer *buf)
{
	struct aura_object *o = buf->object;
	struct usb_dev_info *inf = aura_get_transportdata(node);
	uint8_t rqtype;
	uint16_t wIndex, wValue, *ptr;
	size_t datalen; /*Actual data in packet, save for setup */

	if (o->retlen) {
		rqtype = LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN;
		datalen = o->retlen;
	} else {
		datalen = o->arglen - 2 * sizeof(uint16_t);
		rqtype = LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT;
	}
	ptr = (uint16_t *)&buf->data[buf->pos];
	wValue = *ptr++;
	wIndex = *ptr++;

	memmove(&buf->data[buf->pos], ptr, datalen);

	/*
	 * VUSB-based devices (or libusb?) do not seem to play nicely when we have the
	 * setup packet with no data. Transfers may fail instantly.
	 * A typical run at my box gives:
	 *
	 * 9122 succeeded, 878 failed total 10000
	 *
	 * See tests-transports/test-susb-stability-none
	 * Adding just one byte of data to the packet fix the issue.
	 * Posible workarounds are:
	 * 1. Retry N times
	 * 2. Add just one dummy byte for the transfer
	 * Since nobody reported this workaround breaking support for their
	 * hardware - we'll do it the second way. For now.
	 */

	if (!datalen)
		datalen++; /* buffer's big enough anyway */

	/* e.g if device is big endian, but has le descriptors
	 * we have to be extra careful here
	 */

	if (node->need_endian_swap) {
		wValue = __swap16(wValue);
		wIndex = __swap16(wValue);
	}

	inf->current_buffer = buf;
	libusb_fill_control_setup((unsigned char *)buf->data, rqtype, o->id, wValue, wIndex,
				  datalen);
	libusb_fill_control_transfer(inf->ctransfer, inf->handle,
				     (unsigned char *)buf->data, cb_call_done, node, 4000);
	inf->control_retry_count = 0;
	submit_control(node);
}
Beispiel #3
0
int urpc_unpack_u16(lua_State *L, uint16_t* src, int swap)
{
	uint16_t tmp;
	if (swap)
		tmp = __swap16(*src);
	else
		tmp = *src;
	lua_pushnumber(L, tmp);
	return 1;
}
Beispiel #4
0
/*----------------*/
int main(int argc, char *argv[])
{
    APP_STATUS status;

    srvInit();
    aptInit(APPID_APPLICATION);
    gfxInit();
    hidInit(NULL);
    fsInit();

    svcCreateEvent(&new_cmd_event, 0);
    svcCreateEvent(&cmd_done_event, 0);
    svcCreateThread(&thread, cmd_thread_func, 0x0,
                    (u32*)((char*)thread_stack + sizeof(thread_stack)),
                    0x31, 0xfffffffe);

    int where = 0;
    u32 ret = SOC_Initialize((u32*)0x08000000, 0x48000);

    if(ret == 0) {
        listen_socket = socket(AF_INET, SOCK_STREAM, 0);
        if(listen_socket == -1) {
            where = 1;
            ret = SOC_GetErrno();
        }
        else {
            u32 tmp = fcntl(listen_socket, F_GETFL);
            fcntl(listen_socket, F_SETFL, tmp | O_NONBLOCK);

            struct sockaddr_in addr;
            addr.sin_family = AF_INET;
            addr.sin_port = __swap16(PORT);
            addr.sin_addr.s_addr = INADDR_ANY;

            ret = bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr));
            if(ret != 0) {
                where = 2;
                ret = SOC_GetErrno();
            }
            else {
                ret = listen(listen_socket, 1);
                if(ret == -1) {
                    ret = SOC_GetErrno();
                    where = 3;
                }
            }
        }

    }

    u32 it = 0;
    int accept_errno = 0;
    int first = 1;


    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&top);

        print(&top, "newver\n");
        print(&top, "ret: %08x, where: %d\n", ret, where);
        print(&top, "frame: %08x\n", it);
        u32 ip = gethostid();
        print(&top, "ip: %d.%d.%d.%d\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
                
        if(accept_errno != 0) print(&top, "accept returned errno %d\n", accept_errno);

        if(!first) {
            int s = accept(listen_socket, NULL, NULL);
            if(s == -1) {
                int err = SOC_GetErrno();

                if(err != -EWOULDBLOCK)
                    accept_errno = err;
            }
            else {
                sock = s;
                conn_main();
                closesocket(sock);
            }
        }

        it++;
        first = 0;
        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A)
            break;
    }

    thread_exit = 1;
    svcSignalEvent(new_cmd_event);
    svcWaitSynchronization(thread, U64_MAX);
    svcCloseHandle(thread);

    svcCloseHandle(new_cmd_event);
    svcCloseHandle(cmd_done_event);

    SOC_Shutdown();
    fsExit();
    hidExit();
    gfxExit();
    aptExit();
    srvExit();
    return 0;
}