aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Staub <atsju2@yahoo.fr>2018-07-02 14:34:28 +0200
committerPeter Wu <peter@lekensteyn.nl>2018-07-02 15:52:26 +0000
commit4572b77148828d87e1eab2aadd8dafa4549d7146 (patch)
treecf45ca1c768855d65851b788b7f092910b817316
parent53e04b621caa00c5cd5641d2fb8eb7e2783f85bd (diff)
WSUTIL: create phtole32 and 64 functions
Change-Id: I15c3c40665ccab1e60057837ffce5bae50d1b52c Reviewed-on: https://code.wireshark.org/review/28567 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r--epan/dissectors/packet-zbee-nwk-gp.c17
-rw-r--r--epan/dissectors/packet-zbee-security.c17
-rw-r--r--wsutil/pint.h18
3 files changed, 28 insertions, 24 deletions
diff --git a/epan/dissectors/packet-zbee-nwk-gp.c b/epan/dissectors/packet-zbee-nwk-gp.c
index 18a7830514..56ee9ad082 100644
--- a/epan/dissectors/packet-zbee-nwk-gp.c
+++ b/epan/dissectors/packet-zbee-nwk-gp.c
@@ -21,6 +21,7 @@
#include <epan/prefs.h>
#include <epan/uat.h>
#include <wsutil/bits_ctz.h>
+#include <wsutil/pint.h>
#include "packet-zbee.h"
#include "packet-zbee-nwk.h"
#include "packet-zbee-security.h"
@@ -1564,19 +1565,11 @@ zbee_gp_make_nonce(zbee_nwk_green_power_packet *packet, gchar *nonce)
{
memset(nonce, 0, ZBEE_SEC_CONST_NONCE_LEN);
if (packet->direction == ZBEE_NWK_GP_FC_EXT_DIRECTION_FROM_ZGPD) {
- nonce[0] = (guint8)((packet->source_id) & 0xff);
- nonce[1] = (guint8)((packet->source_id) >> 8 & 0xff);
- nonce[2] = (guint8)((packet->source_id) >> 16 & 0xff);
- nonce[3] = (guint8)((packet->source_id) >> 24 & 0xff);
+ phtole32(nonce, packet->source_id);
}
- nonce[4] = (guint8)((packet->source_id) & 0xff);
- nonce[5] = (guint8)((packet->source_id) >> 8 & 0xff);
- nonce[6] = (guint8)((packet->source_id) >> 16 & 0xff);
- nonce[7] = (guint8)((packet->source_id) >> 24 & 0xff);
- nonce[8] = (guint8)((packet->security_frame_counter) & 0xff);
- nonce[9] = (guint8)((packet->security_frame_counter) >> 8 & 0xff);
- nonce[10] = (guint8)((packet->security_frame_counter) >> 16 & 0xff);
- nonce[11] = (guint8)((packet->security_frame_counter) >> 24 & 0xff);
+ phtole32(nonce+4, packet->source_id);
+ phtole32(nonce+8, packet->security_frame_counter);
+
if ((packet->application_id == ZBEE_NWK_GP_APP_ID_ZGP) && (packet->direction !=
ZBEE_NWK_GP_FC_EXT_DIRECTION_FROM_ZGPD)) {
nonce[12] = (gchar)0xa3;
diff --git a/epan/dissectors/packet-zbee-security.c b/epan/dissectors/packet-zbee-security.c
index dab9ddb73b..553e797052 100644
--- a/epan/dissectors/packet-zbee-security.c
+++ b/epan/dissectors/packet-zbee-security.c
@@ -26,6 +26,7 @@
* we can do is parse the security header and give up.
*/
#include <wsutil/wsgcrypt.h>
+#include <wsutil/pint.h>
#include "packet-ieee802154.h"
#include "packet-zbee.h"
@@ -825,19 +826,11 @@ static void
zbee_sec_make_nonce(zbee_security_packet *packet, guint8 *nonce)
{
/* First 8 bytes are the extended source address (little endian). */
- *(nonce++) = (guint8)((packet->src64)>>0 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>8 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>16 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>24 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>32 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>40 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>48 & 0xff);
- *(nonce++) = (guint8)((packet->src64)>>56 & 0xff);
+ phtole64(nonce, packet->src64);
+ nonce += 8;
/* Next 4 bytes are the frame counter (little endian). */
- *(nonce++) = (guint8)((packet->counter)>>0 & 0xff);
- *(nonce++) = (guint8)((packet->counter)>>8 & 0xff);
- *(nonce++) = (guint8)((packet->counter)>>16 & 0xff);
- *(nonce++) = (guint8)((packet->counter)>>24 & 0xff);
+ phtole32(nonce, packet->counter);
+ nonce += 4;
/* Next byte is the security control field. */
*(nonce) = packet->control;
} /* zbee_sec_make_nonce */
diff --git a/wsutil/pint.h b/wsutil/pint.h
index 72c67e4a48..f81f9713c7 100644
--- a/wsutil/pint.h
+++ b/wsutil/pint.h
@@ -135,6 +135,24 @@ static inline void phton64(guint8 *p, guint64 v) {
p[7] = (guint8)(v >> 0);
}
+static inline void phtole32(guint8 *p, guint32 v) {
+ p[0] = (guint8)(v >> 0);
+ p[1] = (guint8)(v >> 8);
+ p[2] = (guint8)(v >> 16);
+ p[3] = (guint8)(v >> 24);
+}
+
+static inline void phtole64(guint8 *p, guint64 v) {
+ p[0] = (guint8)(v >> 0);
+ p[1] = (guint8)(v >> 8);
+ p[2] = (guint8)(v >> 16);
+ p[3] = (guint8)(v >> 24);
+ p[4] = (guint8)(v >> 32);
+ p[5] = (guint8)(v >> 40);
+ p[6] = (guint8)(v >> 48);
+ p[7] = (guint8)(v >> 56);
+}
+
/* Subtract two guint32s with respect to wraparound */
#define guint32_wraparound_diff(higher, lower) ((higher>lower)?(higher-lower):(higher+0xffffffff-lower+1))