@@ -79,6 +79,15 @@ func TestUplinkScenarios(t *testing.T) {
79
79
AppEUI : [8 ]byte {8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 },
80
80
}
81
81
82
+ nsFCntRollOver := session.NodeSession {
83
+ DevAddr : [4 ]byte {1 , 2 , 3 , 4 },
84
+ DevEUI : [8 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 },
85
+ NwkSKey : [16 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 },
86
+ FCntUp : 65535 ,
87
+ FCntDown : 5 ,
88
+ AppEUI : [8 ]byte {8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 },
89
+ }
90
+
82
91
nsRelaxFCnt := session.NodeSession {
83
92
DevAddr : [4 ]byte {1 , 2 , 3 , 4 },
84
93
DevEUI : [8 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 },
@@ -171,6 +180,31 @@ func TestUplinkScenarios(t *testing.T) {
171
180
},
172
181
}
173
182
183
+ expectedApplicationPushDataUpFCntRollOver := & as.HandleDataUpRequest {
184
+ AppEUI : ns .AppEUI [:],
185
+ DevEUI : ns .DevEUI [:],
186
+ FCnt : 65536 ,
187
+ FPort : 1 ,
188
+ Data : []byte {1 , 2 , 3 , 4 },
189
+ TxInfo : & as.TXInfo {
190
+ Frequency : int64 (rxInfo .Frequency ),
191
+ DataRate : & as.DataRate {
192
+ Modulation : string (rxInfo .DataRate .Modulation ),
193
+ BandWidth : uint32 (rxInfo .DataRate .Bandwidth ),
194
+ SpreadFactor : uint32 (rxInfo .DataRate .SpreadFactor ),
195
+ Bitrate : uint32 (rxInfo .DataRate .BitRate ),
196
+ },
197
+ },
198
+ RxInfo : []* as.RXInfo {
199
+ {
200
+ Mac : rxInfo .MAC [:],
201
+ Time : rxInfo .Time .Format (time .RFC3339Nano ),
202
+ Rssi : int32 (rxInfo .RSSI ),
203
+ LoRaSNR : rxInfo .LoRaSNR ,
204
+ },
205
+ },
206
+ }
207
+
174
208
expectedApplicationPushDataUpNoData := & as.HandleDataUpRequest {
175
209
AppEUI : ns .AppEUI [:],
176
210
DevEUI : ns .DevEUI [:],
@@ -732,6 +766,31 @@ func TestUplinkScenarios(t *testing.T) {
732
766
ExpectedFCntUp : 10 ,
733
767
ExpectedFCntDown : 5 ,
734
768
},
769
+ {
770
+ Name : "unconfirmed uplink with FCnt rollover" ,
771
+ NodeSession : nsFCntRollOver ,
772
+ RXInfo : rxInfo ,
773
+ SetMICKey : ns .NwkSKey ,
774
+ PHYPayload : lorawan.PHYPayload {
775
+ MHDR : lorawan.MHDR {
776
+ MType : lorawan .UnconfirmedDataUp ,
777
+ Major : lorawan .LoRaWANR1 ,
778
+ },
779
+ MACPayload : & lorawan.MACPayload {
780
+ FHDR : lorawan.FHDR {
781
+ DevAddr : ns .DevAddr ,
782
+ FCnt : 65536 ,
783
+ },
784
+ FPort : & fPortOne ,
785
+ FRMPayload : []lorawan.Payload {& lorawan.DataPayload {Bytes : []byte {1 , 2 , 3 , 4 }}},
786
+ },
787
+ },
788
+ ExpectedControllerHandleRXInfo : expectedControllerHandleRXInfo ,
789
+ ExpectedApplicationHandleDataUp : expectedApplicationPushDataUpFCntRollOver ,
790
+ ExpectedApplicationGetDataDown : expectedGetDataDown ,
791
+ ExpectedFCntUp : 65536 ,
792
+ ExpectedFCntDown : 5 ,
793
+ },
735
794
}
736
795
737
796
runUplinkTests (ctx , tests )
@@ -1319,10 +1378,17 @@ func runUplinkTests(ctx common.Context, tests []uplinkTestCase) {
1319
1378
}
1320
1379
So (t .PHYPayload .SetMIC (t .SetMICKey ), ShouldBeNil )
1321
1380
1381
+ // marshal and unmarshal the PHYPayload to make sure the FCnt gets
1382
+ // truncated to to 16 bit
1383
+ var phy lorawan.PHYPayload
1384
+ b , err := t .PHYPayload .MarshalBinary ()
1385
+ So (err , ShouldBeNil )
1386
+ So (phy .UnmarshalBinary (b ), ShouldBeNil )
1387
+
1322
1388
// create RXPacket and call HandleRXPacket
1323
1389
rxPacket := gw.RXPacket {
1324
1390
RXInfo : t .RXInfo ,
1325
- PHYPayload : t . PHYPayload ,
1391
+ PHYPayload : phy ,
1326
1392
}
1327
1393
So (uplink .HandleRXPacket (ctx , rxPacket ), ShouldResemble , t .ExpectedHandleRXPacketError )
1328
1394
0 commit comments