aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2010-12-28 12:36:26 +0000
committerAnders Broman <anders.broman@ericsson.com>2010-12-28 12:36:26 +0000
commit735709bee6e62b4e283ebeff791b40e24e2c32b5 (patch)
tree4cd181cb127b3ead2af60472ec59090a6b136cfa
parent23b188ca06ff0e6c5141d70a018219ed479e99bc (diff)
Add tvb_bcd_dig_to_ep_str()
/* * 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
-rw-r--r--asn1/ansi_map/packet-ansi_map-template.c6
-rw-r--r--epan/dissectors/packet-ansi_a.c12
-rw-r--r--epan/dissectors/packet-ansi_map.c12
-rw-r--r--epan/dissectors/packet-gsm_a_common.h5
-rw-r--r--epan/tvbuff.c65
-rw-r--r--epan/tvbuff.h19
6 files changed, 105 insertions, 14 deletions
diff --git a/asn1/ansi_map/packet-ansi_map-template.c b/asn1/ansi_map/packet-ansi_map-template.c
index c62b991340..5d2327c209 100644
--- a/asn1/ansi_map/packet-ansi_map-template.c
+++ b/asn1/ansi_map/packet-ansi_map-template.c
@@ -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 */
diff --git a/epan/dissectors/packet-ansi_a.c b/epan/dissectors/packet-ansi_a.c
index c959f722df..8c53450973 100644
--- a/epan/dissectors/packet-ansi_a.c
+++ b/epan/dissectors/packet-ansi_a.c
@@ -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;
diff --git a/epan/dissectors/packet-ansi_map.c b/epan/dissectors/packet-ansi_map.c
index ccf779b12a..90f3e17ba9 100644
--- a/epan/dissectors/packet-ansi_map.c
+++ b/epan/dissectors/packet-ansi_map.c
@@ -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"
};
diff --git a/epan/dissectors/packet-gsm_a_common.h b/epan/dissectors/packet-gsm_a_common.h
index 9e33cc9c48..14e53572d6 100644
--- a/epan/dissectors/packet-gsm_a_common.h
+++ b/epan/dissectors/packet-gsm_a_common.h
@@ -56,13 +56,14 @@
/* 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 */
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 220beaaa14..d3e31ff9d7 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -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.
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index d4e76230a9..55a688bc91 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -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)