/* ** Function for starting the HTTP server ** ** IN: ** HTTPSRV_PARAM_STRUCT* params - server parameters (port, ip, index page etc.) ** ** OUT: ** none ** ** Return Value: ** uint32_t server handle if successful, NULL otherwise */ uint32_t HTTPSRV_init(HTTPSRV_PARAM_STRUCT *params) { HTTPSRV_SERVER_TASK_PARAM server_params; server_params.params = params; /* Server must run with lower priority than TCP/IP task. */ if (params->server_prio == 0) { params->server_prio = HTTPSRVCFG_DEF_SERVER_PRIO; } else if (params->server_prio < _RTCSTASK_priority) { return(0); } /* Run server task. */ if (RTCS_task_create(HTTPSRV_SERVER_TASK_NAME, params->server_prio, (params->ssl_params != NULL) ? HTTPSRV_SSL_SERVER_STACK_SIZE : HTTPSRV_SERVER_STACK_SIZE, httpsrv_server_task, &server_params) != RTCS_OK) { HTTPSRV_release(server_params.handle); return(0); } return(server_params.handle); }
/** create httpd server task - poll mode * \param server < pointer to server structure * \return */ static uint_32 httpd_server_task_create(HTTPD_STRUCT *server) { uint_32 stack; HTTPD_ASSERT(server); return RTCS_task_create("httpd server", server->params->server_prio, server->params->server_stack, httpd_server_task, server); }
int_32 Shell_Clock_server_start(int_32 argc, char_ptr argv[] ) { uint_32 result; boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc == 1) { result =RTCS_task_create("Clock_server", SHELL_CLOCK_SERVER_PRIO, SHELL_CLOCK_SERVER_STACK, Clock_server_task, NULL); if (result == 0) { printf("Clock Server Started.\n"); } else { printf("Unable to start Clock Server, error = 0x%x\n",result); return_code = SHELL_EXIT_ERROR; } } else { printf("Error, %s invoked with incorrect number of arguments\n", argv[0]); print_usage = TRUE; } } if (print_usage) { if (shorthelp) { printf("%s \n", argv[0]); } else { printf("Usage: %s\n",argv[0]); } } return return_code; } /* Endbody */
uint_32 DHCPSRV_init ( char_ptr name, uint_32 priority, uint_32 stacksize ) { /* Body */ return RTCS_task_create(name, priority, stacksize, DHCPSRV_task, NULL); } /* Endbody */
uint32_t TFTPSRV_init ( char *name, uint32_t priority, uint32_t stacksize ) { /* Body */ if (TFTPSRV_task_id == 0) { return RTCS_task_create(name, priority, stacksize, TFTPSRV_task, NULL); } else { return RTCSERR_SERVER_ALREADY_RUNNING; } } /* Endbody */
uint32_t SNTP_init ( char *name, uint32_t priority, uint32_t stacksize, _ip_address destination, uint32_t poll ) { /* Body */ struct sntpclnt_init init; init.poll = poll; init.dest = destination; return RTCS_task_create(name, priority, stacksize, SNTP_task, &init); } /* Endbody */
/* ** Detach script processing to separate task ** ** IN: ** HTTPSRV_SESSION_STRUCT* session - session structure pointer. ** HTTPSRV_STRUCT *server - pointer to server structure (needed for session parameters). ** ** OUT: ** none ** ** Return Value: ** none */ void httpsrv_detach_script(HTTPSRV_DET_TASK_PARAM* task_params) { _mqx_uint error; _mqx_uint priority; error = _task_get_priority(MQX_NULL_TASK_ID, &priority); if (error != MQX_OK) { return; } error = RTCS_task_create("httpsrv detached script", priority, task_params->stack_size, httpsrv_detached_task, (void *)task_params); if (error != MQX_OK) { return; } }
/*FUNCTION*------------------------------------------------------------- * * Function Name : PPP_resume * Returned Value : RTCS_OK * Comments : * Resume PPP FSM and open HDLC layer. * *END*-----------------------------------------------------------------*/ uint32_t PPP_resume(_ppp_handle handle) { #if RTCSCFG_ENABLE_IP4 PPP_CFG_PTR ppp_ptr = handle; uint32_t error = RTCS_OK; /* Reopen low-level device */ ppp_ptr->IOPCB_DEVICE = fopen(ppp_ptr->DEVICE_NAME, NULL); /* Open HDLC and resume PPP FSM */ _iopcb_open(ppp_ptr->DEVICE, PPP_lowerup, PPP_lowerdown, ppp_ptr); error = RTCS_task_create("PPP rx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_rx_task, ppp_ptr); return(error); #else return RTCSERR_IP_IS_DISABLED; #endif }
uint32_t DNS_init ( void ) { /* Body */ DNS_CONTROL_STRUCT *control_ptr = RTCS_getcfg(DNS); uint32_t temp_socket = 0; int32_t error; if (control_ptr != NULL) { return RTCS_OK; } /* ** Please note, if this is modified to use a value other than ** DNS_MAX_UDP_MESSAGE_SIZE, the recvfrom() in the DNS_Resolver_task ** will need to be modified as well, as they rely on this constant. */ control_ptr = RTCS_mem_alloc_system_zero(sizeof(DNS_CONTROL_STRUCT)+DNS_MAX_UDP_MESSAGE_SIZE); if (control_ptr == NULL) { return RTCSERR_DNS_UNABLE_TO_ALLOCATE_MEMORY; } /* Endif */ _mem_set_type(control_ptr, MEM_TYPE_DNS_CONTROL_STRUCT); RTCS_setcfg(DNS, control_ptr); temp_socket = socket(PF_INET, SOCK_DGRAM, 0); if (temp_socket == RTCS_HANDLE_ERROR) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_OPEN_SOCKET; } /* Endif */ error = RTCS_detachsock(temp_socket); if (error != RTCS_OK) { DNS_init_unwind(control_ptr, temp_socket); return error; } /* Endif */ control_ptr->INT_QUERY_PARTID = RTCS_part_create( sizeof(DNS_INTERNAL_QUERY_STRUCT), DNSALLOC_SIZE, DNSALLOC_SIZE, 0, NULL, NULL); if (control_ptr->INT_QUERY_PARTID == 0) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_CREATE_PARTITION; } /* Endif */ control_ptr->ADDR_RR_PARTID = RTCS_part_create( sizeof(DNS_ADDR_RECORD_STRUCT), DNSALLOC_SIZE, DNSALLOC_SIZE, 0, NULL, NULL); if (control_ptr->ADDR_RR_PARTID == 0) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_CREATE_PARTITION; } /* Endif */ control_ptr->NAME_RR_PARTID = RTCS_part_create( sizeof(DNS_NAME_RECORD_STRUCT), DNSALLOC_SIZE, DNSALLOC_SIZE, 0, NULL, NULL); if (control_ptr->NAME_RR_PARTID == 0) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_CREATE_PARTITION; } /* Endif */ control_ptr->RR_LIST_PARTID = RTCS_part_create( sizeof(DNS_RR_LIST_STRUCT), DNSALLOC_SIZE, DNSALLOC_SIZE, 0, NULL, NULL); if (control_ptr->RR_LIST_PARTID == 0) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_CREATE_PARTITION; } /* Endif */ control_ptr->CNAME_PARTID = RTCS_part_create( sizeof(DNS_CNAME_STRUCT), DNSALLOC_SIZE, DNSALLOC_SIZE, 0, NULL, NULL); if (control_ptr->CNAME_PARTID == 0) { DNS_init_unwind(control_ptr, temp_socket); return RTCSERR_DNS_UNABLE_TO_CREATE_PARTITION; } /* Endif */ control_ptr->ROOT_SLIST_PTR = DNS_A_Root_server; control_ptr->LOCAL_SLIST_PTR = DNS_First_Local_server; control_ptr->NS_BUFFER = NULL; control_ptr->RES_BUFFER = (unsigned char *)(control_ptr + 1); control_ptr->RES_SOCKET = temp_socket; control_ptr->UPDATING = FALSE; error = RTCS_mutex_init(&control_ptr->CACHE_MUTEX); if (error != RTCS_OK) { DNS_init_unwind(control_ptr, temp_socket); return error; } /* Endif */ error = RTCS_mutex_init(&control_ptr->SLIST_MUTEX); if (error != RTCS_OK) { DNS_init_unwind(control_ptr, temp_socket); return error; } /* Endif */ error = RTCS_task_create("DNS Resolver", _RTCSTASK_priority, _RTCSTASK_stacksize + 500 * sizeof(uint32_t), DNS_Resolver_task, control_ptr); if (error) { DNS_init_unwind(control_ptr, temp_socket); return error; } /* Endif */ return RTCS_OK; } /* Endbody */
static void Clock_server_task ( pointer unused1, pointer unused2 ) { sockaddr_in laddr, raddr={0}; uint_32 sock, listensock; uint_32 error; uint_16 rlen; /* Clock server services port 999 */ laddr.sin_family = AF_INET; laddr.sin_port = 999; laddr.sin_addr.s_addr = INADDR_ANY; /* Listen on TCP port */ listensock= socket(PF_INET, SOCK_STREAM, 0); if (listensock == RTCS_HANDLE_ERROR) { printf("\nCreate stream socket failed"); _task_block(); } error = bind(listensock, &laddr, sizeof(laddr)); if (error != RTCS_OK) { printf("\nStream bind failed - 0x%lx", error); _task_block(); } error = listen(listensock, 0); if (error != RTCS_OK) { printf("\nListen failed - 0x%lx", error); _task_block(); } printf("\nClock Server active on port 999\n"); for (;;) { /* Connection requested; accept it */ rlen = sizeof(raddr); printf("Clock server: Waiting on accept\n"); sock = accept(listensock, &raddr, &rlen); if (sock == RTCS_HANDLE_ERROR) { printf("\n\n*** Clock server: Accept failed, error 0x%lx *** \n\n\n", RTCS_geterror(listensock)); } else { printf("Clock server: Connection from %ld.%ld.%ld.%ld, port %d, socket %x\n", (raddr.sin_addr.s_addr >> 24) & 0xFF, (raddr.sin_addr.s_addr >> 16) & 0xFF, (raddr.sin_addr.s_addr >> 8) & 0xFF, raddr.sin_addr.s_addr & 0xFF, raddr.sin_port, sock); /* Create a task to look after it */ printf("Clock server: detaching socket %x\n",sock); #if USE_RTCS_ATTACH_DETACH RTCS_detachsock(sock); #endif printf("Clock server: spawning child task\n"); #if CREATE_WITH_RTCS RTCS_task_create("Clock_child", SHELL_CLOCK_CHILD_PRIO, SHELL_CLOCK_CHILD_STACK, Clock_child_task, (pointer) sock); #else { TASK_TEMPLATE_STRUCT task_template = {0}; task_template.TASK_NAME = "Clock_child"; task_template.TASK_PRIORITY = SHELL_CLOCK_CHILD_PRIO; task_template.TASK_STACKSIZE = SHELL_CLOCK_CHILD_STACK; task_template.TASK_ADDRESS = Clock_child_task; task_template.CREATION_PARAMETER = (uint_32)sock; if (_task_create(0, 0, (uint_32)&task_template) == MQX_NULL_TASK_ID) { printf("Clock server: failed to spawn child task\n"); } } #endif } } } /* Endbody */
/** server task - httpd main task which create new task for each new request */ static void httpd_server_task(pointer init_ptr, pointer creator) { HTTPD_STRUCT *server = (HTTPD_STRUCT*)init_ptr; int s; unsigned short len; struct sockaddr_in sin; HTTPD_SES_TASK_PARAM *param; _mqx_uint res; uint_32 stack; HTTPD_DEBUG(1, "server task start\n"); res = _lwsem_create(&sem_session_counter, server->params->max_ses); if (!server && res != MQX_OK) goto ERROR; RTCS_task_resume_creator(creator, RTCS_OK); HTTPD_DEBUG(1, "server task run...\n"); while (server->run) { // limit maximal opened sessions _lwsem_wait(&sem_session_counter); // allocate session task parameter structure param = _mem_alloc_system(sizeof(HTTPD_SES_TASK_PARAM)); if (param) { param->server = server; param->sock = accept(server->sock, &sin, &len); if (0 < param->sock) { // accept return corect socket number - no error // try create task for session res = RTCS_task_create("httpd session", server->params->ses_prio, server->params->ses_stack, httpd_session_dynamic_task, param); if (MQX_OK != res) { // session task creation failed, clean and wait... shutdown(param->sock, FLAG_ABORT_CONNECTION); // abort opened connection _mem_free(param); _lwsem_post(&sem_session_counter); _time_delay(1); } } else { // accept return error, clean and wait, then try again... _mem_free(param); _lwsem_post(&sem_session_counter); _time_delay(1); } } else { // allocation failed ?!?!? wait some time _time_delay(100); } } HTTPD_DEBUG(1, "server task stop\n"); ERROR: RTCS_task_resume_creator(creator, (uint_32)RTCS_ERROR); }
void ftpsrv_server_task(void* init_ptr, void* creator) { FTPSRV_STRUCT* server = (FTPSRV_STRUCT*) init_ptr; _mqx_uint res; /* Task init start */ if (server == NULL) { RTCS_task_resume_creator(creator, (uint32_t)RTCS_ERROR); } server->server_tid = _task_get_id(); res = _lwsem_create(&server->ses_cnt, server->params.max_ses); if (res != MQX_OK) { server->server_tid = 0; RTCS_task_resume_creator(creator, (uint32_t)RTCS_ERROR); } RTCS_task_resume_creator(creator, RTCS_OK); /* Task init end */ while (server->run) { uint32_t conn_sock = 0; uint32_t new_sock = 0; _lwsem_wait(&server->ses_cnt); while (!conn_sock && server->run) { conn_sock = RTCS_selectset(&(server->sock_v4), 2, 250); } if (server->run) { unsigned short length = 0; struct sockaddr remote_addr; new_sock = accept(conn_sock, (sockaddr*) &remote_addr, &length); } else { break; } if (new_sock != RTCS_SOCKET_ERROR) { FTPSRV_SESSION_PARAM ses_param; ses_param.sock = new_sock; ses_param.server = server; /* Try to create task for session */ res = RTCS_task_create("ftpsrv session", server->params.server_prio, FTPSRV_SESSION_STACK_SIZE, ftpsrv_session_task, &ses_param); if (MQX_OK != res) { shutdown(new_sock, FLAG_ABORT_CONNECTION); _lwsem_post(&server->ses_cnt); } } else { _lwsem_post(&server->ses_cnt); /* We probably run out of sockets. Wait some arbitrary * time and then try again to prevent session tasks resource starvation. */ _time_delay(150); } } _lwsem_destroy(&server->ses_cnt); server->server_tid = 0; }
uint_32 PPP_initialize ( _iopcb_handle device, /* [IN] - I/O stream to use */ _ppp_handle _PTR_ handle /* [OUT] - the PPP state structure */ ) { /* Body */ #if RTCSCFG_ENABLE_IP4 PPP_CFG_PTR ppp_ptr; uint_32 i, error; /* Allocate the state structure */ ppp_ptr = PPP_memalloc(sizeof(PPP_CFG)); if (!ppp_ptr) { return RTCSERR_PPP_ALLOC_FAILED; } /* Endif */ /* Initialize it */ PPP_memzero(ppp_ptr, sizeof(PPP_CFG)); ppp_ptr->LINK_STATE = FALSE; ppp_ptr->DEVICE = device; for (i = 0; i < PPP_CALL_MAX; i++) { ppp_ptr->LCP_CALL[i].CALLBACK = NULL; ppp_ptr->LCP_CALL[i].PARAM = NULL; } /* Endfor */ ppp_ptr->PROT_CALLS = NULL; ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS; ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS; /* Initialize the lwsem */ if (PPP_mutex_init(&ppp_ptr->MUTEX)) { return RTCSERR_PPP_INIT_MUTEX_FAILED; } /* Endif */ /* Initialize LCP */ error = LCP_init(ppp_ptr); if (error) { PPP_mutex_destroy(&ppp_ptr->MUTEX); return error; } /* Endif */ /* Initialize CCP */ error = CCP_init(ppp_ptr); if (error) { LCP_destroy(ppp_ptr); PPP_mutex_destroy(&ppp_ptr->MUTEX); return error; } /* Endif */ CCP_open(ppp_ptr); /* Create a pool of message buffers */ ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE), PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT); if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID) { CCP_destroy(ppp_ptr); LCP_destroy(ppp_ptr); PPP_mutex_destroy(&ppp_ptr->MUTEX); return RTCSERR_PPP_CREATE_PKT_POOL_FAILED; } /* Endif */ /* Create the Tx Task */ error = RTCS_task_create("PPP tx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_tx_task, ppp_ptr); if (error) { RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); CCP_destroy(ppp_ptr); LCP_destroy(ppp_ptr); PPP_mutex_destroy(&ppp_ptr->MUTEX); return error; } /* Endif */ /* Create the Rx Task */ /* Set task ready for run */ ppp_ptr->STOP_RX = FALSE; error = RTCS_task_create("PPP rx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_rx_task, ppp_ptr); if (error) { RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); CCP_destroy(ppp_ptr); LCP_destroy(ppp_ptr); PPP_mutex_destroy(&ppp_ptr->MUTEX); return error; } /* Endif */ /* Return the handle */ ppp_ptr->VALID = PPP_VALID; *handle = ppp_ptr; return PPP_OK; #else return RTCSERR_IP_IS_DISABLED; #endif /* RTCSCFG_ENABLE_IP4 */ } /* Endbody */
/** create task for session * \param server < pointer to server structure * \param stack < stack size for session task * \return */ static uint_32 httpd_session_static_task_create(HTTPD_STRUCT *server) { return RTCS_task_create("httpd session", 8, server->params->ses_stack, httpd_session_static_task, server); }
_ppp_handle PPP_init ( PPP_PARAM_STRUCT* params ) { /* Body */ #if RTCSCFG_ENABLE_IP4 PPP_CFG_PTR ppp_ptr; uint32_t error; IPCP_DATA_STRUCT ipcp_data; int stage = 0; /* Allocate the state structure */ ppp_ptr = _mem_alloc_zero(sizeof(PPP_CFG)); if (!ppp_ptr) { return(NULL); } ppp_ptr->DEVICE_NAME = _mem_alloc_zero(strlen(params->device)+1); if (ppp_ptr->DEVICE_NAME == NULL) { _mem_free(ppp_ptr); return(NULL); } strcpy(ppp_ptr->DEVICE_NAME, params->device); /* Stage 0 - Open low level device */ ppp_ptr->IOPCB_DEVICE = fopen(params->device, NULL); if (ppp_ptr->IOPCB_DEVICE == NULL) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 1 - Initialize HDLC and lwsem */ ppp_ptr->DEVICE = _iopcb_ppphdlc_init(ppp_ptr->IOPCB_DEVICE); if (ppp_ptr->DEVICE == NULL) { PPP_init_fail(ppp_ptr, stage); return(NULL); } ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS; ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS; if (_lwsem_create(&ppp_ptr->MUTEX, 1)) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 2 - Initialize LCP */ error = LCP_init(ppp_ptr); if (error) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 3 - Initialize and open CCP */ /* error = CCP_init(ppp_ptr); if (error) { PPP_init_fail(ppp_ptr, stage); return error; } CCP_open(ppp_ptr); */ stage++; /* Stage 4 - Create a pool of message buffers */ ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE), PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT); if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 5 - Create the Tx Task */ error = RTCS_task_create("PPP tx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_tx_task, ppp_ptr); if (error) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 6 - Create the Rx Task */ ppp_ptr->STOP_RX = FALSE; error = RTCS_task_create("PPP rx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_rx_task, ppp_ptr); if (error) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 7 - Open HDLC layer */ error = _iopcb_open(ppp_ptr->DEVICE, PPP_lowerup, PPP_lowerdown, ppp_ptr); if (error != PPPHDLC_OK) { PPP_init_fail(ppp_ptr, stage); return(NULL); } ppp_ptr->VALID = PPP_VALID; stage++; /* Stage 8 - Add PPP interface to RTCS */ error = RTCS_if_add(ppp_ptr, RTCS_IF_PPP, &ppp_ptr->IF_HANDLE); if (error != RTCS_OK) { PPP_init_fail(ppp_ptr, stage); return(NULL); } stage++; /* Stage 9 - Bind IP address to PPP interface */ _mem_zero(&ipcp_data, sizeof(ipcp_data)); ipcp_data.IP_UP = params->up; ipcp_data.IP_DOWN = params->down; ipcp_data.IP_PARAM = params->callback_param; if(params->listen_flag == 0) { ipcp_data.ACCEPT_LOCAL_ADDR = TRUE; ipcp_data.ACCEPT_REMOTE_ADDR = TRUE; } else { ipcp_data.ACCEPT_LOCAL_ADDR = FALSE; ipcp_data.ACCEPT_REMOTE_ADDR = FALSE; } ipcp_data.LOCAL_ADDR = params->local_addr; ipcp_data.REMOTE_ADDR = params->remote_addr; ipcp_data.DEFAULT_NETMASK = TRUE; ipcp_data.DEFAULT_ROUTE = TRUE; error = RTCS_if_bind_IPCP(ppp_ptr->IF_HANDLE, &ipcp_data); if (error != RTCS_OK) { PPP_init_fail(ppp_ptr, stage); return(NULL); } params->if_handle = ppp_ptr->IF_HANDLE; stage++; /* Stage 10 - Init complete, return handle */ return(ppp_ptr); #else return(NULL); #endif /* RTCSCFG_ENABLE_IP4 */ } /* Endbody */
uint32_t TELNETCLN_connect(TELNETCLN_PARAM_STRUCT *params) { TELNETCLN_ERROR error; uint32_t prio; TELNETCLN_CONTEXT *context; error = TELNETCLN_OK; context = telnetcln_create_context(params); if (context == NULL) { error = TELNETCLN_FAIL; goto EXIT; } /* ** Install device driver for socket and telnet */ error = telnetcln_init_socket(context); if (error != TELNETCLN_OK) { error = TELNETCLN_FAIL; goto EXIT; } error = telnetcln_init_devices(context); if (error != TELNETCLN_OK) { error = TELNETCLN_FAIL; goto EXIT; } /* * Create two processes: * 1. to read input and send read characters to socket * 2. to read from socket and write the received chars to output */ if (MQX_OK != _task_get_priority(MQX_NULL_TASK_ID, &prio)) { error = TELNETCLN_FAIL; goto EXIT; } if (RTCS_task_create(TELNETCLN_OUT_TASK_NAME, prio, TELNETCLN_STACK_SIZE, telnetcln_in_task, (void*)context) != RTCS_OK) { error = TELNETCLN_FAIL; goto EXIT; } if (RTCS_task_create(TELNETCLN_IN_TASK_NAME, prio, TELNETCLN_STACK_SIZE, telnetcln_out_task, (void*)context) != RTCS_OK) { error = TELNETCLN_FAIL; goto EXIT; } _task_ready(_task_get_td((_task_id) context->rx_tid)); context->params.callbacks.on_connected(context->params.callbacks.param); EXIT: if (error != TELNETCLN_OK) { telnetcln_cleanup(context); _mem_free(context); context = NULL; } return((uint32_t) context); }
uint_32 RTCS_create ( void ) { /* Body */ RTCS_DATA_PTR RTCS_data_ptr; SOCKET_CONFIG_STRUCT_PTR socket_cfg_ptr; uint_32 error; /* ** Check and see if this is the first time we have initialized, */ if (RTCS_get_data() != NULL) { return RTCSERR_INITIALIZED; } // RTCS_data_ptr = RTCS_mem_alloc_system_zero(sizeof(RTCS_DATA)); if (RTCS_data_ptr == NULL) { error = RTCSERR_OUT_OF_MEMORY; } else { _mem_set_type(RTCS_data_ptr, MEM_TYPE_RTCS_DATA); RTCS_set_data(RTCS_data_ptr); /* ** Initialize socket state */ socket_cfg_ptr = RTCS_mem_alloc_system_zero(sizeof(SOCKET_CONFIG_STRUCT)); if (socket_cfg_ptr == NULL) { error = RTCSERR_OUT_OF_MEMORY; } else { _mem_set_type(socket_cfg_ptr, MEM_TYPE_SOCKET_CONFIG_STRUCT); socket_cfg_ptr->INITIALIZED = TRUE; socket_cfg_ptr->SOCKET_HEAD = NULL; socket_cfg_ptr->SOCKET_TAIL = NULL; RTCS_mutex_init(&socket_cfg_ptr->SOCK_MUTEX); RTCS_setcfg(SOCKET, socket_cfg_ptr); /* ** Initialize global data */ _IP_forward = FALSE; _TCP_bypass_rx = FALSE; _TCP_bypass_tx = FALSE; RTCS_data_ptr->VERSION = RTCS_VERSION; #if RTCSCFG_LOG_SOCKET_API||RTCSCFG_LOG_PCB RTCS_data_ptr->RTCS_LOG_PROTCOUNT = RTCSLOG_PROT_MAX; RTCSLOG_disable(RTCS_LOGCTRL_ALL); #endif RTCS_data_ptr->TCPIP_qid = RTCS_msgq_get_id(0,TCPIP_QUEUE); /* ** Create a pool of buffers for use in communicating to the TCP/IP task. */ RTCS_data_ptr->TCPIP_msg_pool = RTCS_msgpool_create(sizeof(TCPIP_MESSAGE), _RTCS_msgpool_init, _RTCS_msgpool_grow, _RTCS_msgpool_max); if (RTCS_data_ptr->TCPIP_msg_pool == MSGPOOL_NULL_POOL_ID) { RTCS_log_error( ERROR_TCPIP, RTCSERR_CREATE_POOL_FAILED, 0, 0, 0); error = RTCSERR_CREATE_POOL_FAILED; } else { /* ** Create the socket partition */ RTCS_data_ptr->RTCS_socket_partition = RTCS_part_create(sizeof(SOCKET_STRUCT), _RTCS_socket_part_init, _RTCS_socket_part_grow, _RTCS_socket_part_max, NULL, NULL); if (RTCS_data_ptr->RTCS_socket_partition == 0) { RTCS_log_error(ERROR_RTCS, RTCSERR_CREATE_PARTITION_FAILED, 0, 0, 0); error = RTCSERR_CREATE_PARTITION_FAILED; } else { /* ** Create TCPIP task */ error = RTCS_task_create("TCP/IP", _RTCSTASK_priority, _RTCSTASK_stacksize, TCPIP_task, NULL); if (error) { RTCS_part_destroy(RTCS_data_ptr->RTCS_socket_partition); } } if (error) { RTCS_msgpool_destroy( RTCS_data_ptr->TCPIP_msg_pool ); } } if (error) { RTCS_setcfg(SOCKET, NULL); _mem_free(socket_cfg_ptr); } } if (error) { RTCS_set_data(NULL); _mem_free(RTCS_data_ptr); } } return error; } /* Endbody */