Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
pana_avp.c
00001 /* 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "nsconfig.h" 00019 #include "ns_types.h" 00020 #include "string.h" 00021 #include "common_functions.h" 00022 #include "Security/PANA/pana_avp.h" 00023 #ifdef PANA 00024 00025 uint8_t *pana_avp_base_write(uint8_t avp_type, uint16_t length, uint8_t *dptr, uint16_t flags, uint32_t vendor_id) 00026 { 00027 dptr = common_write_16_bit(avp_type, dptr); //AVP Type 00028 dptr = common_write_16_bit(flags, dptr); //FLAGS 00029 dptr = common_write_16_bit(length, dptr); //LEN 00030 dptr = common_write_16_bit(0, dptr); //RESERVED 00031 if (flags & PANA_EAP_VENDOR_FLAG) { 00032 dptr = common_write_32_bit(vendor_id, dptr); //SET VENDOR 00033 } 00034 return dptr; 00035 } 00036 00037 uint8_t *pana_avp_32_bit_write(uint8_t avp_type, uint32_t value, uint8_t *dptr) 00038 { 00039 dptr = pana_avp_base_write(avp_type, 4, dptr, 0, 0); 00040 return common_write_32_bit(value, dptr); 00041 } 00042 00043 00044 uint8_t *pana_avp_write_n_bytes(uint16_t avp_type, uint16_t length, const uint8_t *value, uint8_t *dptr) 00045 { 00046 dptr = pana_avp_base_write(avp_type, length,dptr, 0, 0); 00047 if (value) { 00048 memcpy(dptr, value, length); 00049 } else { 00050 memset(dptr, 0, length); 00051 } 00052 dptr += length; 00053 //Padding 00054 while(length % 4) { 00055 *dptr++= 0; 00056 length++; 00057 } 00058 return dptr; 00059 } 00060 00061 uint8_t *pana_avp_vendor_id_write_n_bytes(uint16_t avp_type, uint16_t length, const uint8_t *value, uint8_t *dptr, uint32_t vendor_id) 00062 { 00063 dptr = pana_avp_base_write(avp_type, length,dptr, PANA_EAP_VENDOR_FLAG, vendor_id); 00064 if (value) { 00065 memcpy(dptr, value, length); 00066 } else { 00067 memset(dptr, 0, length); 00068 } 00069 dptr += length; 00070 00071 while(length % 4) { 00072 *dptr++= 0; 00073 length++; 00074 } 00075 return dptr; 00076 00077 } 00078 00079 bool pana_avp_discover(uint8_t *dptr, uint16_t data_len, pana_avp_t *avp) 00080 { 00081 uint16_t avp_code; 00082 uint16_t readed = 0, pana_temp_var_16 = 0; 00083 avp->avp_ptr = NULL; 00084 while (readed < data_len) { 00085 avp->flags = 0; 00086 avp->vendor_id = 0; 00087 avp_code = common_read_16_bit(dptr); 00088 dptr += 2; 00089 avp->flags = common_read_16_bit(dptr); 00090 dptr += 2; 00091 pana_temp_var_16 = common_read_16_bit(dptr); 00092 if (pana_temp_var_16 == 0) { 00093 return false; 00094 } 00095 dptr += 4; //Update pointer and Skip Reserved 00096 avp->len = pana_temp_var_16; 00097 00098 if (avp->flags & PANA_EAP_VENDOR_FLAG) { 00099 avp->vendor_id = common_read_32_bit(dptr); 00100 dptr += 4; 00101 readed += 4; 00102 } 00103 readed += 8; 00104 readed += pana_temp_var_16; 00105 //Set Data Start here already 00106 avp->avp_ptr = dptr; 00107 dptr += pana_temp_var_16; 00108 00109 //Check division remainder 00110 while(pana_temp_var_16 % 4) { 00111 dptr++; 00112 readed++; 00113 pana_temp_var_16++; 00114 } 00115 00116 if (readed > data_len) { 00117 avp->avp_ptr = NULL; 00118 return false; 00119 } 00120 00121 if (avp_code == avp->code) { 00122 //Save AVP pointer 00123 return true; 00124 } 00125 avp->avp_ptr = NULL; 00126 00127 } 00128 return false; 00129 00130 } 00131 #endif 00132
Generated on Fri Jul 22 2022 04:53:58 by
1.7.2
