uint_32 PPP_shutdown ( _ppp_handle handle /* [IN] - the PPP state structure */ ) { /* Body */ #if RTCSCFG_ENABLE_IP4 PPP_CFG_PTR ppp_ptr = handle; _rtcs_sem sem; uint_32 error = RTCS_OK; /* wait time in 0.1 Sec */ uint_32 wait_time = 50; /* delay time in mS */ uint_32 delay_time = 100; PPP_lowerdown(ppp_ptr); ppp_ptr->STOP_RX = TRUE; while(ppp_ptr->STOP_RX) { /* Waiting before Rx task will be closed or kill it. */ _time_delay(delay_time); wait_time--; if(!wait_time) { error = RTCSERR_TIMEOUT; RTCS_task_destroy(ppp_ptr->RX_TASKID); break; } } /* Kill Tx task */ RTCS_sem_init(&sem); PPP_send_shutdown(ppp_ptr, &sem); RTCS_sem_wait(&sem); RTCS_sem_destroy(&sem); RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); CCP_destroy(ppp_ptr); LCP_destroy(ppp_ptr); PPP_mutex_destroy(&ppp_ptr->MUTEX); PPP_memfree(handle); return(error); #else return RTCSERR_IP_IS_DISABLED; #endif /* RTCSCFG_ENABLE_IP4 */ } /* Endbody */
uint32_t PPP_release ( _ppp_handle handle /* [IN] - the PPP state structure */ ) { /* Body */ #if RTCSCFG_ENABLE_IP4 PPP_CFG_PTR ppp_ptr = handle; _rtcs_sem sem; uint32_t error = RTCS_OK; /* wait time in 0.1 Sec */ uint32_t wait_time = 50; /* delay time in mS */ uint32_t delay_time = 100; if (ppp_ptr == NULL) { return(RTCS_OK); } error = RTCS_if_unbind(ppp_ptr->IF_HANDLE, IPCP_get_local_addr(ppp_ptr->IF_HANDLE)); if (error != RTCS_OK) { return(error); } ppp_ptr->STOP_RX = TRUE; /* Waiting before Rx task will be closed or kill it. */ while(ppp_ptr->STOP_RX) { _time_delay(delay_time); wait_time--; if(!wait_time) { error = RTCSERR_TIMEOUT; RTCS_task_destroy(ppp_ptr->RX_TASKID); break; } } error = PPP_close(ppp_ptr); if (error != PPP_OK) { return(error); } /* Kill Tx task */ RTCS_sem_init(&sem); PPP_send_shutdown(ppp_ptr, &sem); RTCS_sem_wait(&sem); RTCS_sem_destroy(&sem); error = _iopcb_close(ppp_ptr->DEVICE); if (error != RTCS_OK) { return(error); } error = _iopcb_ppphdlc_release(ppp_ptr->DEVICE); if (error != RTCS_OK) { return(error); } ppp_ptr->DEVICE = NULL; error = RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); if (error != MQX_OK) { return(error); } /* error = CCP_destroy(ppp_ptr); if (error != PPP_OK) { return(error); } */ error = LCP_destroy(ppp_ptr); if (error != PPP_OK) { return(error); } PPP_mutex_destroy(&ppp_ptr->MUTEX); if (ppp_ptr->IOPCB_DEVICE) { fflush(ppp_ptr->IOPCB_DEVICE); error = fclose(ppp_ptr->IOPCB_DEVICE); if (error != RTCS_OK) { return(error); } } error = RTCS_if_remove(ppp_ptr->IF_HANDLE); if (error != RTCS_OK) { return(error); } PPP_memfree(handle); return(error); #else return RTCSERR_IP_IS_DISABLED; #endif /* RTCSCFG_ENABLE_IP4 */ } /* Endbody */
/*FUNCTION*------------------------------------------------------------- * * Function Name : PPP_init_fail * Returned Value : none * Comments : * Do cleanup when initialization fails. * *END*-----------------------------------------------------------------*/ void PPP_init_fail(PPP_CFG_PTR ppp_ptr, int stage) { if (stage > 0) { fclose(ppp_ptr->IOPCB_DEVICE); _mem_free(ppp_ptr->DEVICE_NAME); ppp_ptr->DEVICE_NAME = NULL; } if (stage > 1) { _lwsem_destroy(&ppp_ptr->MUTEX); } if (stage > 2) { LCP_destroy(ppp_ptr); } if (stage > 3) { // CCP_close(ppp_ptr); // CCP_destroy(ppp_ptr); } if (stage > 5) { LWSEM_STRUCT sem; RTCS_sem_init(&sem); PPP_send_shutdown(ppp_ptr, &sem); RTCS_sem_wait(&sem); RTCS_sem_destroy(&sem); } /* Message pool must be destroyed after we send shutdown message to TX task */ if (stage > 4) { RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); } if (stage > 6) { uint32_t wait_time = 50; uint32_t delay_time = 100; ppp_ptr->STOP_RX = TRUE; while(ppp_ptr->STOP_RX) { _time_delay(delay_time); wait_time--; if(!wait_time) { RTCS_task_destroy(ppp_ptr->RX_TASKID); break; } } } if (stage > 7) { _iopcb_close(ppp_ptr->DEVICE); } if (stage > 8) { RTCS_if_unbind(ppp_ptr->IF_HANDLE, IPCP_get_local_addr(ppp_ptr->IF_HANDLE)); RTCS_if_remove(ppp_ptr->IF_HANDLE); } _mem_free(ppp_ptr); }
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 */