Browse Source

UserPriority TLV 22.11.1 is now properly encoded as dual int.

AdrianSimionov 10 years ago
parent
commit
0559f8af5e
5 changed files with 37 additions and 2 deletions
  1. 9 0
      src/docsis_decode.c
  2. 1 0
      src/docsis_decode.h
  3. 25 0
      src/docsis_encode.c
  4. 1 0
      src/docsis_encode.h
  5. 1 2
      src/docsis_symtable.h

+ 9 - 0
src/docsis_decode.c

@@ -129,6 +129,15 @@ void decode_dual_qtag (unsigned char *tlvbuf, symbol_type *sym, size_t length )
     printf("%s %d,%d;\n", sym->sym_ident, tlvbuf[0] * 256 + tlvbuf[1], tlvbuf[2]*256 + tlvbuf[3]);
 }
 
+void decode_dual_int (unsigned char *tlvbuf, symbol_type *sym, size_t length )
+{
+    if (length != 2 ) {
+        fprintf(stderr, "dual integers length mismatch\n");
+        exit(-45);
+    }
+    printf("%s %d,%d;\n", sym->sym_ident, tlvbuf[0], tlvbuf[1]);
+}
+
 void decode_ethermask (unsigned char *tlvbuf, symbol_type *sym, size_t length)
 {
 /* the return value of ether_ntoa is a pointer to a static string

+ 1 - 0
src/docsis_decode.h

@@ -36,6 +36,7 @@ void decode_ip (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ip6 (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ether (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_dual_qtag (unsigned char *tlvbuf, symbol_type *sym, size_t length );
+void decode_dual_int (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_ethermask (unsigned char *tlvbuf, symbol_type *sym, size_t length );
 void decode_md5 (unsigned char *tlvbuf, symbol_type *sym, size_t length);
 void decode_snmp_wd (unsigned char *tlvbuf, symbol_type *sym, size_t length);

+ 25 - 0
src/docsis_encode.c

@@ -245,6 +245,31 @@ int encode_dual_qtag ( unsigned char *buf, void *tval, struct symbol_entry *sym_
     return (sizeof(final));
 }
 
+int encode_dual_int ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
+{
+    short int i, final;
+    char *token;
+    char *array[2];
+    const char s[2] = ",";
+    union t_val *helper;
+
+#ifdef DEBUG
+    fprintf(stderr, "encode_dual_int: found '%s' on line %d\n", helper->strval, line );
+#endif /* DEBUG */
+    helper = (union t_val *) tval;
+    i = 0;
+    token = strtok(helper->strval, s);
+    while (token != NULL)
+    {
+    	array[i++] = token;
+    	token = strtok (NULL, s);
+    }
+    final = htons(atoi(array[0]) << 8 | atoi(array[1]));
+    memcpy (buf, &final, sizeof(final));
+    free(helper->strval);
+    return(sizeof(final));
+}
+
 int encode_ethermask ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
 {
 int reta, retb; 	     /* return value of ether_aton */

+ 1 - 0
src/docsis_encode.h

@@ -32,6 +32,7 @@ int encode_ip     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 int encode_ip6     	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ether	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_dual_qtag	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
+int encode_dual_int	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_ethermask	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_string 	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );
 int encode_strzero	(unsigned char *buf, void *tval, struct symbol_entry *sym_ptr );

+ 1 - 2
src/docsis_symtable.h

@@ -162,8 +162,7 @@ symbol_type symtable[NUM_IDENTIFIERS] =  {
 { 49,     "SrcMacAddress",                     2,      47,     (encode_ether),          (decode_ether),          0,           0             }, /* TLV 22.10.2 MULPIv3.0-I24 Annex C.2.1.8.2 */
 { 50,     "EtherType",                         3,      47,     (encode_hexstr),         (decode_hexstr),         3,           3             }, /* TLV 22.10.3 MULPIv3.0-I24 Annex C.2.1.8.3 */
 { 51,     "IEEE802Classifier",                 11,     28,     (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 22.11 MULPIv3.0-I24 Annex C.2.1.9 */
-/* TODO: Fix the UserPriotity to be as per MULPI spec, check the POSTER for more info */
-{ 52,     "UserPriority",                      1,      51,     (encode_ushort),         (decode_ushort),         0,           0             }, /* TLV 22.11.1 MULPIv3.0-I24 Annex C.2.1.9.1 */
+{ 52,     "UserPriority",                      1,      51,     (encode_dual_int),       (decode_dual_int),       0,           0             }, /* TLV 22.11.1 MULPIv3.0-I24 Annex C.2.1.9.1 */
 { 53,     "VlanID",                            2,      51,     (encode_ushort),         (decode_ushort),         0,           4096          }, /* TLV 22.11.2 MULPIv3.0-I24 Annex C.2.1.9.2 */
 { 211,    "PcIPv6PacketClassification",        12,     28,     (encode_nothing),        (decode_aggregate),      0,           0             }, /* TLV 22.12 MULPIv3.0-I24 Annex C.2.1.10 */
 { 212,    "PcIPv6TrafficClassRangeAndMask",    1,      211,    (encode_hexstr),         (decode_hexstr),         3,           3             }, /* TLV 22.12.1 MULPIv3.0-I24 Annex C.2.1.10.1 */