📄 pppbaptx.c
字号:
M_BLK_ID packet, /* BAP packet */ char unique_digits_length, /* unique digits option length */ char * unique_digits_string, /* unique digits option value */ char * subscriber_number_string, /* subscriber number option value */ char * subaddress_string /* subadress option value */ ) { BAP_PHONE_DELTA_OPTION * ptr_phone_delta_option = NULL; BAP_PHONE_DELTA_UNIQUE_DIGITS * ptr_unique_digits_option = NULL; USHORT phone_delta_length = 0; /* Get the data pointer->ie base address */ char * packet_address = packet->mBlkHdr.mData; USHORT unique_digits_string_length = 0; USHORT subscriber_number_string_length = 0; USHORT subaddress_string_length = 0; phone_delta_length = sizeof (BAP_PHONE_DELTA_OPTION) - 1; if (subscriber_number_string != NULL) { subscriber_number_string_length = (USHORT) strlen(subscriber_number_string); if (subscriber_number_string_length) phone_delta_length = (USHORT) (phone_delta_length + subscriber_number_string_length + (USHORT) sizeof (BAP_PHONE_DELTA_OPTION) -1); } if ((unique_digits_string != NULL) || (unique_digits_length != 0)) { unique_digits_string_length = (USHORT) strlen(unique_digits_string) + sizeof (unique_digits_length); if (unique_digits_string_length) phone_delta_length = (USHORT) (phone_delta_length + unique_digits_string_length + sizeof (BAP_PHONE_DELTA_OPTION) -1); } if (subaddress_string != NULL) { subaddress_string_length = (USHORT) strlen(subaddress_string); if (subaddress_string_length) phone_delta_length = (USHORT) (phone_delta_length + subaddress_string_length + (USHORT) sizeof (BAP_PHONE_DELTA_OPTION) - 1); } /* move to the address were option field start */ ptr_phone_delta_option = (BAP_PHONE_DELTA_OPTION *) (packet_address + packet->mBlkHdr.mLen); ptr_phone_delta_option->type = BAP_PHONE_DELTA; ptr_phone_delta_option->length = (BYTE) phone_delta_length; /* move to the address were SUB Option field start */ ptr_phone_delta_option = (BAP_PHONE_DELTA_OPTION *) (packet_address + (ULONG) packet->mBlkHdr.mLen + sizeof (BAP_PHONE_DELTA_OPTION) - 1); /* update the length PACKET + TYPE | LENGTH */ packet->mBlkHdr.mLen = packet->mBlkHdr.mLen + sizeof (BAP_PHONE_DELTA_OPTION) - 1; if (subscriber_number_string_length) { ptr_phone_delta_option->type = SUBSCRIBER_NUMBER_TYPE; ptr_phone_delta_option->length = (BYTE)(subscriber_number_string_length + sizeof (BAP_PHONE_DELTA_OPTION) - 1); memcpy ((void *) &ptr_phone_delta_option->data, (void *) subscriber_number_string, subscriber_number_string_length); /* update the length PACKET + TYPE | LENGTH + TYPE | LENGTH | VALUE */ packet->mBlkHdr.mLen = packet->mBlkHdr.mLen + subscriber_number_string_length + (sizeof (BAP_PHONE_DELTA_OPTION) - 1); /* Update the pointer of the packet */ ptr_phone_delta_option = (BAP_PHONE_DELTA_OPTION *) (packet_address + (ULONG)packet->mBlkHdr.mLen); } if (subaddress_string_length) { ptr_phone_delta_option->type = PHONE_NUMBER_SUBADDRESS_TYPE; ptr_phone_delta_option->length = (BYTE)(subaddress_string_length + sizeof (BAP_PHONE_DELTA_OPTION) - 1); memcpy ((void *) &ptr_phone_delta_option->data, (void *) subaddress_string, subaddress_string_length); /* update the length PACKET + TYPE | LENGTH + TYPE | LENGTH | VALUE + TYPE | LENGTH | VALUE */ packet->mBlkHdr.mLen = packet->mBlkHdr.mLen + subaddress_string_length + (sizeof (BAP_PHONE_DELTA_OPTION) - 1); /* Update the pointer of the packet */ ptr_phone_delta_option = (BAP_PHONE_DELTA_OPTION *) (packet_address + packet->mBlkHdr.mLen); } if(unique_digits_string_length) { ptr_unique_digits_option = (BAP_PHONE_DELTA_UNIQUE_DIGITS *) ptr_phone_delta_option; ptr_unique_digits_option->type = UNIQUE_DIGITS_TYPE; ptr_unique_digits_option->length = (BYTE)(unique_digits_string_length + sizeof (BAP_PHONE_DELTA_OPTION) - 1); ptr_unique_digits_option->number_of_digits = unique_digits_length; memcpy ((void *) &ptr_unique_digits_option->digits, (void *) unique_digits_string, strlen(unique_digits_string)); /* Update with new lenght */ packet->mBlkHdr.mLen = packet->mBlkHdr.mLen + unique_digits_string_length + (sizeof (BAP_PHONE_DELTA_OPTION) - 1); } }/* BACP Application Interface Functions *//******************************************************************************** bacpUpCallInit - Initialize the Upcall routines for BACP** This routine is called from application to initialize the bacpUpCall functions* used by BAP modules, to interact with BODA (Bandwidth on Demand Application)* * RETURNS: OK/ERROR*/STATUS bacpUpCallInit ( PFW_STACK_OBJ *managerStackObj, /* manager stack object */ BACP_UPCALL_FUNCTIONS *upcallFuncPtr /* function pointer to up calls */ ) { PFW_PLUGIN_OBJ * pluginObj = NULL; PFW_PLUGIN_OBJ_STATE * pluginState = NULL; BACP_STACK_DATA * pStackData = NULL; if ((pluginObj = pfwPluginObjGet (pfwStackObjPfwGet (managerStackObj), "PPP_BACP") ) == NULL) { printf ("BACP pluginObject pointer is NULL \n"); return ERROR; } if ((pluginState = pfwPluginObjStateGet (managerStackObj, pluginObj)) == NULL) { printf ("BACP pluginState pointer is NULL \n"); return ERROR; } pStackData = (BACP_STACK_DATA *)pluginState->stackData; if (pStackData == NULL) { printf ("Stack Data pointer is NULL \n"); return ERROR; } if (upcallFuncPtr == NULL) { printf (" Upcall Function pointer is NULL \n"); return ERROR; } pStackData->bacpUpcall = upcallFuncPtr; return OK; }/******************************************************************************** bapBundleCurrentBandwidthGet - get the current total bandwidth of the bundle** This routine is called from application to get the total bandwidth of the * bundle. Calls bap_calculate_total_bandwidth_for_the_bundle to calculate the * bandwidth.* * RETURNS: Total bandwidth calculated*/ULONG bapBundleCurrentBandwidthGet ( PFW_STACK_OBJ *managerStackObj /* manager stack object */ ) { PFW_PLUGIN_OBJ * pluginObj = NULL; PFW_PLUGIN_OBJ_STATE * pluginState = NULL; ULONG bandwidth = 0; BACP_STACK_DATA *pStackData = NULL; if ((pluginObj = pfwPluginObjGet (pfwStackObjPfwGet (managerStackObj), "PPP_BACP")) == NULL) return 0; if ((pluginState = pfwPluginObjStateGet (managerStackObj, pluginObj)) == NULL) return 0; pStackData = (BACP_STACK_DATA *) pluginState->stackData; if (pStackData->stateData.state != PPP_OPENED_STATE) { printf ("BACP is not in PPP_OPENED_STATE \n"); return 0; } if (pfwPluginObjStateLock (pluginState) == ERROR) return 0; bandwidth = bap_calculate_total_bandwidth_for_the_bundle (pluginState); if (pfwPluginObjStateRelease (pluginState) == ERROR) return 0; return (bandwidth); }/******************************************************************************** bap_calculate_total_bandwidth_for_the_bundle - calculates the total * bandwidth of from the active port list of BACP Componenet** This routine is called to calculate the total bandwidth for the bundle. The * routine gets a pointer to the first entry in the active_port_queue of BACP * component. The total bandwidth is calculated as the sum of the port_speed * of all the links in the active_port_queue.* * RETURNS: ULONG (calculated total bandwidth)*/LOCAL ULONG bap_calculate_total_bandwidth_for_the_bundle ( PFW_PLUGIN_OBJ_STATE *pComponentState /* BACP plugin object state */ ) { BAP_ACTIVE_PORT *sptr_active_port = NULL; ULONG total_bandwidth = 0; BACP_STACK_DATA *pStackData = (BACP_STACK_DATA *)pComponentState->stackData; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_first_entry_in_list ((LINK *) &pStackData->active_port_queue); while (sptr_active_port != NULL) { total_bandwidth += sptr_active_port->port_speed; sptr_active_port = (BAP_ACTIVE_PORT *) get_pointer_to_next_entry_in_list ((LINK *) sptr_active_port); } return (total_bandwidth); }/******************************************************************************** bapBundleBandwidthAdd - add a link with the specified bandwidth to the bundle** This routine is called to add the requested bandwidth to the bundle. It also * finds and reserves a port with the requested bandwidth, creates call or * callback request and sends the packet. The timer is started to keep track * number of request sent. ** RETURNS: OK/ERROR*/STATUS bapBundleBandwidthAdd ( PFW_STACK_OBJ *managerStackObj, /* manager stack object */ ULONG bandwidth, /* bandwidth to be added */ char * reason_string, /* reason string */ BYTE_ENUM(BAP_PACKET_TYPE) call_or_callback /* call or callback request */ ) { PFW_PLUGIN_OBJ * pluginObj = NULL; PFW_PLUGIN_OBJ_STATE * pluginState = NULL; PFW_OBJ * pfwObj = NULL; BACP_STACK_DATA * pStackData = NULL; BACP_PROFILE_DATA * pProfileData = NULL; BYTE txIdentifier; PORT_CONNECTION_INFO *port_info = NULL; BAP_BUFFER * bap_buffer = NULL; M_BLK_ID packet = NULL; SL_LIST tempPortList; if ((pluginObj = pfwPluginObjGet (pfwStackObjPfwGet (managerStackObj), "PPP_BACP") ) == NULL) return ERROR; if ((pluginState = pfwPluginObjStateGet (managerStackObj, pluginObj)) == NULL) return ERROR; if (pfwPluginObjStateLock (pluginState) == ERROR) return ERROR; pfwObj = pluginState->pluginObj->pfwObj; pStackData = (BACP_STACK_DATA *) pluginState->stackData; pProfileData = (BACP_PROFILE_DATA *) pluginState->profileData; if (pStackData->stateData.state != PPP_OPENED_STATE) { if (pfwPluginObjStateRelease (pluginState) == ERROR) return ERROR; return ERROR; } if ((port_info = (PORT_CONNECTION_INFO *)pfwMalloc (pfwObj, sizeof(PORT_CONNECTION_INFO))) == NULL) { printf("PPP: could not allocate memory for new port connection info \n"); if (pfwPluginObjStateRelease (pluginState) == ERROR) return ERROR; return ERROR; } port_info->next = NULL; if (call_or_callback == BAP_CALL_REQUEST) { port_info->port_speed = bandwidth; port_info->port_dial_type = PORT_DIAL_OUT; /* For the request bandwidth reserve a port. If fail return */ if (pmPortFindAndReserve (port_info) == ERROR) {#ifdef PPP_DEBUG printf("BAP: In function BundleBandwidthAdd: Find and Reserve a port failed \n");#endif /* PPP_DEBUG */ if (port_info != NULL) { pfwFree (port_info); port_info = NULL; } if (pfwPluginObjStateRelease (pluginState) == ERROR) return ERROR; return ERROR; } txIdentifier = pStackData->last_bap_id++; bap_buffer = bap_create_call_request (pluginState, txIdentifier, port_info, reason_string); if (bap_buffer == NULL) {#ifdef PPP_DEBUG printf("BAP: In function BundleBandwidthAdd:Create CALL REQ Packet failed \n");#endif /* PPP_DEBUG */ pmPortUnreserve (port_info); if (port_info != NULL) { pfwFree (port_info); port_info = NULL; } if (pfwPluginObjStateRelease (pluginState) == ERROR) return ERROR; return ERROR; } /* save all port information */ sllInit ((SL_LIST *)&bap_buffer->port_list); sllPutAtTail ((SL_LIST *)&bap_buffer->port_list, (SL_NODE *)port_info); /* update the status */ bap_buffer->status = BAP_CALL_REQUEST_ALREADY_IN_PROGRESS; /* add to call request send queue */ add_entry_to_list ((LINK *) &pStackData->call_request_send_queue, (LINK *) bap_buffer); /* Updating BAP statistics */ pStackData->bap_statistics.number_of_tx_bytes += bap_buffer->bap->mBlkHdr.mLen; ++pStackData->bap_statistics.number_of_tx_packets; ++pStackData->bap_statistics. number_of_control_tx_packets [BAP_CALL_REQUEST];#ifdef PPP_DEBUG logMsg("BAP Tx: Sending Call Request Packet ID %d Length %u\n",txIdentifier, \ bap_buffer->bap->mBlkHdr.mLen, 3, 4, 5, 6);#endif /* PPP_DEBUG */ /* * save the packet information after making a duplicate packet to * call_request_send_queue */ packet = bap_buffer->bap; bap_buffer->bap = bacpDupPkt (packet); if (bap_buffer->bap == NULL) {#ifdef PPP_DEBUG logMsg ("bap_create_call_request Packet duplication Error: \n",\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -