sock_result_t socket_create_tcp_server(uint16_t port, network_interface_t nif) { socket_t* socket = new socket_t(); tcp_server_t* server = new tcp_server_t(); wiced_result_t result = WICED_OUT_OF_HEAP_SPACE; if (socket && server) { result = wiced_tcp_server_start(server, wiced_wlan_interface(nif), port, WICED_MAXIMUM_NUMBER_OF_SERVER_SOCKETS, server_connected, server_received, server_disconnected, NULL); } if (result!=WICED_SUCCESS) { if (socket) { delete socket; socket = NULL; } if (server) { server->close(); delete server; server = NULL; } } else { socket->set_server(server); SocketListLock lock(list_for(socket)); add_socket(socket); } return socket ? as_sock_result(socket) : as_sock_result(result); }
static void tcp_server_thread_main(uint32_t arg) { wiced_result_t result; // 5 Connections maximum at a time platform_dct_security_t* dct_security = NULL; wiced_tls_identity_t tls_identity; #if 0 wiced_tcp_server_start(&tcp_server,INTERFACE,TCP_SERVER_LISTEN_PORT,5, client_connected_callback, received_data_callback, client_disconnected_callback, NULL ); /* Lock the DCT to allow us to access the certificate and key */ WPRINT_APP_INFO(( "Read the certificate Key from DCT\n" )); result = wiced_dct_read_lock( (void**) &dct_security, WICED_FALSE, DCT_SECURITY_SECTION, 0, sizeof( *dct_security ) ); if ( result != WICED_SUCCESS ) { WPRINT_APP_INFO(("Unable to lock DCT to read certificate\n")); return; } /* Setup TLS identity */ result = wiced_tls_init_identity( &tls_identity, dct_security->private_key, strlen( dct_security->private_key ), (uint8_t*) dct_security->certificate, strlen( dct_security->certificate ) ); if ( result != WICED_SUCCESS ) { WPRINT_APP_INFO(( "Unable to initialize TLS identity. Error = [%d]\n", result )); return; } else WPRINT_APP_INFO(("Init identity succeeded\n")); result = wiced_tcp_server_enable_tls (&tcp_server, &tls_identity); if(result != WICED_SUCCESS) { WPRINT_APP_INFO(( "Failed to enable TLS. Error = [%d]\n", result )); return; } else WPRINT_APP_INFO(("Enable TLS succeeded\n")); #endif WPRINT_APP_INFO(("IP\t\tPort\tC\tDEVICE\tREGID\tVALUE\tDBSIZE\n")); WPRINT_APP_INFO(("----------------------------------------------------------------------\n")); char receiveChar; uint32_t expected_data_size=1; while(1) { wiced_uart_receive_bytes( STDIO_UART, &receiveChar, &expected_data_size, WICED_NEVER_TIMEOUT ); switch(receiveChar) { case 'p': printStatus(); break; case '?': WPRINT_APP_INFO(("p: print status of server sockets\n")); break; } } }