src/lte/model/lte-asn1-header.cc
author Tom Henderson <tomh@tomh.org>
Thu, 17 Aug 2017 08:15:32 -0700
changeset 13047 a39655894155
parent 11274 609de51c9b88
child 13300 9c62f5c32658
permissions -rw-r--r--
uan: Rescan python bindings
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Lluis Parcerisa <lparcerisa@cttc.cat>
    19  */
    20 
    21 #include "ns3/log.h"
    22 #include "ns3/lte-asn1-header.h"
    23 
    24 #include <stdio.h>
    25 #include <sstream>
    26 #include <cmath>
    27 
    28 namespace ns3 {
    29 
    30 NS_LOG_COMPONENT_DEFINE ("Asn1Header");
    31 
    32 NS_OBJECT_ENSURE_REGISTERED (Asn1Header);
    33 
    34 TypeId
    35 Asn1Header::GetTypeId (void)
    36 {
    37   static TypeId tid = TypeId ("ns3::Asn1Header")
    38     .SetParent<Header> ()
    39     .SetGroupName("Lte")
    40   ;
    41   return tid;
    42 }
    43 
    44 TypeId
    45 Asn1Header::GetInstanceTypeId (void) const
    46 {
    47   return GetTypeId ();
    48 }
    49 
    50 Asn1Header::Asn1Header ()
    51 {
    52   m_serializationPendingBits = 0x00;
    53   m_numSerializationPendingBits = 0;
    54   m_isDataSerialized = false;
    55 }
    56 
    57 Asn1Header::~Asn1Header ()
    58 {
    59 }
    60 
    61 uint32_t
    62 Asn1Header::GetSerializedSize (void) const
    63 {
    64   if (!m_isDataSerialized)
    65     {
    66       PreSerialize ();
    67     }
    68   return m_serializationResult.GetSize ();
    69 }
    70 
    71 void Asn1Header::Serialize (Buffer::Iterator bIterator) const
    72 {
    73   if (!m_isDataSerialized)
    74     {
    75       PreSerialize ();
    76     }
    77   bIterator.Write (m_serializationResult.Begin (),m_serializationResult.End ());
    78 }
    79 
    80 void Asn1Header::WriteOctet (uint8_t octet) const
    81 {
    82   m_serializationResult.AddAtEnd (1);
    83   Buffer::Iterator bIterator = m_serializationResult.End ();
    84   bIterator.Prev ();
    85   bIterator.WriteU8 (octet);
    86 }
    87 
    88 template <int N>
    89 void Asn1Header::SerializeBitset (std::bitset<N> data) const
    90 {
    91 
    92   size_t dataSize = data.size ();
    93   uint8_t pendingBits = dataSize;
    94   uint8_t mask = 1;
    95   int j;
    96 
    97   // No extension marker (Clause 16.7 ITU-T X.691),
    98   // as 3GPP TS 36.331 does not use it in its IE's.
    99 
   100   // Clause 16.8 ITU-T X.691
   101   if (dataSize == 0)
   102     {
   103       return;
   104     }
   105 
   106   // Clause 16.9 ITU-T X.691
   107   // Clause 16.10 ITU-T X.691
   108   if (dataSize <= 65536)
   109     {
   110       // If there are bits pending to be processed,
   111       // append first bits in data to complete an octet.
   112       if (m_numSerializationPendingBits > 0)
   113         {
   114           mask = 0x80 >> m_numSerializationPendingBits;
   115           while (pendingBits > 0 && m_numSerializationPendingBits < 8)
   116             {
   117               m_serializationPendingBits |= (data[pendingBits - 1]) ? mask : 0;
   118               pendingBits--;
   119               m_numSerializationPendingBits++;
   120               mask = (mask >> 1) & (~mask);
   121             }
   122 
   123           if (m_numSerializationPendingBits >= 8)
   124             {
   125               WriteOctet (m_serializationPendingBits);
   126               m_numSerializationPendingBits = 0;
   127               m_serializationPendingBits = 0;
   128             }
   129         }
   130 
   131       while (pendingBits > 0)
   132         {
   133           mask = 1;
   134           j = 8;
   135 
   136           // If there are less than 8 remaining bits,
   137           // store it to m_serializationPendingBits.
   138           if (pendingBits < 8)
   139             {
   140               mask = 0x80;
   141               m_numSerializationPendingBits = pendingBits;
   142               while (pendingBits > 0)
   143                 {
   144                   m_serializationPendingBits |= (data[pendingBits - 1]) ? mask : 0;
   145                   mask = (mask >> 1) & (~mask);
   146                   pendingBits--;
   147                 }
   148             }
   149 
   150           // Write the data to buffer
   151           else
   152             {
   153               uint8_t octetToWrite = 0;
   154               for (; j > 0; j--)
   155                 {
   156                   octetToWrite |= (data[pendingBits - j]) ? mask : 0;
   157                   mask = (mask << 1) & (~mask);
   158                 }
   159               WriteOctet (octetToWrite);
   160               pendingBits -= 8;
   161             }
   162         }
   163     }
   164 
   165   // Clause 16.11 ITU-T X.691
   166   else
   167     {
   168       printf ("FRAGMENTATION NEEDED!\n");
   169     }
   170 }
   171 
   172 template <int N>
   173 void Asn1Header::SerializeBitstring (std::bitset<N> data) const
   174 {
   175   SerializeBitset<N> (data);
   176 }
   177 
   178 
   179 void Asn1Header::SerializeBitstring (std::bitset<1> data) const
   180 {
   181   SerializeBitstring<1> (data);
   182 }
   183 
   184 void Asn1Header::SerializeBitstring (std::bitset<2> data) const
   185 {
   186   SerializeBitstring<2> (data);
   187 }
   188 
   189 void Asn1Header::SerializeBitstring (std::bitset<8> data) const
   190 {
   191   SerializeBitstring<8> (data);
   192 }
   193 
   194 void Asn1Header::SerializeBitstring (std::bitset<10> data) const
   195 {
   196   SerializeBitstring<10> (data);
   197 }
   198 
   199 void Asn1Header::SerializeBitstring (std::bitset<16> data) const
   200 {
   201   SerializeBitstring<16> (data);
   202 }
   203 
   204 void Asn1Header::SerializeBitstring (std::bitset<27> data) const
   205 {
   206   SerializeBitstring<27> (data);
   207 }
   208 
   209 void Asn1Header::SerializeBitstring (std::bitset<28> data) const
   210 {
   211   SerializeBitstring<28> (data);
   212 }
   213 
   214 void Asn1Header::SerializeBitstring (std::bitset<32> data) const
   215 {
   216   SerializeBitstring<32> (data);
   217 }
   218 
   219 void Asn1Header::SerializeBoolean (bool value) const
   220 {
   221   // Clause 12 ITU-T X.691
   222   std::bitset<1> val;
   223   (value) ? val.set () : val.reset ();
   224   SerializeBitset<1> (val);
   225 }
   226 
   227 template <int N>
   228 void Asn1Header::SerializeSequence (std::bitset<N> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   229 {
   230   if (isExtensionMarkerPresent)
   231     {
   232       // Extension marker present, but no extension
   233       SerializeBoolean (false);
   234     }
   235   SerializeBitstring<N> (optionalOrDefaultMask);
   236 }
   237 
   238 void Asn1Header::SerializeSequence (std::bitset<0> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   239 {
   240   SerializeSequence<0> (optionalOrDefaultMask,isExtensionMarkerPresent);
   241 }
   242 
   243 void Asn1Header::SerializeSequence (std::bitset<1> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   244 {
   245   SerializeSequence<1> (optionalOrDefaultMask,isExtensionMarkerPresent);
   246 }
   247 
   248 void Asn1Header::SerializeSequence (std::bitset<2> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   249 {
   250   SerializeSequence<2> (optionalOrDefaultMask,isExtensionMarkerPresent);
   251 }
   252 
   253 void Asn1Header::SerializeSequence (std::bitset<3> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   254 {
   255   SerializeSequence<3> (optionalOrDefaultMask,isExtensionMarkerPresent);
   256 }
   257 
   258 void Asn1Header::SerializeSequence (std::bitset<4> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   259 {
   260   SerializeSequence<4> (optionalOrDefaultMask,isExtensionMarkerPresent);
   261 }
   262 
   263 void Asn1Header::SerializeSequence (std::bitset<5> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   264 {
   265   SerializeSequence<5> (optionalOrDefaultMask,isExtensionMarkerPresent);
   266 }
   267 
   268 void Asn1Header::SerializeSequence (std::bitset<6> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   269 {
   270   SerializeSequence<6> (optionalOrDefaultMask,isExtensionMarkerPresent);
   271 }
   272 
   273 void Asn1Header::SerializeSequence (std::bitset<7> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   274 {
   275   SerializeSequence<7> (optionalOrDefaultMask,isExtensionMarkerPresent);
   276 }
   277 
   278 void Asn1Header::SerializeSequence (std::bitset<9> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   279 {
   280   SerializeSequence<9> (optionalOrDefaultMask,isExtensionMarkerPresent);
   281 }
   282 
   283 void Asn1Header::SerializeSequence (std::bitset<10> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   284 {
   285   SerializeSequence<10> (optionalOrDefaultMask,isExtensionMarkerPresent);
   286 }
   287 
   288 void Asn1Header::SerializeSequence (std::bitset<11> optionalOrDefaultMask, bool isExtensionMarkerPresent) const
   289 {
   290   SerializeSequence<11> (optionalOrDefaultMask,isExtensionMarkerPresent);
   291 }
   292 
   293 void Asn1Header::SerializeSequenceOf (int numElems, int nMax, int nMin) const
   294 {
   295   // Clause 20.6 ITU-T X.691
   296   SerializeInteger (numElems, nMin, nMax);
   297 }
   298 
   299 void Asn1Header::SerializeEnum (int numElems, int selectedElem) const
   300 {
   301   // Clause 14 ITU-T X.691
   302   SerializeInteger (selectedElem, 0, numElems - 1);
   303 }
   304 
   305 void Asn1Header::SerializeChoice (int numOptions, int selectedOption, bool isExtensionMarkerPresent) const
   306 {
   307   if(isExtensionMarkerPresent)
   308   {
   309     // Never extended attributes
   310     SerializeBoolean(false);
   311   }
   312   
   313   // Clause 23.4 ITU-T X.691
   314   if (numOptions < 2)
   315     {
   316       return;
   317     }
   318 
   319   SerializeInteger (selectedOption,0,numOptions - 1);
   320 }
   321 
   322 void Asn1Header::SerializeInteger (int n, int nmin, int nmax) const
   323 {
   324   // Misusage check: Ensure nmax>nmin ...
   325   if (nmin > nmax)
   326     {
   327       int aux = nmin;
   328       nmin = nmax;
   329       nmax = aux;
   330     }
   331 
   332   // Clause 11.5.3 ITU-T X.691
   333   int range = nmax - nmin + 1;
   334   // Substract nmin to n
   335   n -= nmin;
   336 
   337   // Clause 11.5.4 ITU-T X.691
   338   if (range <= 1)
   339     {
   340       return;
   341     }
   342 
   343   // Clause 11.5.6 ITU-T X.691
   344   int requiredBits = std::ceil (std::log (range) / std::log (2.0));
   345 
   346   switch (requiredBits)
   347     {
   348     case 1:
   349       SerializeBitset<1> (std::bitset<1> (n));
   350       break;
   351     case 2:
   352       SerializeBitset<2> (std::bitset<2> (n));
   353       break;
   354     case 3:
   355       SerializeBitset<3> (std::bitset<3> (n));
   356       break;
   357     case 4:
   358       SerializeBitset<4> (std::bitset<4> (n));
   359       break;
   360     case 5:
   361       SerializeBitset<5> (std::bitset<5> (n));
   362       break;
   363     case 6:
   364       SerializeBitset<6> (std::bitset<6> (n));
   365       break;
   366     case 7:
   367       SerializeBitset<7> (std::bitset<7> (n));
   368       break;
   369     case 8:
   370       SerializeBitset<8> (std::bitset<8> (n));
   371       break;
   372     case 9:
   373       SerializeBitset<9> (std::bitset<9> (n));
   374       break;
   375     case 10:
   376       SerializeBitset<10> (std::bitset<10> (n));
   377       break;
   378     case 11:
   379       SerializeBitset<11> (std::bitset<11> (n));
   380       break;
   381     case 12:
   382       SerializeBitset<12> (std::bitset<12> (n));
   383       break;
   384     case 13:
   385       SerializeBitset<13> (std::bitset<13> (n));
   386       break;
   387     case 14:
   388       SerializeBitset<14> (std::bitset<14> (n));
   389       break;
   390     case 15:
   391       SerializeBitset<15> (std::bitset<15> (n));
   392       break;
   393     case 16:
   394       SerializeBitset<16> (std::bitset<16> (n));
   395       break;
   396     case 17:
   397       SerializeBitset<17> (std::bitset<17> (n));
   398       break;
   399     case 18:
   400       SerializeBitset<18> (std::bitset<18> (n));
   401       break;
   402     case 19:
   403       SerializeBitset<19> (std::bitset<19> (n));
   404       break;
   405     case 20:
   406       SerializeBitset<20> (std::bitset<20> (n));
   407       break;
   408     default:
   409       {
   410         std::cout << "SerializeInteger " << requiredBits << " Out of range!!" << std::endl;
   411         exit (1);
   412       }
   413     }
   414 }
   415 
   416 void Asn1Header::SerializeNull () const
   417 {
   418   // Clause 18 ITU-T X.691
   419   return;
   420 }
   421 
   422 void Asn1Header::FinalizeSerialization () const
   423 {
   424   if (m_numSerializationPendingBits > 0)
   425     {
   426       m_numSerializationPendingBits = 0;
   427       SerializeBitset<8> (std::bitset<8> (m_serializationPendingBits));
   428     }
   429   m_isDataSerialized = true;
   430 }
   431 
   432 template <int N>
   433 Buffer::Iterator Asn1Header::DeserializeBitset (std::bitset<N> *data, Buffer::Iterator bIterator)
   434 {
   435 
   436   int bitsToRead = N;
   437   uint8_t mask;
   438 
   439   // Read bits from pending bits
   440   if (m_numSerializationPendingBits > 0)
   441     {
   442       while (bitsToRead > 0 && m_numSerializationPendingBits > 0)
   443         {
   444           data->set (bitsToRead - 1,(m_serializationPendingBits & 0x80) ? 1 : 0);
   445           bitsToRead--;
   446           m_numSerializationPendingBits--;
   447           m_serializationPendingBits = m_serializationPendingBits << 1;
   448         }
   449     }
   450 
   451   // Read bits from buffer
   452   while (bitsToRead > 0)
   453     {
   454       uint8_t octet = bIterator.ReadU8 ();
   455       // If 8 bits can be allocated to the bitset, set the bits
   456       if (bitsToRead >= 8)
   457         {
   458           mask = 0x80;
   459           for (int j = 0; j < 8; j++)
   460             {
   461               data->set (bitsToRead - 1,(octet & mask) ? 1 : 0);
   462               bitsToRead--;
   463               mask = mask >> 1;
   464             }
   465         }
   466 
   467       // Otherwise, we'll have to save the remaining bits
   468       else
   469         {
   470           mask = 0x80;
   471           m_numSerializationPendingBits = 8 - bitsToRead;
   472           m_serializationPendingBits = octet << bitsToRead;
   473           while (bitsToRead > 0)
   474             {
   475               data->set (bitsToRead - 1,(octet & mask) ? 1 : 0);
   476               bitsToRead--;
   477               mask = mask >> 1;
   478             }
   479         }
   480     }
   481 
   482   return bIterator;
   483 }
   484 
   485 template <int N>
   486 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<N> *data, Buffer::Iterator bIterator)
   487 {
   488   return DeserializeBitset<N> (data,bIterator);
   489 }
   490 
   491 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<1> *data, Buffer::Iterator bIterator)
   492 {
   493   return DeserializeBitstring<1> (data,bIterator);
   494 }
   495 
   496 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<2> *data, Buffer::Iterator bIterator)
   497 {
   498   return DeserializeBitstring<2> (data,bIterator);
   499 }
   500 
   501 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<8> *data, Buffer::Iterator bIterator)
   502 {
   503   return DeserializeBitstring<8> (data,bIterator);
   504 }
   505 
   506 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<10> *data, Buffer::Iterator bIterator)
   507 {
   508   return DeserializeBitstring<10> (data,bIterator);
   509 }
   510 
   511 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<16> *data, Buffer::Iterator bIterator)
   512 {
   513   return DeserializeBitstring<16> (data,bIterator);
   514 }
   515 
   516 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<27> *data, Buffer::Iterator bIterator)
   517 {
   518   return DeserializeBitstring<27> (data,bIterator);
   519 }
   520 
   521 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<28> *data, Buffer::Iterator bIterator)
   522 {
   523   return DeserializeBitstring<28> (data,bIterator);
   524 }
   525 
   526 Buffer::Iterator Asn1Header::DeserializeBitstring (std::bitset<32> *data, Buffer::Iterator bIterator)
   527 {
   528   return DeserializeBitstring<32> (data,bIterator);
   529 }
   530 
   531 Buffer::Iterator Asn1Header::DeserializeBoolean (bool *value, Buffer::Iterator bIterator)
   532 {
   533   std::bitset<1> readBit;
   534   bIterator = DeserializeBitset<1> (&readBit,bIterator);
   535   *value = (readBit[0] == 1) ? true : false;
   536   return bIterator;
   537 }
   538 
   539 Buffer::Iterator Asn1Header::DeserializeInteger (int *n, int nmin, int nmax, Buffer::Iterator bIterator)
   540 {
   541   // Misusage check: Ensure nmax>nmin ...
   542   if (nmin > nmax)
   543     {
   544       int aux = nmin;
   545       nmin = nmax;
   546       nmax = aux;
   547     }
   548 
   549   int range = nmax - nmin + 1;
   550 
   551   if (range == 1)
   552     {
   553       return bIterator;
   554     }
   555 
   556   int requiredBits = std::ceil (std::log (range) / std::log (2.0));
   557 
   558   std::bitset<1> bitsRead1;
   559   std::bitset<2> bitsRead2;
   560   std::bitset<3> bitsRead3;
   561   std::bitset<4> bitsRead4;
   562   std::bitset<5> bitsRead5;
   563   std::bitset<6> bitsRead6;
   564   std::bitset<7> bitsRead7;
   565   std::bitset<8> bitsRead8;
   566   std::bitset<9> bitsRead9;
   567   std::bitset<10> bitsRead10;
   568   std::bitset<11> bitsRead11;
   569   std::bitset<12> bitsRead12;
   570   std::bitset<13> bitsRead13;
   571   std::bitset<14> bitsRead14;
   572   std::bitset<15> bitsRead15;
   573   std::bitset<16> bitsRead16;
   574   std::bitset<17> bitsRead17;
   575   std::bitset<18> bitsRead18;
   576   std::bitset<19> bitsRead19;
   577   std::bitset<20> bitsRead20;
   578 
   579   switch (requiredBits)
   580     {
   581     case 1:
   582       bIterator = DeserializeBitset<1> (&bitsRead1,bIterator);
   583       *n = (int)bitsRead1.to_ulong ();
   584       break;
   585     case 2: 
   586       bIterator = DeserializeBitset<2> (&bitsRead2,bIterator);
   587       *n = (int)bitsRead2.to_ulong ();
   588       break;
   589     case 3: 
   590       bIterator = DeserializeBitset<3> (&bitsRead3,bIterator);
   591       *n = (int)bitsRead3.to_ulong ();
   592       break;
   593     case 4: 
   594       bIterator = DeserializeBitset<4> (&bitsRead4,bIterator);
   595       *n = (int)bitsRead4.to_ulong ();
   596       break;
   597     case 5:
   598       bIterator = DeserializeBitset<5> (&bitsRead5,bIterator);
   599       *n = (int)bitsRead5.to_ulong ();
   600       break;
   601     case 6:
   602       bIterator = DeserializeBitset<6> (&bitsRead6,bIterator);
   603       *n = (int)bitsRead6.to_ulong ();
   604       break;
   605     case 7:
   606       bIterator = DeserializeBitset<7> (&bitsRead7,bIterator);
   607       *n = (int)bitsRead7.to_ulong ();
   608       break;
   609     case 8:
   610       bIterator = DeserializeBitset<8> (&bitsRead8,bIterator);
   611       *n = (int)bitsRead8.to_ulong ();
   612       break;
   613     case 9:
   614       bIterator = DeserializeBitset<9> (&bitsRead9,bIterator);
   615       *n = (int)bitsRead9.to_ulong ();
   616       break;
   617     case 10:
   618       bIterator = DeserializeBitset<10> (&bitsRead10,bIterator);
   619       *n = (int)bitsRead10.to_ulong ();
   620       break;
   621     case 11:
   622       bIterator = DeserializeBitset<11> (&bitsRead11,bIterator);
   623       *n = (int)bitsRead11.to_ulong ();
   624       break;
   625     case 12:
   626       bIterator = DeserializeBitset<12> (&bitsRead12,bIterator);
   627       *n = (int)bitsRead12.to_ulong ();
   628       break;
   629     case 13:
   630       bIterator = DeserializeBitset<13> (&bitsRead13,bIterator);
   631       *n = (int)bitsRead13.to_ulong ();
   632       break;
   633     case 14:
   634       bIterator = DeserializeBitset<14> (&bitsRead14,bIterator);
   635       *n = (int)bitsRead14.to_ulong ();
   636       break;
   637     case 15:
   638       bIterator = DeserializeBitset<15> (&bitsRead15,bIterator);
   639       *n = (int)bitsRead15.to_ulong ();
   640       break;
   641     case 16:
   642       bIterator = DeserializeBitset<16> (&bitsRead16,bIterator);
   643       *n = (int)bitsRead16.to_ulong ();
   644       break;
   645     case 17:
   646       bIterator = DeserializeBitset<17> (&bitsRead17,bIterator);
   647       *n = (int)bitsRead17.to_ulong ();
   648       break;
   649     case 18:
   650       bIterator = DeserializeBitset<18> (&bitsRead18,bIterator);
   651       *n = (int)bitsRead18.to_ulong ();
   652       break;
   653     case 19:
   654       bIterator = DeserializeBitset<19> (&bitsRead19,bIterator);
   655       *n = (int)bitsRead19.to_ulong ();
   656       break;
   657     case 20:
   658       bIterator = DeserializeBitset<20> (&bitsRead20,bIterator);
   659       *n = (int)bitsRead20.to_ulong ();
   660       break;
   661     default:
   662       {
   663         std::cout << "SerializeInteger Out of range!!" << std::endl;
   664         exit (1);
   665       }
   666     }
   667 
   668   *n += nmin;
   669 
   670   return bIterator;
   671 }
   672 
   673 Buffer::Iterator Asn1Header::DeserializeChoice (int numOptions, bool isExtensionMarkerPresent, int *selectedOption, Buffer::Iterator bIterator)
   674 {
   675   if (isExtensionMarkerPresent)
   676   {
   677     bool marker;
   678     bIterator = DeserializeBoolean (&marker,bIterator);
   679   }
   680   return DeserializeInteger (selectedOption,0,numOptions - 1,bIterator);
   681 }
   682 
   683 Buffer::Iterator Asn1Header::DeserializeEnum (int numElems, int *selectedElem, Buffer::Iterator bIterator)
   684 {
   685   return DeserializeInteger (selectedElem,0,numElems - 1,bIterator);
   686 }
   687 
   688 template <int N>
   689 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<N> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   690 {
   691   if (isExtensionMarkerPresent)
   692     {
   693       bool dummy;
   694       bIterator = DeserializeBoolean (&dummy,bIterator);
   695     }
   696   bIterator = DeserializeBitset<N> (optionalOrDefaultMask,bIterator);
   697   return bIterator;
   698 }
   699 
   700 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<0> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   701 {
   702   return DeserializeSequence<0> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   703 }
   704 
   705 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<1> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   706 {
   707   return DeserializeSequence<1> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   708 }
   709 
   710 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<2> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   711 {
   712   return DeserializeSequence<2> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   713 }
   714 
   715 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<3> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   716 {
   717   return DeserializeSequence<3> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   718 }
   719 
   720 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<4> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   721 {
   722   return DeserializeSequence<4> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   723 }
   724 
   725 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<5> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   726 {
   727   return DeserializeSequence<5> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   728 }
   729 
   730 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<6> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   731 {
   732   return DeserializeSequence<6> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   733 }
   734 
   735 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<7> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   736 {
   737   return DeserializeSequence<7> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   738 }
   739 
   740 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<9> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   741 {
   742   return DeserializeSequence<9> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   743 }
   744 
   745 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<10> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   746 {
   747   return DeserializeSequence<10> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   748 }
   749 
   750 Buffer::Iterator Asn1Header::DeserializeSequence (std::bitset<11> *optionalOrDefaultMask, bool isExtensionMarkerPresent, Buffer::Iterator bIterator)
   751 {
   752   return DeserializeSequence<11> (optionalOrDefaultMask,isExtensionMarkerPresent,bIterator);
   753 }
   754 
   755 Buffer::Iterator Asn1Header::DeserializeNull (Buffer::Iterator bIterator)
   756 {
   757   return bIterator;
   758 }
   759 
   760 Buffer::Iterator Asn1Header::DeserializeSequenceOf (int *numElems, int nMax, int nMin, Buffer::Iterator bIterator)
   761 {
   762   return DeserializeInteger (numElems,nMin,nMax,bIterator);
   763 }
   764 
   765 } // namespace ns3