Add tvb_bcd_dig_to_ep_str()
authorAnders Broman <anders.broman@ericsson.com>
Tue, 28 Dec 2010 12:36:26 +0000 (12:36 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Tue, 28 Dec 2010 12:36:26 +0000 (12:36 -0000)
/*
 * Given a tvbuff, an offset into the tvbuff, and a length that starts
 * at that offset (which may be -1 for "all the way to the end of the
 * tvbuff"), fetch BCD encoded digits from a tvbuff starting from either
 * the low or high half byte, formating the digits according to an input digit set,
 * if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
 * A pointer to the EP allocated string will be returned.
 * Note a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
 */

svn path=/trunk/; revision=35286

asn1/ansi_map/packet-ansi_map-template.c
epan/dissectors/packet-ansi_a.c
epan/dissectors/packet-ansi_map.c
epan/dissectors/packet-gsm_a_common.h
epan/tvbuff.c
epan/tvbuff.h

index c62b991340f3a4e7a30bcaa74b9e2ec4bc0753e3..5d2327c20900dd1c64993d2e8081aa922c8cb333 100644 (file)
@@ -570,12 +570,16 @@ static int dissect_invokeData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_
 static int dissect_returnData(proto_tree *tree, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx);
 static int dissect_ansi_map_SystemMyTypeCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_);
 
+#if 0
+/* Moved to tvbuff.h
+ * XXX remove after trial period.
+ */
 typedef struct dgt_set_t
 {
     unsigned char out[15];
 }
 dgt_set_t;
-
+#endif
 static dgt_set_t Dgt_tbcd = {
     {
   /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e */
index c959f722df730aba236377d18f4e4bcfeb475862..8c5345097385186d06b67673d0db9471437592ca 100644 (file)
@@ -726,7 +726,7 @@ static guint16 rtp_port;
 static gboolean a_meid_configured = FALSE;
 
 
-typedef struct dgt_set_t
+typedef struct ansi_a_dgt_set_t
 {
     /*
      * would typically be 15 but to allow MEID decoding this
@@ -734,26 +734,26 @@ typedef struct dgt_set_t
      */
     unsigned char out[16];
 }
-dgt_set_t;
+ansi_a_dgt_set_t;
 
 /*
  * As per A.S0001 Called Party BCD Number
  */
-static dgt_set_t Dgt_tbcd = {
+static ansi_a_dgt_set_t Dgt_tbcd = {
     {
   /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f */
      '0','1','2','3','4','5','6','7','8','9','*','#','a','b','c', 0
     }
 };
 
-static dgt_set_t Dgt_msid = {
+static ansi_a_dgt_set_t Dgt_msid = {
     {
   /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f */
      '0','1','2','3','4','5','6','7','8','9','?','?','?','?','?', 0
     }
 };
 
-static dgt_set_t Dgt_meid = {
+static ansi_a_dgt_set_t Dgt_meid = {
     {
   /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f */
      '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
@@ -774,7 +774,7 @@ my_dgt_tbcd_unpack(
     char        *out,           /* ASCII pattern out */
     guchar      *in,            /* packed pattern in */
     int         num_octs,       /* Number of octets to unpack */
-    dgt_set_t   *dgt            /* Digit definitions */
+    ansi_a_dgt_set_t   *dgt            /* Digit definitions */
     )
 {
     int cnt = 0;
index ccf779b12a2772d85b51e90b2ed74ad3c0ad59c2..90f3e17ba9dd2d6227a239d0c14505ab3775e433 100644 (file)
@@ -1358,12 +1358,16 @@ static int dissect_invokeData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_
 static int dissect_returnData(proto_tree *tree, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx);
 static int dissect_ansi_map_SystemMyTypeCode(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_);
 
+#if 0
+/* Moved to tvbuff.h
+ * XXX remove after trial period.
+ */
 typedef struct dgt_set_t
 {
     unsigned char out[15];
 }
 dgt_set_t;
-
+#endif
 static dgt_set_t Dgt_tbcd = {
     {
   /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e */
@@ -15519,7 +15523,7 @@ dissect_ansi_map_ReturnData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int of
 
 
 /*--- End of included file: packet-ansi_map-fn.c ---*/
-#line 3642 "packet-ansi_map-template.c"
+#line 3646 "packet-ansi_map-template.c"
 
 /*
  * 6.5.2.dk N.S0013-0 v 1.0,X.S0004-550-E v1.0 2.301
@@ -19361,7 +19365,7 @@ void proto_register_ansi_map(void) {
         NULL, HFILL }},
 
 /*--- End of included file: packet-ansi_map-hfarr.c ---*/
-#line 5291 "packet-ansi_map-template.c"
+#line 5295 "packet-ansi_map-template.c"
     };
 
     /* List of subtrees */
@@ -19622,7 +19626,7 @@ void proto_register_ansi_map(void) {
     &ett_ansi_map_ReturnData,
 
 /*--- End of included file: packet-ansi_map-ettarr.c ---*/
-#line 5324 "packet-ansi_map-template.c"
+#line 5328 "packet-ansi_map-template.c"
     };
 
 
index 9e33cc9c485418ed78e1d97d5a68ea6feda58cda..14e53572d6f93a1b2c86def499eb6e318689db2a 100644 (file)
 /* PROTOTYPES/FORWARDS */
 typedef guint16 (*elem_fcn)(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint len, gchar *add_string, int string_len);
 typedef void (*msg_fcn)(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint len);
-
+#if 0
+/* XXX moved to tvbuff.h, clean up later */
 typedef struct dgt_set_t
 {
        unsigned char out[15];
 }
 dgt_set_t;
-
+#endif
 int my_dgt_tbcd_unpack( 
        char    *out,           /* ASCII pattern out */
        guchar  *in,            /* packed pattern in */
index 220beaaa147b662db6fd574868e149cd2a6eb353..d3e31ff9d7e2e17c09a177b045295c70407f081c 100644 (file)
@@ -2901,6 +2901,71 @@ tvb_bytes_to_str_punct(tvbuff_t *tvb, const gint offset, const gint len, const g
        return bytes_to_str_punct(tvb_get_ptr(tvb, offset, len), len, punct);
 }
 
+
+/*
+ * Given a tvbuff, an offset into the tvbuff, and a length that starts
+ * at that offset (which may be -1 for "all the way to the end of the
+ * tvbuff"), fetch BCD encoded digits from a tvbuff starting from either 
+ * the low or high half byte, formating the digits according to an input digit set, 
+ * if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
+ * A pointer to the EP allocated string will be returned.
+ * Note a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
+ */
+static dgt_set_t Dgt1_9_bcd = {
+    {
+  /*  0   1   2   3   4   5   6   7   8   9   a   b   c   d   e */
+     '0','1','2','3','4','5','6','7','8','9','?','?','?','?','?'
+    }
+};
+gchar *
+tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first)
+{
+       int length;
+       guint8 octet;
+       int i=0;
+       char *digit_str;
+       gint t_offset = offset;
+
+       if (!dgt)
+               dgt = &Dgt1_9_bcd;
+
+       if( len == -1){
+               length = tvb_length(tvb);
+               if (length < offset){
+                       return "";
+               }
+       }else{
+               length = offset + len;
+       }
+       digit_str = ep_alloc((length - offset)*2+1);
+
+       while ( t_offset < length ){
+
+               octet = tvb_get_guint8(tvb,t_offset);
+               if (!skip_first){
+                       digit_str[i] = dgt->out[octet & 0x0f]; 
+                       i++;
+               }
+               skip_first = FALSE;
+
+               /*
+                * unpack second value in byte
+                */
+               octet = octet >> 4;
+
+               if (octet == 0x0f)      /* odd number bytes - hit filler */
+                       break;
+
+               digit_str[i] = dgt->out[octet & 0x0f]; 
+               i++;
+               t_offset++;
+
+       }
+       digit_str[i]= '\0';
+       return digit_str;
+
+}
+
 /*
  * Format a bunch of data from a tvbuff as bytes, returning a pointer
  * to the string with the formatted data.
index d4e76230a97030d6b9fcd26f23051a72a5201f68..55a688bc91aabe92bcded832c7ee5d5f7917778f 100644 (file)
@@ -644,12 +644,29 @@ extern gint tvb_memeql(tvbuff_t *tvb, const gint offset, const guint8 *str,
 extern gchar *tvb_bytes_to_str_punct(tvbuff_t *tvb, const gint offset, const gint len,
     const gchar punct);
 
-/*
+/**
  * Format a bunch of data from a tvbuff as bytes, returning a pointer
  * to the string with the formatted data.
  */
 extern gchar *tvb_bytes_to_str(tvbuff_t *tvb, const gint offset, const gint len);
 
+/**
+ * Given a tvbuff, an offset into the tvbuff, and a length that starts
+ * at that offset (which may be -1 for "all the way to the end of the
+ * tvbuff"), fetch BCD encoded digits from a tvbuff starting from either 
+ * the low or high half byte, formating the digits according to an input digit set, 
+ * if NUll a default digit set of 0-9 returning "?" for overdecadic digits will be used.
+ * A pointer to the EP allocated string will be returned.
+ * Note a tvbuff content of 0xf is considered a 'filler' and will end the conversion.
+ */
+typedef struct dgt_set_t
+{
+       const unsigned char out[15];
+}
+dgt_set_t;
+
+extern gchar *tvb_bcd_dig_to_ep_str(tvbuff_t *tvb, const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
+
 #define TVB_GET_DS_TVB(tvb)            \
        (tvb->ds_tvb)