@@ -630,17 +630,15 @@ bool STM32LoRaWAN::mibSetUint32(const char* name, Mib_t type, uint32_t value) {
630630
631631bool STM32LoRaWAN::mibGetUint64 (const char * name, Mib_t type, uint64_t *value) {
632632 MibRequestConfirm_t mibReq;
633- if (!mibGet (name, type, mibReq))
634- return false ;
635-
636- const uint8_t *buf;
633+ uint8_t buf[8 ];
637634
638635 switch (type) {
639- case MIB_DEV_EUI: buf = mibReq.Param .DevEui ; break ;
640- case MIB_JOIN_EUI: buf = mibReq.Param .JoinEui ; break ;
636+ case MIB_DEV_EUI: mibReq.Param .DevEui = buf ; break ;
637+ case MIB_JOIN_EUI: mibReq.Param .JoinEui = buf ; break ;
641638 default : return failure (" Internal error: Unknown MIB type: %s / %u\r\n " , name, type);
642639 }
643-
640+ if (!mibGet (name, type, mibReq))
641+ return false ;
644642 *value = (uint64_t )buf[0 ] << 7 *8 |
645643 (uint64_t )buf[1 ] << 6 *8 |
646644 (uint64_t )buf[2 ] << 5 *8 |
@@ -726,66 +724,69 @@ size_t STM32LoRaWAN::mibHexSize(const char *name, Mib_t type) {
726724
727725bool STM32LoRaWAN::mibGetHex (const char * name, Mib_t type, String* value) {
728726 MibRequestConfirm_t mibReq;
729- if (!mibGet (name, type, mibReq))
730- return false ;
731-
732727 size_t size = mibHexSize (name, type);
733728
734729 if (!size)
735730 return false ;
736731
737- uint8_t dev_addr_buf[4 ];;
738- uint8_t *buf;
732+ uint8_t dev_addr_buf[4 ];
733+ uint8_t buf_type[size];
734+ uint8_t *buf = buf_type;
739735
740736 switch (type) {
741- case MIB_DEV_EUI: buf = mibReq.Param .DevEui ; break ;
742- case MIB_JOIN_EUI: buf = mibReq.Param .JoinEui ; break ;
743- // This assumes big endian, since that's the natural way to
744- // write down a a number in hex
745- case MIB_DEV_ADDR:
746- dev_addr_buf[0 ] = mibReq.Param .DevAddr >> (3 *8 );
747- dev_addr_buf[1 ] = mibReq.Param .DevAddr >> (2 *8 );
748- dev_addr_buf[2 ] = mibReq.Param .DevAddr >> (1 *8 );
749- dev_addr_buf[3 ] = mibReq.Param .DevAddr >> (0 *8 );
750- buf = dev_addr_buf;
751- break ;
752- case MIB_APP_KEY: buf = mibReq.Param .AppKey ; break ;
753- case MIB_NWK_KEY: buf = mibReq.Param .NwkKey ; break ;
737+ case MIB_DEV_EUI: mibReq.Param .DevEui = buf_type; break ;
738+ case MIB_JOIN_EUI: mibReq.Param .JoinEui = buf_type; break ;
739+ case MIB_APP_KEY: mibReq.Param .AppKey = buf_type; break ;
740+ case MIB_NWK_KEY: mibReq.Param .NwkKey = buf_type; break ;
754741 #if (defined( LORAMAC_VERSION ) && ( LORAMAC_VERSION == 0x01010100 ))
755- case MIB_J_S_INT_KEY: buf = mibReq.Param .JSIntKey ; break ;
756- case MIB_J_S_ENC_KEY: buf = mibReq.Param .JSEncKey ; break ;
757- case MIB_F_NWK_S_INT_KEY: buf = mibReq.Param .FNwkSIntKey ; break ;
758- case MIB_S_NWK_S_INT_KEY: buf = mibReq.Param .SNwkSIntKey ; break ;
759- case MIB_NWK_S_ENC_KEY: buf = mibReq.Param .NwkSEncKey ; break ;
742+ case MIB_J_S_INT_KEY: mibReq.Param .JSIntKey = buf_type ; break ;
743+ case MIB_J_S_ENC_KEY: mibReq.Param .JSEncKey = buf_type ; break ;
744+ case MIB_F_NWK_S_INT_KEY: mibReq.Param .FNwkSIntKey = buf_type ; break ;
745+ case MIB_S_NWK_S_INT_KEY: mibReq.Param .SNwkSIntKey = buf_type ; break ;
746+ case MIB_NWK_S_ENC_KEY: mibReq.Param .NwkSEncKey = buf_type ; break ;
760747 #else /* ( LORAMAC_VERSION == 0x01010100 ) */
761- case MIB_NWK_S_KEY: buf = mibReq.Param .NwkSKey ; break ;
748+ case MIB_NWK_S_KEY: mibReq.Param .NwkSKey = buf_type ; break ;
762749 #endif /* ( LORAMAC_VERSION == 0x01010100 ) */
763- case MIB_APP_S_KEY: buf = mibReq.Param .AppSKey ; break ;
764- case MIB_MC_KE_KEY: buf = mibReq.Param .McKEKey ; break ;
750+ case MIB_APP_S_KEY: mibReq.Param .AppSKey = buf_type ; break ;
751+ case MIB_MC_KE_KEY: mibReq.Param .McKEKey = buf_type ; break ;
765752 #if ( LORAMAC_MAX_MC_CTX > 0 )
766- case MIB_MC_KEY_0: buf = mibReq.Param .McKey0 ; break ;
767- case MIB_MC_APP_S_KEY_0: buf = mibReq.Param .McAppSKey0 ; break ;
768- case MIB_MC_NWK_S_KEY_0: buf = mibReq.Param .McNwkSKey0 ; break ;
753+ case MIB_MC_KEY_0: mibReq.Param .McKey0 = buf_type ; break ;
754+ case MIB_MC_APP_S_KEY_0: mibReq.Param .McAppSKey0 = buf_type ; break ;
755+ case MIB_MC_NWK_S_KEY_0: mibReq.Param .McNwkSKey0 = buf_type ; break ;
769756 #endif /* LORAMAC_MAX_MC_CTX > 0 */
770757 #if ( LORAMAC_MAX_MC_CTX > 1 )
771- case MIB_MC_KEY_1: buf = mibReq.Param .McKey1 ; break ;
772- case MIB_MC_APP_S_KEY_1: buf = mibReq.Param .McAppSKey1 ; break ;
773- case MIB_MC_NWK_S_KEY_1: buf = mibReq.Param .McNwkSKey1 ; break ;
758+ case MIB_MC_KEY_1: mibReq.Param .McKey1 = buf_type ; break ;
759+ case MIB_MC_APP_S_KEY_1: mibReq.Param .McAppSKey1 = buf_type ; break ;
760+ case MIB_MC_NWK_S_KEY_1: mibReq.Param .McNwkSKey1 = buf_type ; break ;
774761 #endif /* LORAMAC_MAX_MC_CTX > 1 */
775762 #if ( LORAMAC_MAX_MC_CTX > 2 )
776- case MIB_MC_KEY_2: buf = mibReq.Param .McKey2 ; break ;
777- case MIB_MC_APP_S_KEY_2: buf = mibReq.Param .McAppSKey2 ; break ;
778- case MIB_MC_NWK_S_KEY_2: buf = mibReq.Param .McNwkSKey2 ; break ;
763+ case MIB_MC_KEY_2: mibReq.Param .McKey2 = buf_type ; break ;
764+ case MIB_MC_APP_S_KEY_2: mibReq.Param .McAppSKey2 = buf_type ; break ;
765+ case MIB_MC_NWK_S_KEY_2: mibReq.Param .McNwkSKey2 = buf_type ; break ;
779766 #endif /* LORAMAC_MAX_MC_CTX > 2 */
780767 #if ( LORAMAC_MAX_MC_CTX > 3 )
781- case MIB_MC_KEY_3: buf = mibReq.Param .McKey3 ; break ;
782- case MIB_MC_APP_S_KEY_3: buf = mibReq.Param .McAppSKey3 ; break ;
783- case MIB_MC_NWK_S_KEY_3: buf = mibReq.Param .McNwkSKey3 ; break ;
768+ case MIB_MC_KEY_3: mibReq.Param .McKey3 = buf_type ; break ;
769+ case MIB_MC_APP_S_KEY_3: mibReq.Param .McAppSKey3 = buf_type ; break ;
770+ case MIB_MC_NWK_S_KEY_3: mibReq.Param .McNwkSKey3 = buf_type ; break ;
784771 #endif /* LORAMAC_MAX_MC_CTX > 3 */
785772 default :
786773 return failure (" Internal error: Unknown MIB type: %s / %u\r\n " , name, type);
787774 }
788775
776+
777+ if (!mibGet (name, type, mibReq))
778+ return false ;
779+
780+ if (type == MIB_DEV_ADDR) {
781+ // This assumes big endian, since that's the natural way to
782+ // write down a a number in hex
783+ dev_addr_buf[0 ] = mibReq.Param .DevAddr >> (3 *8 );
784+ dev_addr_buf[1 ] = mibReq.Param .DevAddr >> (2 *8 );
785+ dev_addr_buf[2 ] = mibReq.Param .DevAddr >> (1 *8 );
786+ dev_addr_buf[3 ] = mibReq.Param .DevAddr >> (0 *8 );
787+ buf = dev_addr_buf;
788+ }
789+
789790 return toHex (value, buf, size);
790791}
791792
0 commit comments