Commit 54d9342b authored by yunshou-yang's avatar yunshou-yang

SM-ies: updatesrc/nas/ies/AllowedSSCMode.c

parent bb72a122
#include <stdint.h>
#include <stdbool.h>
#include "bstrlib.h"
#define ALLOWED_SSC_MODE_MINIMUM_LENGTH 1
#define ALLOWED_SSC_MODE_MAXIMUM_LENGTH 1
typedef bstring AllowedSSCMode;
#define SSC_MODE1_NOT_ALLOWED 0
#define SSC_MODE1_ALLOWED 1
#define SSC_MODE2_NOT_ALLOWED 0
#define SSC_MODE2_ALLOWED 1
#define SSC_MODE3_NOT_ALLOWED 0
#define SSC_MODE3_ALLOWED 1
//typedef bstring AllowedSSCMode;
typedef struct{
bool is_ssc1_allowed;
bool is_ssc2_allowed;
bool is_ssc3_allowed;
}AllowedSSCMode;
int encode_allowed_ssc_mode ( AllowedSSCMode allowedsscmode, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_allowed_ssc_mode ( AllowedSSCMode * allowedsscmode, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
......
......@@ -8,22 +8,20 @@
int encode_alwayson_pdu_session_indication ( AlwaysonPDUSessionIndication alwaysonpdusessionindication, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t bitStream = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,ALWAYSON_PDU_SESSION_INDICATION_MINIMUM_LENGTH , len);
if ((encode_result = encode_bstring (alwaysonpdusessionindication, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if(iei > 0){
bitStream |= (iei & 0xf0);
}
if(alwaysonpdusessionindication.apsi_indication)
bitStream |= 0x01;
ENCODE_U8(buffer+encoded,bitStream,encoded);
return encoded;
}
......@@ -31,17 +29,23 @@ int encode_alwayson_pdu_session_indication ( AlwaysonPDUSessionIndication always
int decode_alwayson_pdu_session_indication ( AlwaysonPDUSessionIndication * alwaysonpdusessionindication, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
if((decode_result = decode_bstring (alwaysonpdusessionindication, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
uint8_t bitStream = 0;
DECODE_U8(buffer+decoded,bitStream,decoded);
if(iei != bitStream&0xf0){
return -1;
}
if(iei > 0){
bitStream = (bitStream & 0x01);
}
if(bitStream)
alwaysonpdusessionindication->apsi_indication = true;
else
alwaysonpdusessionindication->apsi_indication = false;
return decoded;
}
#ifndef _ALWAYSONPDUSESSIONINDICATION_H_
#define _ALWAYSONPDUSESSIONINDICATION_H_
#include <stdint.h>
#include <stdbool.h>
#include "bstrlib.h"
#define ALWAYSON_PDU_SESSION_INDICATION_MINIMUM_LENGTH 1
#define ALWAYSON_PDU_SESSION_INDICATION_MAXIMUM_LENGTH 1
typedef bstring AlwaysonPDUSessionIndication;
#define ALWAYSON_PDU_SESSION_NOT_ALLOWED 0
#define ALWAYSON_PDU_SESSION_REQUIRED 1
typedef struct{
bool apsi_indication;
}AlwaysonPDUSessionIndication;
int encode_alwayson_pdu_session_indication ( AlwaysonPDUSessionIndication alwaysonpdusessionindication, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_alwayson_pdu_session_indication ( AlwaysonPDUSessionIndication * alwaysonpdusessionindication, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -8,22 +8,19 @@
int encode_alwayson_pdu_session_requested ( AlwaysonPDUSessionRequested alwaysonpdusessionrequested, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t bitStream = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,ALWAYSON_PDU_SESSION_REQUESTED_MINIMUM_LENGTH , len);
if ((encode_result = encode_bstring (alwaysonpdusessionrequested, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if(iei > 0){
bitStream |= (iei & 0xf0);
}
if(alwaysonpdusessionrequested.apsr_requested)
bitStream |= 0x01;
ENCODE_U8(buffer+encoded,bitStream,encoded);
return encoded;
}
......@@ -31,17 +28,23 @@ int encode_alwayson_pdu_session_requested ( AlwaysonPDUSessionRequested alwayson
int decode_alwayson_pdu_session_requested ( AlwaysonPDUSessionRequested * alwaysonpdusessionrequested, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
if((decode_result = decode_bstring (alwaysonpdusessionrequested, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
uint8_t bitStream = 0;
DECODE_U8(buffer+decoded,bitStream,decoded);
if(iei != bitStream&0xf0){
return -1;
}
if(iei > 0){
bitStream = (bitStream & 0x01);
}
if(bitStream)
alwaysonpdusessionrequested->apsr_requested = true;
else
alwaysonpdusessionrequested->apsr_requested = false;
return decoded;
}
#ifndef _ALWAYSONPDUSESSIONREQUESTED_H_
#define _ALWAYSONPDUSESSIONREQUESTED_H_
#include <stdint.h>
#include <stdbool.h>
#include "bstrlib.h"
#define ALWAYSON_PDU_SESSION_REQUESTED_MINIMUM_LENGTH 1
#define ALWAYSON_PDU_SESSION_REQUESTED_MAXIMUM_LENGTH 1
typedef bstring AlwaysonPDUSessionRequested;
#define ALWAYSON_PDU_SESSION_NOT_REQUESTED 0
#define ALWAYSON_PDU_SESSION_REQUESTED 1
typedef struct{
bool apsr_requested;
}AlwaysonPDUSessionRequested;
int encode_alwayson_pdu_session_requested ( AlwaysonPDUSessionRequested alwaysonpdusessionrequested, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_alwayson_pdu_session_requested ( AlwaysonPDUSessionRequested * alwaysonpdusessionrequested, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -37,7 +37,7 @@ int encode_authentication_parameter_rand ( AuthenticationParameterRAND authenti
int decode_authentication_parameter_rand ( AuthenticationParameterRAND * authenticationparameterrand, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded = 0;
uint8_t ielen = 1;
uint8_t ielen = 16;
int decode_result;
if (iei > 0) {
......
......@@ -8,39 +8,35 @@
int encode_dnn ( DNN dnn, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,DNN_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
if ((encode_result = encode_bstring (dnn, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
return encoded;
}
int decode_dnn ( DNN * dnn, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
int decoded = 0;
uint8_t ielen = 0;
int decode_result = 0;
if (iei > 0)
{
......@@ -48,16 +44,15 @@ int decode_dnn ( DNN * dnn, uint8_t iei, uint8_t * buffer, uint32_t len )
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
if((decode_result = decode_bstring (dnn, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -8,27 +8,22 @@
int encode_eap_message ( EAPMessage eapmessage, uint8_t iei, uint8_t * buffer, uint32_t len )
{
printf("encode_eap_message\n");
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,EAP_MESSAGE_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
encoded++;
if ((encode_result = encode_bstring (eapmessage, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
......@@ -46,14 +41,14 @@ int decode_eap_message ( EAPMessage * eapmessage, uint8_t iei, uint8_t * buffer,
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
int decode_result = 0;
if (iei > 0)
{
CHECK_IEI_DECODER (iei, *buffer);
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
......@@ -66,6 +61,7 @@ int decode_eap_message ( EAPMessage * eapmessage, uint8_t iei, uint8_t * buffer,
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -8,18 +8,17 @@
int encode_extended_protocol_configuration_options ( ExtendedProtocolConfigurationOptions extendedprotocolconfigurationoptions, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,EXTENDED_PROTOCOL_CONFIGURATION_OPTIONS_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
......@@ -27,13 +26,12 @@ int encode_extended_protocol_configuration_options ( ExtendedProtocolConfigurati
encoded++;
if ((encode_result = encode_bstring (extendedprotocolconfigurationoptions, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
uint32_t res = encoded - 1 - ((iei > 0) ? 1 : 0);
uint32_t res = encoded - 2 - ((iei > 0) ? 1 : 0);
*lenPtr =res/(1<<8);
lenPtr++;
*lenPtr = res%(1<<8);
......@@ -44,8 +42,8 @@ int encode_extended_protocol_configuration_options ( ExtendedProtocolConfigurati
int decode_extended_protocol_configuration_options ( ExtendedProtocolConfigurationOptions * extendedprotocolconfigurationoptions, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint32_t ielen=0;
int decode_result = 0;
if (iei > 0)
{
......@@ -56,7 +54,7 @@ int decode_extended_protocol_configuration_options ( ExtendedProtocolConfigurati
ielen = *(buffer + decoded);
decoded++;
ielen = ( ielen << 8)+*(buffer + decoded);
ielen = ( ielen << 8) + *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
......@@ -65,6 +63,7 @@ int decode_extended_protocol_configuration_options ( ExtendedProtocolConfigurati
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -8,27 +8,19 @@
int encode_gprs_timer ( GPRSTimer gprstimer, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t timeValue = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,GPRS_TIMER_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if ((encode_result = encode_bstring (gprstimer, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
timeValue = (gprstimer.unit<<5) | gprstimer.timeValue;
ENCODE_U8(buffer+encoded,timeValue,encoded);
return encoded;
}
......@@ -36,8 +28,7 @@ int encode_gprs_timer ( GPRSTimer gprstimer, uint8_t iei, uint8_t * buffer, uint
int decode_gprs_timer ( GPRSTimer * gprstimer, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint8_t timeValue = 0;
if (iei > 0)
{
......@@ -45,13 +36,10 @@ int decode_gprs_timer ( GPRSTimer * gprstimer, uint8_t iei, uint8_t * buffer, ui
decoded++;
}
DECODE_U8(buffer+decoded,timeValue,decoded);
gprstimer->unit = (uint8_t)((timeValue&0xe0)>>5);
gprstimer->timeValue = (uint8_t)(timeValue&0x1f);
if((decode_result = decode_bstring (gprstimer, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
#ifndef _GPRSTIMER_H_
#define _GPRSTIMER_H_
#include <stdint.h>
#include "bstrlib.h"
#define GPRS_TIMER_MINIMUM_LENGTH 2
#define GPRS_TIMER_MAXIMUM_LENGTH 2
typedef bstring GPRSTimer;
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_2_SECONDS 0b000
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_1_MINUTE 0b001
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_DECIHOURS 0b010
#define VALUE_INDICATES_THAT_THE_TIMER_IS_DEACTIVATED 0b111
typedef struct{
uint8_t unit:3;
uint8_t timeValue:5;
} GPRSTimer;
int encode_gprs_timer ( GPRSTimer gprstimer, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_gprs_timer ( GPRSTimer * gprstimer, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -8,12 +8,12 @@
int encode_gprs_timer3 ( GPRSTimer3 gprstimer3, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
uint8_t timeValue = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,GPRS_TIMER3_MINIMUM_LENGTH , len);
if( iei >0 ){
if( iei > 0){
*buffer=iei;
encoded++;
}
......@@ -32,7 +32,7 @@ int decode_gprs_timer3 ( GPRSTimer3 * gprstimer3, uint8_t iei, uint8_t * buffer,
{
int decoded=0;
uint8_t ielen=0;
uint8_t timeValue;
uint8_t timeValue = 0;
if (iei > 0)
{
......
......@@ -8,13 +8,13 @@
#define GPRS_TIMER3_MAXIMUM_LENGTH 3
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_10_MINUTES 0b000
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_1_HOUR 0b001
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_10_HOURS 0b010
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_2_SECONDS 0b011
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_1_HOUR 0b001
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_10_HOURS 0b010
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_2_SECONDS 0b011
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_30_SECONDS 0b100
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_1_MINUTE 0b101
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_320_HOURS 0b110
#define VALUE_INDICATES_THAT_THE_TIMER_IS_DEACTIVATED 0b111
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_1_MINUTE 0b101
#define VALUE_IS_INCREMENTED_IN_MULTIPLES_OF_320_HOURS 0b110
#define VALUE_INDICATES_THAT_THE_TIMER_IS_DEACTIVATED 0b111
typedef struct{
uint8_t unit:3;
......
......@@ -8,21 +8,17 @@
int encode_intergrity_protection_maximum_data_rate ( IntergrityProtectionMaximumDataRate intergrityprotectionmaximumdatarate, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,INTERGRITY_PROTECTION_MAXIMUM_DATA_RATE_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei > 0)
{
*buffer=iei;
encoded++;
}
if ((encode_result = encode_bstring (intergrityprotectionmaximumdatarate, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
......@@ -36,8 +32,8 @@ int encode_intergrity_protection_maximum_data_rate ( IntergrityProtectionMaximum
int decode_intergrity_protection_maximum_data_rate ( IntergrityProtectionMaximumDataRate * intergrityprotectionmaximumdatarate, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint8_t ielen=2;
int decode_result = 0;
if (iei > 0)
{
......@@ -45,9 +41,6 @@ int decode_intergrity_protection_maximum_data_rate ( IntergrityProtectionMaximum
decoded++;
}
if((decode_result = decode_bstring (intergrityprotectionmaximumdatarate, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
......
#include <stdint.h>
#include "bstrlib.h"
#define INTERGRITY_PROTECTION_MAXIMUM_DATA_RATE_MINIMUM_LENGTH 3
#define INTERGRITY_PROTECTION_MAXIMUM_DATA_RATE_MAXIMUM_LENGTH 3
#define INTERGRITY_PROTECTION_MAXIMUM_DATA_RATE_MINIMUM_LENGTH 2
#define INTERGRITY_PROTECTION_MAXIMUM_DATA_RATE_MAXIMUM_LENGTH 2
typedef bstring IntergrityProtectionMaximumDataRate;
......
......@@ -8,27 +8,19 @@
int encode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupportedPacketFilters maximumnumberofsupportedpacketfilters, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,MAXIMUM_NUMBER_OF_SUPPORTED_PACKET_FILTERS_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if ((encode_result = encode_bstring (maximumnumberofsupportedpacketfilters, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
ENCODE_U8(buffer+encoded,(uint8_t)(maximumnumberofsupportedpacketfilters&0x00ff),encoded);
ENCODE_U8(buffer+encoded,(uint8_t)((maximumnumberofsupportedpacketfilters & 0x700) >> 3),encoded);
return encoded;
}
......@@ -36,8 +28,8 @@ int encode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupported
int decode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupportedPacketFilters * maximumnumberofsupportedpacketfilters, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint8_t bit8Stream = 0;
uint16_t bit16Stream = 0;
if (iei > 0)
{
......@@ -45,13 +37,13 @@ int decode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupported
decoded++;
}
if((decode_result = decode_bstring (maximumnumberofsupportedpacketfilters, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream |= bit8Stream;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream |= (uint16_t)(bit8Stream << 3);
*maximumnumberofsupportedpacketfilters = bit16Stream;
return decoded;
}
......@@ -4,7 +4,9 @@
#define MAXIMUM_NUMBER_OF_SUPPORTED_PACKET_FILTERS_MINIMUM_LENGTH 3
#define MAXIMUM_NUMBER_OF_SUPPORTED_PACKET_FILTERS_MAXIMUM_LENGTH 3
typedef bstring MaximumNumberOfSupportedPacketFilters;
typedef uint16_t MaximumNumberOfSupportedPacketFilters;
int encode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupportedPacketFilters maximumnumberofsupportedpacketfilters, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_maximum_number_of_supported_packet_filters ( MaximumNumberOfSupportedPacketFilters * maximumnumberofsupportedpacketfilters, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
......
......@@ -8,31 +8,31 @@
int encode_pdu_address ( PDUAddress pduaddress, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,PDU_ADDRESS_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
ENCODE_U8(buffer+encoded,(uint8_t)(pduaddress.pdu_session_type_value&0x07),encoded);
if ((encode_result = encode_bstring (pduaddress, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
if ((encode_result = encode_bstring (pduaddress.pdu_address_information, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
return encoded;
}
......@@ -40,7 +40,8 @@ int decode_pdu_address ( PDUAddress * pduaddress, uint8_t iei, uint8_t * buffer,
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
int decode_result = 0;
uint8_t bitStream = 0x00;
if (iei > 0)
{
......@@ -48,16 +49,18 @@ int decode_pdu_address ( PDUAddress * pduaddress, uint8_t iei, uint8_t * buffer,
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
DECODE_U8(buffer+decoded,bitStream,decoded);
pduaddress->pdu_session_type_value = bitStream&0x07;
if((decode_result = decode_bstring (pduaddress, ielen, buffer + decoded, len - decoded)) < 0)
if((decode_result = decode_bstring (pduaddress->pdu_address_information, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -4,7 +4,15 @@
#define PDU_ADDRESS_MINIMUM_LENGTH 7
#define PDU_ADDRESS_MAXIMUM_LENGTH 15
typedef bstring PDUAddress;
#define PDU_ADDRESS_IPV4 0x01
#define PDU_ADDRESS_IPV6 0x02
#define PDU_ADDRESS_IPV4V6 0x03
typedef struct{
uint8_t pdu_session_type_value:3;
bstring pdu_address_information;
}PDUAddress;
int encode_pdu_address ( PDUAddress pduaddress, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_pdu_address ( PDUAddress * pduaddress, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
......
......@@ -8,44 +8,99 @@
int encode_qos_rules ( QOSRules qosrules, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
#if 0
uint8_t *lenPtr = NULL;
uint8_t *lenqosrule = NULL;
uint8_t lenmoment = 0;
uint8_t bitstream = 0;
uint16_t lenqosrule_16 = 0;
uint32_t encoded = 0;
int encode_result;
int encode_result = 0;
int i = 0,j = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,QOS_RULES_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
encoded++;
if ((encode_result = encode_bstring (qosrules, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
uint32_t res = encoded - 1 - ((iei > 0) ? 1 : 0);
for(i=0;i<qosrules.numberofqosrulesie;i++)
{
ENCODE_U8(buffer+encoded,qosrules.qosrulesie[i].qosruleidentifer,encoded);
lenqosrule = buffer + encoded;
encoded++;
encoded++;
lenmoment = encoded;
bitstream = (uint8_t)(qosrules.qosrulesie[i].ruleoperationcode << 5);
bitstream |= (uint8_t)(qosrules.qosrulesie[i].dqrbit << 4);
bitstream |= (uint8_t)qosrules.qosrulesie[i].numberofpacketfilters;
ENCODE_U8(buffer+encoded,bitstream,encoded);
if((bitstream >> 5) == MODIFY_EXISTING_QOS_RULE_AND_DELETE_PACKET_FILTERS)
{
for(j = 0;j < (bitstream & 0x0f);j++)
{
ENCODE_U8(buffer+encoded,(uint8_t)qosrules.qosrulesie[i].packetfilterlist.packetfilterdelete[j].packetfilteridentifier,encoded);
}
ENCODE_U8(buffer+encoded,qosrules.qosrulesie[i].qosruleprecedence,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)((qosrules.qosrulesie[i].segregation<<6) | (qosrules.qosrulesie[i].qosflowidentifer & 0x3f)),encoded);
}
else if(((bitstream >> 5) == CREATE_NEW_QOS_RULE) || ((bitstream >> 5) == MODIFY_EXISTING_QOS_RULE_AND_ADD_PACKET_FILTERS) || ((bitstream >> 5) == MODIFY_EXISTING_QOS_RULE_AND_REPLACE_ALL_PACKET_FILTERS))
{
for(j = 0;j < (bitstream & 0x0f);j++)
{
ENCODE_U8(buffer+encoded,(uint8_t)((qosrules.qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfilterdirection << 4)|(qosrules.qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfilteridentifier & 0x0f)),encoded);
uint8_t *lenghtofpacketfiltercontents = buffer + encoded;
encoded++;
if ((encode_result = encode_bstring (qosrules.qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfiltercontents, buffer + encoded, len - encoded)) < 0)
return encode_result;
else
encoded += encode_result;
*lenghtofpacketfiltercontents = encode_result;
}
ENCODE_U8(buffer+encoded,qosrules.qosrulesie[i].qosruleprecedence,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)((qosrules.qosrulesie[i].segregation<<6) | (qosrules.qosrulesie[i].qosflowidentifer & 0x3f)),encoded);
}
lenqosrule_16 = encoded - lenmoment;
*lenqosrule = lenqosrule_16/(1<<8);
lenqosrule++;
*lenqosrule = lenqosrule_16%(1<<8);
}
uint32_t res = encoded - 2 - ((iei > 0) ? 1 : 0);
*lenPtr =res/(1<<8);
lenPtr++;
*lenPtr = res%(1<<8);
return encoded;
#endif
return 0;
}
int decode_qos_rules ( QOSRules * qosrules, uint8_t iei, uint8_t * buffer, uint32_t len )
{
#if 0
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint16_t ielen=0;
int decode_result = 0;
uint16_t allsize = 0;
uint8_t *buffer_tmp = NULL;
uint16_t numberofqosrulesie = 0;
uint16_t lenqosrule = 0;
uint8_t bitstream = 0;
int i=0,j=0;
if (iei > 0)
{
......@@ -60,11 +115,76 @@ int decode_qos_rules ( QOSRules * qosrules, uint8_t iei, uint8_t * buffer, uint3
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
if((decode_result = decode_bstring (qosrules, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
//qosrules->qosrulesie = (QOSRulesIE *)malloc(ielen);
buffer_tmp = buffer + decoded;
//allsize = ielen;
while(allsize < ielen)
{
allsize = *(buffer_tmp+1)+1;
buffer_tmp += allsize;
numberofqosrulesie++;
}
qosrules->numberofqosrulesie = numberofqosrulesie;
qosrules->qosrulesie = (QOSRulesIE *)calloc(qosrules->numberofqosrulesie,sizeof(QOSRulesIE));
for(i=0;i<numberofqosrulesie;i++)
{
DECODE_U8(buffer+decoded,qosrules->qosrulesie[i].qosruleidentifer,decoded);
decoded++;
decoded++;
/*lenqosrule = *(buffer + decoded);
decoded++;
lenqosrule = (lenqosrule << 8)+*(buffer + decoded);
decoded++;
lenmoment = encoded;
*/
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].ruleoperationcode = (bitstream>>5);
qosrules->qosrulesie[i].dqrbit = (bitstream>>4)&0x01;
qosrules->qosrulesie[i].numberofpacketfilters = bitstream&0x0f;
if(qosrules->qosrulesie[i].ruleoperationcode == MODIFY_EXISTING_QOS_RULE_AND_DELETE_PACKET_FILTERS)
{
qosrules->qosrulesie[i].packetfilterlist.packetfilterdelete = (PacketFilterDelete *)calloc(qosrules->qosrulesie[i].numberofpacketfilters,sizeof(PacketFilterDelete));
for(j = 0;j < qosrules->qosrulesie[i].numberofpacketfilters;j++)
{
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].packetfilterlist.packetfilterdelete[j].packetfilteridentifier = bitstream&0x0f;
}
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].qosruleprecedence = bitstream;
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].segregation = (bitstream>>6)&0x01;
qosrules->qosrulesie[i].qosflowidentifer = bitstream&0x3f;
}
else if((qosrules->qosrulesie[i].ruleoperationcode == CREATE_NEW_QOS_RULE) || (qosrules->qosrulesie[i].ruleoperationcode == MODIFY_EXISTING_QOS_RULE_AND_ADD_PACKET_FILTERS) || (qosrules->qosrulesie[i].ruleoperationcode == MODIFY_EXISTING_QOS_RULE_AND_REPLACE_ALL_PACKET_FILTERS))
{
qosrules->qosrulesie[i].packetfilterlist.packetfilternodelete = (PacketFilterNoDelete *)calloc(qosrules->qosrulesie[i].numberofpacketfilters,sizeof(PacketFilterNoDelete));
for(j = 0;j < qosrules->qosrulesie[i].numberofpacketfilters;j++)
{
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfilterdirection = (bitstream>>4)&0x03;
qosrules->qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfilteridentifier = bitstream&0x0f;
uint8_t *lenghtofpacketfiltercontents = *(buffer + decoded);
decoded++;
if ((decode_result = decode_bstring (qosrules->qosrulesie[i].packetfilterlist.packetfilternodelete[j].packetfiltercontents, lenghtofpacketfiltercontents, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
}
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].qosruleprecedence = bitstream;
DECODE_U8(buffer+decoded,bitstream,decoded);
qosrules->qosrulesie[i].segregation = (bitstream>>6)&0x01;
qosrules->qosrulesie[i].qosflowidentifer = bitstream&0x3f;
}
}
return decoded;
#endif
return 0;
}
No preview for this file type
......@@ -8,25 +8,23 @@
int encode_smpdudn_request_container ( SMPDUDNRequestContainer smpdudnrequestcontainer, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,SMPDUDN_REQUEST_CONTAINER_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
if ((encode_result = encode_bstring (smpdudnrequestcontainer, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
......@@ -40,7 +38,7 @@ int decode_smpdudn_request_container ( SMPDUDNRequestContainer * smpdudnrequestc
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
int decode_result = 0;
if (iei > 0)
{
......@@ -58,6 +56,6 @@ int decode_smpdudn_request_container ( SMPDUDNRequestContainer * smpdudnrequestc
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -8,31 +8,48 @@
int encode_snssai ( SNSSAI snssai, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t ielen = 0;
uint8_t bitStream = 0;
uint32_t bit32Stream = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,SNSSAI_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
ielen = snssai.len;
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
*(buffer + encoded) = ielen;
encoded++;
bitStream = snssai.sst;
ENCODE_U8(buffer+encoded,bitStream,encoded);
if((ielen == SST_AND_SD_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT))
{
bit32Stream = snssai.sd;
ENCODE_U8(buffer+encoded,(uint8_t)bit32Stream,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(bit32Stream>>8),encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(bit32Stream>>16),encoded);
}
/*
if ((encode_result = encode_bstring (snssai, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
*/
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
if((ielen == SST_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT))
{
bitStream = snssai.mappedhplmnsst;
ENCODE_U8(buffer+encoded,bitStream,encoded);
}
if(ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT)
{
bit32Stream = snssai.mappedhplmnsd;
ENCODE_U8(buffer+encoded,(uint8_t)bit32Stream,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(bit32Stream>>8),encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(bit32Stream>>16),encoded);
}
return encoded;
}
......@@ -40,7 +57,8 @@ int decode_snssai ( SNSSAI * snssai, uint8_t iei, uint8_t * buffer, uint32_t len
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint8_t bitStream = 0;
uint32_t bit32Stream = 0;
if (iei > 0)
{
......@@ -48,16 +66,42 @@ int decode_snssai ( SNSSAI * snssai, uint8_t iei, uint8_t * buffer, uint32_t len
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
DECODE_U8(buffer+decoded,bitStream,decoded);
snssai->sst = bitStream;
if((ielen == SST_AND_SD_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT))
{
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream = (uint32_t)(bitStream&0Xff);
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream |= (uint32_t)((bitStream<<8)&0xff00);
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream |= (uint32_t)((bitStream<<16)&0xff0000);
snssai->sd = bit32Stream;
}
if((ielen == SST_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_LENGHT) || (ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT))
{
DECODE_U8(buffer+decoded,bitStream,decoded);
snssai->mappedhplmnsst = bitStream;
}
if(ielen == SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT)
{
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream = (uint32_t)(bitStream&0Xff);
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream |= (uint32_t)((bitStream<<8)&0xff00);
DECODE_U8(buffer+decoded,bitStream,decoded);
bit32Stream |= (uint32_t)((bitStream<<16)&0xff0000);
snssai->mappedhplmnsd = bit32Stream;
}
if((decode_result = decode_bstring (snssai, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -7,11 +7,21 @@
#define SNSSAI_MINIMUM_LENGTH 3
#define SNSSAI_MAXIMUM_LENGTH 10
typedef enum{
SST_LENGHT = 0b00000001,
SST_AND_MAPPEDHPLMNSST_LENGHT = 0b00000010,
SST_AND_SD_LENGHT = 0b00000100,
SST_AND_SD_AND_MAPPEDHPLMNSST_LENGHT = 0b00000101,
SST_AND_SD_AND_MAPPEDHPLMNSST_AND_MAPPEDHPLMNSD_LENGHT = 0b00001000
}length_of_snssai_contents;
typedef struct{
uint8_t iei;
uint8_t len;
uint32_t snssai;
uint32_t mapped_nssai;
length_of_snssai_contents len;
uint8_t sst;
uint32_t sd:24;
uint8_t mappedhplmnsst;
uint32_t mappedhplmnsd;
} SNSSAI;
int encode_snssai ( SNSSAI snssai, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
......
......@@ -8,21 +8,17 @@
int encode_ssc_mode ( SSCMode sscmode, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t bitStream = 0x00;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,SSC_MODE_MINIMUM_LENGTH , len);
if ((encode_result = encode_bstring (sscmode, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if(iei > 0){
bitStream |= (iei & 0xf0);
}
bitStream |= (sscmode.ssc_mode_value & 0x07);
ENCODE_U8(buffer+encoded,bitStream,encoded);
return encoded;
......@@ -31,17 +27,21 @@ int encode_ssc_mode ( SSCMode sscmode, uint8_t iei, uint8_t * buffer, uint32_t l
int decode_ssc_mode ( SSCMode * sscmode, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
if((decode_result = decode_bstring (sscmode, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
uint8_t bitStream = 0x00;
DECODE_U8(buffer+decoded,bitStream,decoded);
if(iei != bitStream&0xf0){
return -1;
}
if(iei > 0){
bitStream = (bitStream & 0x07);
}
sscmode->ssc_mode_value = bitStream;
return decoded;
}
#ifndef _SSCMODE_H_
#define _SSCMODE_H_
#include <stdint.h>
#include "bstrlib.h"
#define SSC_MODE_MINIMUM_LENGTH 1
#define SSC_MODE_MAXIMUM_LENGTH 1
typedef bstring SSCMode;
typedef struct{
uint8_t ssc_mode_value:3;
}SSCMode;
int encode_ssc_mode ( SSCMode sscmode, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_ssc_mode ( SSCMode * sscmode, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -8,31 +8,29 @@
int encode_session_ambr ( SessionAMBR sessionambr, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,SESSION_AMBR_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
ENCODE_U8(buffer+encoded,sessionambr.uint_for_session_ambr_for_downlink,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(sessionambr.session_ambr_for_downlink&0x00ff),encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(sessionambr.session_ambr_for_downlink&0xff00),encoded);
ENCODE_U8(buffer+encoded,sessionambr.uint_for_session_ambr_for_uplink,encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(sessionambr.session_ambr_for_uplink&0x00ff),encoded);
ENCODE_U8(buffer+encoded,(uint8_t)(sessionambr.session_ambr_for_uplink&0xff00),encoded);
if ((encode_result = encode_bstring (sessionambr, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
return encoded;
}
......@@ -40,7 +38,8 @@ int decode_session_ambr ( SessionAMBR * sessionambr, uint8_t iei, uint8_t * buff
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
uint8_t bit8Stream = 0;
uint16_t bit16Stream = 0;
if (iei > 0)
{
......@@ -48,16 +47,29 @@ int decode_session_ambr ( SessionAMBR * sessionambr, uint8_t iei, uint8_t * buff
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
CHECK_LENGTH_DECODER (len - decoded, ielen);
if((decode_result = decode_bstring (sessionambr, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
sessionambr->uint_for_session_ambr_for_downlink = bit8Stream;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream = (uint16_t)bit8Stream & 0xff;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream |= (uint16_t)(bit8Stream << 8);
sessionambr->session_ambr_for_downlink = bit16Stream;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
sessionambr->uint_for_session_ambr_for_uplink = bit8Stream;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream = (uint16_t)bit8Stream & 0xff;
DECODE_U8(buffer+decoded,bit8Stream,decoded);
bit16Stream |= (uint16_t)(bit8Stream << 8);
sessionambr->session_ambr_for_uplink = bit16Stream;
return decoded;
}
#ifndef _SESSIONAMBR_H_
#define _SESSIONAMBR_H_
#include <stdint.h>
#include "bstrlib.h"
#define SESSION_AMBR_MINIMUM_LENGTH 8
#define SESSION_AMBR_MAXIMUM_LENGTH 8
typedef bstring SessionAMBR;
//typedef bstring SessionAMBR;
typedef struct{
uint8_t uint_for_session_ambr_for_downlink;
uint16_t session_ambr_for_downlink;
uint8_t uint_for_session_ambr_for_uplink;
uint16_t session_ambr_for_uplink;
}SessionAMBR;
int encode_session_ambr ( SessionAMBR sessionambr, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode_session_ambr ( SessionAMBR * sessionambr, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -8,31 +8,36 @@
int encode__5gsm_capability ( _5GSMCapability _5gsmcapability, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint8_t *lenPtr = NULL;
uint32_t encoded = 0;
int encode_result;
uint8_t _5gsmcapability_bits = 0;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,_5GSM_CAPABILITY_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if( iei >0 )
{
*buffer=iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded++;
if ((encode_result = encode_bstring (_5gsmcapability, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
if(_5gsmcapability.is_MPTCP_supported)
_5gsmcapability_bits |= 0X10;
if(_5gsmcapability.is_ATSLL_supported)
_5gsmcapability_bits |= 0X08;
if(_5gsmcapability.is_EPTS1_supported)
_5gsmcapability_bits |= 0X04;
if(_5gsmcapability.is_MH6PDU_supported)
_5gsmcapability_bits |= 0X02;
if(_5gsmcapability.is_Rqos_supported)
_5gsmcapability_bits |= 0X01;
ENCODE_U8(buffer+encoded, _5gsmcapability_bits, encoded);
*lenPtr = encoded - 1 - ((iei > 0) ? 1 : 0);
return encoded;
}
......@@ -40,7 +45,9 @@ int decode__5gsm_capability ( _5GSMCapability * _5gsmcapability, uint8_t iei, ui
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
int decode_result = 0;
uint8_t _5gsmcapability_bits = 0;
if (iei > 0)
{
......@@ -54,10 +61,34 @@ int decode__5gsm_capability ( _5GSMCapability * _5gsmcapability, uint8_t iei, ui
CHECK_LENGTH_DECODER (len - decoded, ielen);
if((decode_result = decode_bstring (_5gsmcapability, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
DECODE_U8(buffer+decoded,_5gsmcapability_bits,decoded);
if(_5gsmcapability_bits & 0x10)
_5gsmcapability->is_MPTCP_supported = true;
else
_5gsmcapability->is_MPTCP_supported = false;
if(_5gsmcapability_bits & 0x08)
_5gsmcapability->is_ATSLL_supported = true;
else
_5gsmcapability->is_ATSLL_supported = false;
if(_5gsmcapability_bits & 0x04)
_5gsmcapability->is_EPTS1_supported = true;
else
_5gsmcapability->is_EPTS1_supported = false;
if(_5gsmcapability_bits & 0x02)
_5gsmcapability->is_MH6PDU_supported = true;
else
_5gsmcapability->is_MH6PDU_supported = false;
if(_5gsmcapability_bits & 0x01)
_5gsmcapability->is_Rqos_supported = true;
else
decoded += decode_result;
return decoded;
_5gsmcapability->is_Rqos_supported = false;
return decoded;
}
#ifndef __5GSMCAPABILITY_H_
#define __5GSMCAPABILITY_H_
#include <stdint.h>
#include <stdbool.h>
#include "bstrlib.h"
#define _5GSM_CAPABILITY_MINIMUM_LENGTH 3
#define _5GSM_CAPABILITY_MAXIMUM_LENGTH 15
typedef bstring _5GSMCapability;
#define REFLECTIVE_QOS_NOT_SUPPORTED 0
#define REFLECTIVE_QOS_SUPPORTED 1
#define MULTI_HOMED_IPV6_PDU_SESSION_NOT_SUPPORTED 0
#define MULTI_HOMED_IPV6_PDU_SESSION_SUPPORTED 1
#define ETHERNET_PDN_TYPE_IN_S1_MODE_NOT_SUPPORTED 0
#define ETHERNET_PDN_TYPE_IN_S1_MODE_SUPPORTED 1
#define EATSSS_LOW_LAYER_FUNCTIONALITY_NOT_SUPPORTED 0
#define EATSSS_LOW_LAYER_FUNCTIONALITY_SUPPORTED 1
#define MPTCP_FUNCTIONALITY_NOT_SUPPORTED 0
#define MPTCP_FUNCTIONALITY_SUPPORTED 1
typedef struct{
bool is_Rqos_supported;
bool is_MH6PDU_supported;
bool is_EPTS1_supported;
bool is_ATSLL_supported;
bool is_MPTCP_supported;
//bstring _5GSMCapability_spare;
}_5GSMCapability;
int encode__5gsm_capability ( _5GSMCapability _5gsmcapability, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode__5gsm_capability ( _5GSMCapability * _5gsmcapability, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
......@@ -8,27 +8,18 @@
int encode__5gsm_cause ( _5GSMCause _5gsmcause, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,_5GSM_CAUSE_MINIMUM_LENGTH , len);
if( iei >0 )
{
*buffer=iei;
encoded++;
}
if ((encode_result = encode_bstring (_5gsmcause, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
if( iei > 0 )
{
*buffer=iei;
encoded++;
}
ENCODE_U8(buffer+encoded,_5gsmcause,encoded);
return encoded;
}
......@@ -36,22 +27,15 @@ int encode__5gsm_cause ( _5GSMCause _5gsmcause, uint8_t iei, uint8_t * buffer, u
int decode__5gsm_cause ( _5GSMCause * _5gsmcause, uint8_t iei, uint8_t * buffer, uint32_t len )
{
int decoded=0;
uint8_t ielen=0;
int decode_result;
if (iei > 0)
if( iei > 0 )
{
CHECK_IEI_DECODER (iei, *buffer);
decoded++;
}
DECODE_U8(buffer+decoded,*_5gsmcause,decoded);
if((decode_result = decode_bstring (_5gsmcause, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
return decoded;
}
......@@ -4,7 +4,7 @@
#define _5GSM_CAUSE_MINIMUM_LENGTH 2
#define _5GSM_CAUSE_MAXIMUM_LENGTH 2
typedef bstring _5GSMCause;
typedef uint8_t _5GSMCause;
int encode__5gsm_cause ( _5GSMCause _5gsmcause, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode__5gsm_cause ( _5GSMCause * _5gsmcause, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
......
......@@ -6,58 +6,41 @@
#include "TLVDecoder.h"
#include "_PDUSessionType.h"
int encode__pdu_session_type ( _PDUSessionType _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len )
int encode__pdu_session_type ( _PDUSessionType _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len )
{
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
uint8_t bitStream = 0x00;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER (buffer,_PDU_SESSION_TYPE_MINIMUM_LENGTH , len);
if(iei > 0){
bitStream |= (iei & 0xf0);
}
bitStream |= (_pdusessiontype.pdu_session_type_value & 0x07);
ENCODE_U8(buffer+encoded,bitStream,encoded);
/*
if ((encode_result = encode_bstring (_pdusessiontype, buffer + encoded, len - encoded)) < 0)//加密,实体,首地址,长度
return encode_result;
else
encoded += encode_result;
return encoded;
*/
*(buffer + encoded) = 0x00 | (iei & 0xf0) | (_pdusessiontype & 0x7);
encoded++;
return encoded;
}
int decode__pdu_session_type ( _PDUSessionType * _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len )
int decode__pdu_session_type ( _PDUSessionType * _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len )
{
/*
int decoded=0;
uint8_t ielen=0;
int decode_result;
if((decode_result = decode_bstring (_pdusessiontype, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
return decoded;
*/
int decoded = 0;
*_pdusessiontype = *buffer & 0x7;
decoded++;
return decoded;
uint8_t bitStream = 0x00;
DECODE_U8(buffer+decoded,bitStream,decoded);
if(iei != bitStream&0xf0){
return -1;
}
if(iei > 0){
bitStream = (bitStream & 0x07);
}
_pdusessiontype->pdu_session_type_value = bitStream;
return decoded;
}
#ifndef __PDUSessionType_H_
#define __PDUSessionType_H_
#include <stdint.h>
#include "bstrlib.h"
#define _PDU_SESSION_TYPE_MINIMUM_LENGTH 1
#define _PDU_SESSION_TYPE_MAXIMUM_LENGTH 1
typedef uint8_t _PDUSessionType;
typedef struct {
uint8_t pdu_session_type_value:3;
} _PDUSessionType;
int encode__pdu_session_type ( _PDUSessionType _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
int decode__pdu_session_type ( _PDUSessionType * _pdusessiontype, uint8_t iei, uint8_t * buffer, uint32_t len ) ;
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment