From 2879492799a22b843b2b655ddc5f2aab84d738b7 Mon Sep 17 00:00:00 2001 From: firmwareguru Date: Fri, 22 Feb 2019 07:46:48 -0700 Subject: [PATCH 1/3] fix mqtt string lengths greater than 255 and incorrect example keep-alive --- examples/mqtt-client/mqtt-client.c | 2 +- os/net/app-layer/mqtt/mqtt.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/mqtt-client/mqtt-client.c b/examples/mqtt-client/mqtt-client.c index b71a193ea..35e669e24 100644 --- a/examples/mqtt-client/mqtt-client.c +++ b/examples/mqtt-client/mqtt-client.c @@ -572,7 +572,7 @@ connect_to_broker(void) { /* Connect to MQTT server */ mqtt_connect(&conn, conf.broker_ip, conf.broker_port, - conf.pub_interval * 3); + (conf.pub_interval * 3) / CLOCK_SECOND); state = STATE_CONNECTING; } diff --git a/os/net/app-layer/mqtt/mqtt.c b/os/net/app-layer/mqtt/mqtt.c index 9571244d8..47ffc6a7a 100644 --- a/os/net/app-layer/mqtt/mqtt.c +++ b/os/net/app-layer/mqtt/mqtt.c @@ -416,16 +416,16 @@ PT_THREAD(connect_pt(struct pt *pt, struct mqtt_connection *conn)) PT_MQTT_WRITE_BYTE(conn, conn->connect_vhdr_flags); PT_MQTT_WRITE_BYTE(conn, (conn->keep_alive >> 8)); PT_MQTT_WRITE_BYTE(conn, (conn->keep_alive & 0x00FF)); - PT_MQTT_WRITE_BYTE(conn, conn->client_id.length << 8); + PT_MQTT_WRITE_BYTE(conn, conn->client_id.length >> 8); PT_MQTT_WRITE_BYTE(conn, conn->client_id.length & 0x00FF); PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->client_id.string, conn->client_id.length); if(conn->connect_vhdr_flags & MQTT_VHDR_WILL_FLAG) { - PT_MQTT_WRITE_BYTE(conn, conn->will.topic.length << 8); + PT_MQTT_WRITE_BYTE(conn, conn->will.topic.length >> 8); PT_MQTT_WRITE_BYTE(conn, conn->will.topic.length & 0x00FF); PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->will.topic.string, conn->will.topic.length); - PT_MQTT_WRITE_BYTE(conn, conn->will.message.length << 8); + PT_MQTT_WRITE_BYTE(conn, conn->will.message.length >> 8); PT_MQTT_WRITE_BYTE(conn, conn->will.message.length & 0x00FF); PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->will.message.string, conn->will.message.length); @@ -436,14 +436,14 @@ PT_THREAD(connect_pt(struct pt *pt, struct mqtt_connection *conn)) conn->will.message.length); } if(conn->connect_vhdr_flags & MQTT_VHDR_USERNAME_FLAG) { - PT_MQTT_WRITE_BYTE(conn, conn->credentials.username.length << 8); + PT_MQTT_WRITE_BYTE(conn, conn->credentials.username.length >> 8); PT_MQTT_WRITE_BYTE(conn, conn->credentials.username.length & 0x00FF); PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->credentials.username.string, conn->credentials.username.length); } if(conn->connect_vhdr_flags & MQTT_VHDR_PASSWORD_FLAG) { - PT_MQTT_WRITE_BYTE(conn, conn->credentials.password.length << 8); + PT_MQTT_WRITE_BYTE(conn, conn->credentials.password.length >> 8); PT_MQTT_WRITE_BYTE(conn, conn->credentials.password.length & 0x00FF); PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->credentials.password.string, @@ -534,7 +534,7 @@ PT_THREAD(subscribe_pt(struct pt *pt, struct mqtt_connection *conn)) conn->out_packet.remaining_length_enc, conn->out_packet.remaining_length_enc_bytes); /* Write Variable Header */ - PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid << 8)); + PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid >> 8)); PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid & 0x00FF)); /* Write Payload */ PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.topic_length >> 8)); @@ -596,7 +596,7 @@ PT_THREAD(unsubscribe_pt(struct pt *pt, struct mqtt_connection *conn)) PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->out_packet.remaining_length_enc, conn->out_packet.remaining_length_enc_bytes); /* Write Variable Header */ - PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid << 8)); + PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid >> 8)); PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid & 0x00FF)); /* Write Payload */ PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.topic_length >> 8)); @@ -669,7 +669,7 @@ PT_THREAD(publish_pt(struct pt *pt, struct mqtt_connection *conn)) PT_MQTT_WRITE_BYTES(conn, (uint8_t *)conn->out_packet.topic, conn->out_packet.topic_length); if(conn->out_packet.qos > MQTT_QOS_LEVEL_0) { - PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid << 8)); + PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid >> 8)); PT_MQTT_WRITE_BYTE(conn, (conn->out_packet.mid & 0x00FF)); } /* Write Payload */ @@ -772,7 +772,7 @@ handle_connack(struct mqtt_connection *conn) static void handle_pingresp(struct mqtt_connection *conn) { - DBG("MQTT - Got RINGRESP\n"); + DBG("MQTT - Got PINGRESP\n"); } /*---------------------------------------------------------------------------*/ static void From 6debe1b21b047f84903aed176d8a01cf8c4af1b5 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 24 Feb 2019 15:48:56 +0100 Subject: [PATCH 2/3] Added explicit types for TSCH timeslot timings in usec and ticks --- arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c | 2 +- arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c | 2 +- arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c | 2 +- arch/dev/cc2420/cc2420-tsch-15ms.c | 2 +- os/net/mac/tsch/tsch-timeslot-timing.c | 2 +- os/net/mac/tsch/tsch-types.h | 6 ++++++ os/net/mac/tsch/tsch.h | 6 +++--- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c index af76d63e3..f2874fd03 100644 --- a/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c +++ b/arch/cpu/cc26x0-cc13x0/rf-core/cc13xx-50kbps-tsch.c @@ -57,7 +57,7 @@ #define CC13XX_TSCH_DEFAULT_TS_TIMESLOT_LENGTH 40000 /* TSCH timeslot timing (microseconds) */ -const uint16_t tsch_timing_cc13xx_50kbps[tsch_ts_elements_count] = { +const tsch_timeslot_timing_usec tsch_timing_cc13xx_50kbps = { CC13XX_TSCH_DEFAULT_TS_CCA_OFFSET, CC13XX_TSCH_DEFAULT_TS_CCA, CC13XX_TSCH_DEFAULT_TS_TX_OFFSET, diff --git a/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c b/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c index ad19b5769..f6b1e9a5a 100644 --- a/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c +++ b/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c @@ -94,7 +94,7 @@ static const char rf_cfg_descriptor[] = "802.15.4g 863-870MHz MR-FSK mode #1"; ) /* TSCH timeslot timing (mircoseconds) */ -static const uint16_t cc1200_50kbps_tsch_timing[tsch_ts_elements_count] = { +static const tsch_timeslot_timing_usec cc1200_50kbps_tsch_timing = { CC1200_TSCH_DEFAULT_TS_CCA_OFFSET, CC1200_TSCH_DEFAULT_TS_CCA, CC1200_TSCH_DEFAULT_TS_TX_OFFSET, diff --git a/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c b/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c index 29beef6c0..5314bb517 100644 --- a/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c +++ b/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c @@ -86,7 +86,7 @@ static const char rf_cfg_descriptor[] = "868MHz 2-GFSK 1000 kbps"; ) /* TSCH timeslot timing (in rtimer ticks) */ -static const uint16_t cc1200_1000kbps_tsch_timing[tsch_ts_elements_count] = { +static const tsch_timeslot_timing_usec cc1200_1000kbps_tsch_timing = { CC1200_TSCH_DEFAULT_TS_CCA_OFFSET, CC1200_TSCH_DEFAULT_TS_CCA, CC1200_TSCH_DEFAULT_TS_TX_OFFSET, diff --git a/arch/dev/cc2420/cc2420-tsch-15ms.c b/arch/dev/cc2420/cc2420-tsch-15ms.c index b3b825584..cccc63b34 100644 --- a/arch/dev/cc2420/cc2420-tsch-15ms.c +++ b/arch/dev/cc2420/cc2420-tsch-15ms.c @@ -45,7 +45,7 @@ * \brief 15ms TSCH timeslot timings, required for cc2420 platforms as * they are unable to keep up with the defulat 10ms timeslots. */ -const uint16_t tsch_timeslot_timing_us_15000[tsch_ts_elements_count] = { +const tsch_timeslot_timing_usec tsch_timeslot_timing_us_15000= { 1800, /* CCAOffset */ 128, /* CCA */ 4000, /* TxOffset */ diff --git a/os/net/mac/tsch/tsch-timeslot-timing.c b/os/net/mac/tsch/tsch-timeslot-timing.c index a75676101..1d598a4ae 100644 --- a/os/net/mac/tsch/tsch-timeslot-timing.c +++ b/os/net/mac/tsch/tsch-timeslot-timing.c @@ -61,7 +61,7 @@ * (TxOffset - (RxWait / 2)) instead */ -const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count] = { +const tsch_timeslot_timing_usec tsch_timeslot_timing_us_10000 = { 1800, /* CCAOffset */ 128, /* CCA */ 2120, /* TxOffset */ diff --git a/os/net/mac/tsch/tsch-types.h b/os/net/mac/tsch/tsch-types.h index 20f9911f6..1c2cdb13a 100644 --- a/os/net/mac/tsch/tsch-types.h +++ b/os/net/mac/tsch/tsch-types.h @@ -142,6 +142,12 @@ enum tsch_timeslot_timing_elements { tsch_ts_elements_count, /* Not a timing element */ }; +/** \brief TSCH timeslot timing elements in rtimer ticks */ +typedef rtimer_clock_t tsch_timeslot_timing_ticks[tsch_ts_elements_count]; + +/** \brief TSCH timeslot timing elements in micro-seconds */ +typedef uint16_t tsch_timeslot_timing_usec[tsch_ts_elements_count]; + /** \brief Stores data about an incoming packet */ struct input_packet { uint8_t payload[TSCH_PACKET_MAX_LEN]; /* Packet payload */ diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index ba2926341..6991c08c4 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -167,9 +167,9 @@ extern uint8_t tsch_current_channel; extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN]; extern struct tsch_asn_divisor_t tsch_hopping_sequence_length; /* TSCH timeslot timing (in micro-second) */ -extern uint16_t tsch_timing_us[tsch_ts_elements_count]; +extern tsch_timeslot_timing_usec tsch_timing_us; /* TSCH timeslot timing (in rtimer ticks) */ -extern rtimer_clock_t tsch_timing[tsch_ts_elements_count]; +extern tsch_timeslot_timing_ticks tsch_timing; /* Statistics on the current session */ extern unsigned long tx_count; extern unsigned long rx_count; @@ -177,7 +177,7 @@ extern unsigned long sync_count; extern int32_t min_drift_seen; extern int32_t max_drift_seen; /* The TSCH standard 10ms timeslot timing */ -extern const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count]; +extern const tsch_timeslot_timing_usec tsch_timeslot_timing_us_10000; /* TSCH processes */ PROCESS_NAME(tsch_process); From 36d9d4a84661418e0f088d3ab91c369a536459c6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 24 Feb 2019 16:05:21 +0100 Subject: [PATCH 3/3] Radio API: document TSCH-related radio constants --- arch/cpu/cc2538/dev/cc2538-rf.c | 1 + arch/dev/cc1200/cc1200.c | 1 + arch/platform/zoul/platform.c | 1 + os/dev/radio.h | 15 +++++++++++++++ 4 files changed, 18 insertions(+) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index e3a548067..7fd40afdc 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -1031,6 +1031,7 @@ get_object(radio_param_t param, void *dest, size_t size) if(size != sizeof(uint16_t *) || !dest) { return RADIO_RESULT_INVALID_VALUE; } + /* Assigned value: a pointer to the TSCH timing in usec */ *(const uint16_t **)dest = tsch_timeslot_timing_us_10000; return RADIO_RESULT_OK; } diff --git a/arch/dev/cc1200/cc1200.c b/arch/dev/cc1200/cc1200.c index dd90fdda7..50babb93d 100644 --- a/arch/dev/cc1200/cc1200.c +++ b/arch/dev/cc1200/cc1200.c @@ -1449,6 +1449,7 @@ get_object(radio_param_t param, void *dest, size_t size) if(size != sizeof(uint16_t *) || !dest) { return RADIO_RESULT_INVALID_VALUE; } + /* Assigned value: a pointer to the TSCH timing in usec */ *(const uint16_t **)dest = CC1200_RF_CFG.tsch_timing; return RADIO_RESULT_OK; } diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index bed948829..49158b5b4 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -295,6 +295,7 @@ radio_delay_before_detect(void) { uint16_t * radio_tsch_timeslot_timing(void) { uint16_t *ret; + /* Get and return pointer to TSCH timings in usec */ NETSTACK_RADIO.get_object(RADIO_CONST_TSCH_TIMING, &ret, sizeof(ret)); return ret; } diff --git a/os/dev/radio.h b/os/dev/radio.h index e279e9efe..4cb266608 100644 --- a/os/dev/radio.h +++ b/os/dev/radio.h @@ -185,11 +185,26 @@ enum { /* The maximum transmission power in dBm. */ RADIO_CONST_TXPOWER_MAX, + /* A pointer to TSCH timings in micro-seconds (tsch_timeslot_timing_usec *) */ RADIO_CONST_TSCH_TIMING, + + /* The physical layer header+footer overhead in bytes, after SFD. + * On IEEE 802.15.4 at 2.4 GHz: 1 byte for len + 2 for CRC => 3 */ RADIO_CONST_PHY_OVERHEAD, + + /* The air time of one byte in usec, e.g. 32 for IEEE 802.15.4 at 2.4 GHz */ RADIO_CONST_BYTE_AIR_TIME, + + /* The delay in usec between a call to the radio API's transmit function and + * the end of SFD transmission */ RADIO_CONST_DELAY_BEFORE_TX, + + /* The delay in usec between turning on the radio and it being actually + * listening (able to hear a preamble) */ RADIO_CONST_DELAY_BEFORE_RX, + + /* The delay in usec between the end of SFD reception for an incoming frame + * and the radio API starting to return receiving_packet() != 0 */ RADIO_CONST_DELAY_BEFORE_DETECT, };