📄 pppbaprx.c
字号:
{ pfwTimerCancel (pStackData->callbackRequestRetryTimer); pStackData->number_of_bap_callback_requests = 0; free_bap_buffer ((LINK *) &pStackData->callback_request_send_queue, sptr_bap_buffer); } else { pfwTimerCancel (pStackData->callRequestRetryTimer); pStackData->number_of_bap_call_requests = 0; free_bap_buffer ((LINK *) &pStackData->call_request_send_queue, sptr_bap_buffer); } } /* if the implementation is the Favored-Peer then drop peers request */ else { #ifdef PPP_DEBUG logMsg ("BAP Rx: Dropping Call Request Packet of ID %d as I am the Favored-Peer \n",\ bap_rx_packet->bap_id, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, bap_rx_packet->bap_id, "Favored-Peer NAK the request", BAP_RESPONSE_NAK, 0, 0, NULL); return (FAIL); } } if (pStackData->bacpUpcall == NULL) {#ifdef PPP_DEBUG logMsg ("BAP Rx: In Call Request BODA up call is NULL \n", 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, bap_rx_packet->bap_id, NULL, BAP_RESPONSE_NAK, 0, 0, NULL); return (FAIL); } /* Call Request has LinkType and optionally NoPhone and/or Reason options */ ptr_link_option = (BAP_LINK_TYPE_OPTION *) bap_find_option_in_packet (packet, BAP_LINK_TYPE, SUBOPTION_TYPE_NONE); if (ptr_link_option != 0) { link_speed = ntohs (ptr_link_option->link_speed); link_type = ptr_link_option->link_type; } else {#ifdef PPP_DEBUG logMsg ("BAP Rx: Call Request with no Link-Type Option \n",\ 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, bap_rx_packet->bap_id, "No Link Type Option", BAP_RESPONSE_NAK, 0, 0, NULL); return FAIL; } ptr_reason_option = (BAP_REASON_OPTION *) bap_find_option_in_packet (packet, BAP_REASON, SUBOPTION_TYPE_NONE); if (ptr_reason_option) { ptr_reason_string = (char *) &ptr_reason_option->reason[0]; memcpy((void *) &reason_string, (void *) ptr_reason_string, ptr_reason_option->length - 2); reason_string[ptr_reason_option->length - 2] = 0x00; ptr_reason_string = &reason_string[0]; } ptr_nophone_option = (BAP_NO_PHONE_NUMBER_NEEDED_OPTION *) bap_find_option_in_packet (packet, BAP_NO_PHONE_NUMBER_NEEDED, SUBOPTION_TYPE_NONE); if (pStackData->bacpUpcall != NULL) { response_code = (*pStackData->bacpUpcall->bacpUpCallFunction) (pManagerStackObj, BAP_EVENT_CALL_REQUEST_RECEIVED, link_speed, NULL, (BYTE) BAP_CALL_REQUEST, &ptr_reason_string); } if ((port_info = (PORT_CONNECTION_INFO *)pfwMalloc (pluginState->pluginObj->pfwObj, sizeof(PORT_CONNECTION_INFO))) == NULL) { logMsg ("BAP Rx: Memory alloc failed for new port connection info \n",\ 1, 2, 3, 4, 5, 6); return (FAIL); } port_info->next = NULL; if (response_code == BAP_RESPONSE_ACK) { port_info->port_type = link_type; port_info->port_speed = link_speed; port_info->port_dial_type = PORT_DIAL_IN; /* save all port information */ sllInit ((SL_LIST *)&tempPortList); sllPutAtTail ((SL_LIST *)&tempPortList, (SL_NODE *)port_info); /* For the request reserve a port. If fail send response with NAK */ if (pmFindAndReserveMultiplePort (pfwObj, &tempPortList) == ERROR) {#ifdef PPP_DEBUG logMsg ("BAP Rx: For Call Request, Reserving Port failed \n",\ 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, bap_rx_packet->bap_id, "No free port Available", BAP_RESPONSE_NAK, 0, 0, NULL); if (port_info != NULL) { pfwFree(port_info); /* free the port_info */ port_info = NULL; } return (FAIL); } /* * If No-Phone-Number needed option was not added then local phone * number needed to be sent and if its not set in the PORT INFO * then send response with NAK. */ if (ptr_nophone_option == NULL) { if (checkForLocalPhoneNumberInPortInfo ( pluginState, bap_rx_packet->bap_id, &tempPortList) == ERROR) return (FAIL); } if ((bap_buffer = bap_create_callback_request (pluginState, bap_rx_packet->bap_id, &tempPortList, ptr_reason_string, FALSE)) == NULL) {#ifdef PPP_DEBUG logMsg ("BAP Rx: For Call Request duplicate packet construction failed \n",\ 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response(pluginState, bap_rx_packet->bap_id, "Could not process request", BAP_RESPONSE_NAK, 0, 0, NULL); /* unreserve the previously reserved port and memory associated */ unReservePortAndMemory (&tempPortList); return (FAIL); } /* Copy the port info from the tempPortList to bafbuffer's port list */ if (copyPortInfoToBapBuffer (pfwObj, &bap_buffer->port_list, &tempPortList) == ERROR) return (FAIL); bap_buffer->status = BAP_CALL_REQUEST_ACCEPTED; add_entry_to_list ((LINK *) &pStackData->callback_request_send_queue, (LINK *) bap_buffer); /* If No-Phone-Number Option was included in the original request we */ /* MUST NOT include Phone-Delta Option */ if(ptr_nophone_option != NULL) { bap_send_call_response (pluginState, bap_rx_packet->bap_id, ptr_reason_string, (BYTE) response_code, link_type, link_speed, NULL); } else { bap_send_call_response (pluginState, bap_rx_packet->bap_id, ptr_reason_string, (BYTE) response_code, link_type, link_speed, &bap_buffer->port_list); } /* activation of port */ if ((pLinkStackObj = pmPortActivateAndWait (&bap_buffer->port_list, pManagerStackObj)) == NULL) { port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (&bap_buffer->port_list); port_info->port_status = CALL_STATUS_SECURITY_VIOLATION; port_info->port_action = CALL_ACTION_NO_RETRY; /* To get id of request packet in call request queue */ bap_send_call_status_indication (pluginState, bap_rx_packet->bap_id, "Activate Port Failed", port_info); /* Unreserving the port */ while (port_info != NULL) { pmPortUnreserve (port_info); port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info); } free_bap_buffer ((LINK *) &pStackData->callback_request_send_queue, bap_buffer); return (FAIL); } /* remove the in-active port info from port list of ptr_matching_request */ removePortInfoFromBapBuffer (&bap_buffer->port_list, pLinkStackObj); /* Assign the port info with active member in the port list */ port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (&bap_buffer->port_list); ptr_active_port = (BAP_ACTIVE_PORT *) pfwMalloc (pluginState->pluginObj->pfwObj, sizeof (BAP_ACTIVE_PORT)); if (ptr_active_port == NULL) return (FAIL); ptr_active_port->port_number = port_info->port_number; ptr_active_port->port_bap_type = port_info->port_type; ptr_active_port->port_speed = port_info->port_speed; ptr_active_port->bacpAdded = TRUE; ptr_active_port->linkStackObj = pLinkStackObj; /* add to active port queue */ add_entry_to_list ((LINK *) &pStackData->active_port_queue, (LINK *) ptr_active_port); } else /* send NAK */ { bap_send_call_response (pluginState, bap_rx_packet->bap_id, ptr_reason_string, (BYTE) response_code, 0, 0, NULL); if (port_info != NULL) { pfwFree(port_info); /* free the port_info */ port_info = NULL; } return (FAIL); } return (PASS); }/******************************************************************************* checkForLocalPhoneNumberInPortInfo - Check for presence of Local Phone-Number * in Port Info of the the bap buffer.** This function also returns OK only if there is atleast one port info * containing the local phonu number. If the Local Phone number is not available * for all the ports reserved it returns a ERROR** RETURNS: OK/ERROR */LOCAL STATUS checkForLocalPhoneNumberInPortInfo ( PFW_PLUGIN_OBJ_STATE * pluginState, /* plugin object state in manager stack */ BYTE id, /* sequence identifier */ SL_LIST * portList /* port list to check */ ) { PORT_CONNECTION_INFO * port_info; int countOfPortWithoutPhoneNumber = 0; int portCount; if (portList == NULL) return ERROR; portCount = sllCount (portList); port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList); /* Fails only if the port is not reserved, but still check it */ if (port_info == NULL) return ERROR; /* If there is only one port information */ if (sllCount (portList) == 1) { if (strlen (port_info->port_local_phone_number) == 0) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Call Request with No-Phone-Number \ Option and local phone number is not provided in PORT INFO \ for the Port [%d]",port_info->port_number, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ /* unreserve the previously reserved port */ pmPortUnreserve (port_info); /* free the port_info */ pfwFree(port_info); /* free the port_info */ port_info = NULL; bap_send_call_response (pluginState, id, NULL, BAP_RESPONSE_NAK, 0, 0, NULL); return ERROR; } return OK; } /* If there is more than one port information */ while (port_info != NULL) { if (strlen (port_info->port_local_phone_number) == 0) { /* If node to be deleted is the last node */ if (SLL_NEXT (port_info) == NULL) { sllRemove (portList, (SL_NODE *)port_info, sllPrevious (portList, (SL_NODE *)port_info)); } /* For all other intermediate nodes */ else { if (sllPrevious (portList, (SL_NODE *)port_info) == NULL) sllRemove (portList, (SL_NODE *)port_info, NULL); else sllRemove (portList, (SL_NODE *)port_info, sllPrevious (portList, (SL_NODE *)port_info)); } /* unreserve the previously reserved port */ pmPortUnreserve (port_info); /* free the port_info */ if (port_info != NULL) { pfwFree(port_info); /* free the port_info */ port_info = NULL; } countOfPortWithoutPhoneNumber++; } port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info); } /* * If none of the port associated doesn't have local phone number * send NACK and return ERROR */ if (countOfPortWithoutPhoneNumber == portCount) {#ifdef PPP_DEBUG logMsg ("BAP Rx: Call Request with No-Phone-Number \ Option and Local Phone Number is not provided for any reserved PORT \n", 1, 2, 3, 4, 5, 6);#endif /* PPP_DEBUG */ bap_send_call_response (pluginState, id, NULL, BAP_RESPONSE_NAK, 0, 0, NULL); return ERROR; } return OK; }/******************************************************************************* unReservePortAndMemory - Unreserve and free the port and memory associated * with the port list.** RETURNS: N/A */LOCAL void unReservePortAndMemory ( SL_LIST * portList /* port list to unreserve and free */ ) { PORT_CONNECTION_INFO * port_info, * temp_port_info; port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList); /* Unreserving the port */ while (port_info != NULL) { pmPortUnreserve (port_info); port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info); } /* free the memory associated with port list */ port_info = (PORT_CONNECTION_INFO *) SLL_FIRST (portList); while (port_info != NULL) { temp_port_info = (PORT_CONNECTION_INFO *) SLL_NEXT (port_info); if (port_info != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -