예제 #1
0
/**
 * Create a new socket handle.
 * @param family    Must be {@code AF_INET}
 * @param type      Either SOCK_DGRAM or SOCK_STREAM
 * @param protocol  Either IPPROTO_UDP or IPPROTO_TCP
 * @return
 */
sock_handle_t socket_create(uint8_t family, uint8_t type, uint8_t protocol, uint16_t port, network_interface_t nif)
{
    if (family!=AF_INET || !((type==SOCK_DGRAM && protocol==IPPROTO_UDP) || (type==SOCK_STREAM && protocol==IPPROTO_TCP)))
        return SOCKET_INVALID;

    sock_handle_t result = SOCKET_INVALID;
    socket_t* socket = new socket_t();
    if (socket) {
        wiced_result_t wiced_result;
        socket->set_type((protocol==IPPROTO_UDP ? socket_t::UDP : socket_t::TCP));
        if (protocol==IPPROTO_TCP) {
            wiced_result = wiced_tcp_create_socket(tcp(socket), wiced_wlan_interface(nif));
        }
        else {
            wiced_result = wiced_udp_create_socket(udp(socket), port, wiced_wlan_interface(nif));
        }
        if (wiced_result!=WICED_SUCCESS) {
            socket->set_type(socket_t::NONE);
            delete socket;
            result = as_sock_result(wiced_result);
        }
        else {
            SocketListLock lock(list_for(socket));
            add_socket(socket);
            result = as_sock_result(socket);
        }
    }
    return result;
}
예제 #2
0
wiced_result_t wiced_start_dhcp_server(wiced_dhcp_server_t* server, wiced_interface_t interface)
{
    DHCP_CHECK_PARAMS( (server == NULL) || ( (interface != WICED_STA_INTERFACE) && (interface != WICED_AP_INTERFACE) && (interface != WICED_P2P_INTERFACE) && (interface != WICED_CONFIG_INTERFACE) ), WICED_BADARG );

    server->interface = interface;

    /* Clear cache */
    memset( cached_mac_addresses, 0, sizeof( cached_mac_addresses ) );
    memset( cached_ip_addresses,  0, sizeof( cached_ip_addresses  ) );

    /* Create DHCP socket */
    WICED_VERIFY(wiced_udp_create_socket(&server->socket, IPPORT_DHCPS, interface));

    /* Start DHCP server */
    wiced_rtos_create_thread(&server->thread, DHCP_THREAD_PRIORITY, "DHCPserver", dhcp_thread, DHCP_STACK_SIZE, server);
    return WICED_SUCCESS;
}
예제 #3
0
/*
 * Function:    wilddog_openSocket
 * Description: wilddog openSocket function, it use the interface in wiced platform.
 * Input:        N/A
 * Output:      socketId: The pointer of socket id.
 * Return:      If success, return 0; else return -1.
*/
int wilddog_openSocket( int* socketId )
{
    wiced_udp_socket_t* socket = NULL;

    socket = wmalloc( sizeof(wiced_udp_socket_t) );
    if ( NULL == socket )
    {
        printf( "%s malloc error!\n", __func__ );
        return -1;
    }
    if ( wiced_udp_create_socket( socket, WICED_ANY_PORT, WICED_STA_INTERFACE ) != WICED_SUCCESS )
    {
        return -1;
    }
    *socketId = (int) socket;

    return 0;
}
예제 #4
0
파일: ws2812.c 프로젝트: Daedaluz/ws2812
void application_start(void)
{
    wiced_interface_t interface;
    wiced_result_t result;
	int fail = 0;
    wiced_init( );
	command_console_init(STDIO_UART, 300, cmdline, 10, history, " ");
	console_add_cmd_table(commands);
	memset(write_buffer, 0, BUFFER_SIZE);
	ws2812_init();
	write_ws2812(0, 3, init_data);
	wiced_network_register_link_callback(link_cb_up, link_cb_down, WICED_STA_INTERFACE);
    result = wiced_network_up_default( &interface, NULL);
//	result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);

    if( result != WICED_SUCCESS ) {
        printf("Bringing up network interface failed !\r\n");
		fail = 1;
    }

    /* Create UDP socket */
    if (wiced_udp_create_socket(&udp_socket, PORTNUM, interface) != WICED_SUCCESS) {
        WPRINT_APP_INFO( ("UDP socket creation failed\n") );
		fail = 1;
    } else {
	//	wiced_udp_register_callbacks(&udp_socket, udp_cb, &udp_socket);
		wiced_rtos_register_timed_event( &process_udp_rx_event, WICED_NETWORKING_WORKER_THREAD, &process_received_udp_packet, (1*SECONDS)/50, 0 );
	}
	if(!fail){
		init_data[0] = 0x10;
		init_data[1] = 0x00;
		init_data[2] = 0x00;
	} else {
		init_data[0] = 0x00;
		init_data[1] = 0x10;
		init_data[2] = 0x00;
	}
	write_ws2812(0, 3, init_data);
}