uint32_t PPPFSM_init ( PPPFSM_CFG_PTR fsm, /* [IN/OUT] - State Machine */ _ppp_handle handle, /* [IN] - the PPP state structure */ PPPFSM_CALL_PTR call_ptr, /* [IN] - Protocol-specific call table */ void *param /* [IN] - Parameter for protocol-specific calls */ ) { /* Body */ #if RTCSCFG_ENABLE_IP4 PPP_memzero(fsm, sizeof(PPPFSM_CFG)); fsm->HANDLE = handle; fsm->CALL = call_ptr; fsm->PRIVATE = param; fsm->STATE = PPP_STATE_INITIAL; fsm->CURID = RTCS_rand() & 0xFF; /* Initialize the mutex */ if (PPP_mutex_init(&fsm->MUTEX)) { return RTCSERR_PPP_INIT_MUTEX_FAILED; } /* Endif */ return PPP_OK; #else return RTCSERR_IP_IS_DISABLED; #endif /* RTCSCFG_ENABLE_IP4 */ } /* Endbody */
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 */