-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathwwan.go
More file actions
1031 lines (946 loc) · 34.1 KB
/
wwan.go
File metadata and controls
1031 lines (946 loc) · 34.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2023 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
// Types defined for interaction between pillar and the wwan microservice.
package types
import (
"fmt"
"net"
"time"
"github.com/google/go-cmp/cmp"
"github.com/lf-edge/eve-api/go/evecommon"
"github.com/lf-edge/eve-api/go/info"
"github.com/lf-edge/eve-api/go/metrics"
"github.com/lf-edge/eve/pkg/pillar/base"
"github.com/lf-edge/eve/pkg/pillar/utils/generics"
"github.com/lf-edge/eve/pkg/pillar/utils/netutils"
"google.golang.org/protobuf/types/known/timestamppb"
)
// WwanConfig is published by nim and consumed by the wwan service.
type WwanConfig struct {
// Key of the DevicePortConfig from which WwanConfig was generated.
DPCKey string
// Timestamp of the DevicePortConfig from which WwanConfig was generated.
DPCTimestamp time.Time
// Timestamp of the RadioSilence config applied into this WwanConfig.
RSConfigTimestamp time.Time
// Radio silence is the act of disabling all radio transmission
// for safety or security reasons
RadioSilence bool
// One entry for every cellular modem.
Networks []WwanNetworkConfig
}
// GetNetworkConfig returns pointer to the network config corresponding to the modem
// with the given logical label.
func (wc WwanConfig) GetNetworkConfig(logicalLabel string) *WwanNetworkConfig {
for i := range wc.Networks {
if wc.Networks[i].LogicalLabel == logicalLabel {
return &wc.Networks[i]
}
}
return nil
}
// Equal compares two instances of WwanConfig for equality.
func (wc WwanConfig) Equal(wc2 WwanConfig) bool {
if wc.DPCKey != wc2.DPCKey ||
!wc.DPCTimestamp.Equal(wc2.DPCTimestamp) ||
!wc.RSConfigTimestamp.Equal(wc2.RSConfigTimestamp) ||
wc.RadioSilence != wc2.RadioSilence {
return false
}
return generics.EqualSetsFn(wc.Networks, wc2.Networks,
func(wnc1, wnc2 WwanNetworkConfig) bool {
return wnc1.Equal(wnc2)
})
}
// Key is used for pubsub
func (wc WwanConfig) Key() string {
return "global"
}
// LogCreate :
func (wc WwanConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.WwanConfigLogType, "",
nilUUID, wc.LogKey())
if logObject == nil {
return
}
logObject.Metricf("Wwan config create")
}
// LogModify :
func (wc WwanConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.WwanConfigLogType, "",
nilUUID, wc.LogKey())
oldWc, ok := old.(WwanConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object passed is not of WwanConfig type")
}
logObject.CloneAndAddField("diff", cmp.Diff(oldWc, wc)).
Metricf("Wwan config modify")
}
// LogDelete :
func (wc WwanConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.WwanConfigLogType, "",
nilUUID, wc.LogKey())
logObject.Metricf("Wwan config delete")
base.DeleteLogObject(logBase, wc.LogKey())
}
// LogKey :
func (wc WwanConfig) LogKey() string {
return string(base.WwanConfigLogType) + "-" + wc.Key()
}
// WwanNetworkConfig contains configuration for a single cellular network.
// In case there are multiple SIM cards/slots in the modem, WwanNetworkConfig
// contains config only for the activated one.
type WwanNetworkConfig struct {
// Logical label in PhysicalIO.
LogicalLabel string
// Physical address of the cellular modem.
PhysAddrs WwanPhysAddrs
// Configuration of the activated Access point.
AccessPoint CellularAccessPoint
// Proxies configured for the cellular network.
Proxies []ProxyEntry
// Probe used to detect broken connection.
Probe WwanProbe
// Some LTE modems have GNSS receiver integrated and can be used
// for device location tracking.
// Enable this option to have location info periodically obtained
// from this modem and published by wwan microservice via topic WwanLocationInfo.
LocationTracking bool
// Maximum transmission unit (IP MTU) to apply on the wwan interface.
MTU uint16
// Metric assigned to routes configured for this wwan interface.
RouteMetric uint32
}
// WwanAuthProtocol : authentication protocol used by cellular network.
type WwanAuthProtocol string
const (
// WwanAuthProtocolNone : no authentication.
WwanAuthProtocolNone WwanAuthProtocol = ""
// WwanAuthProtocolPAP : Password Authentication Protocol.
WwanAuthProtocolPAP WwanAuthProtocol = "pap"
// WwanAuthProtocolCHAP : Challenge-Handshake Authentication Protocol.
WwanAuthProtocolCHAP WwanAuthProtocol = "chap"
// WwanAuthProtocolPAPAndCHAP : Both PAP and CHAP.
WwanAuthProtocolPAPAndCHAP WwanAuthProtocol = "pap-and-chap"
)
// FromProto converts proto enum CellularAuthProtocol to the corresponding WwanAuthProtocol.
func (wp *WwanAuthProtocol) FromProto(authProtocol evecommon.CellularAuthProtocol) error {
switch authProtocol {
case evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_NONE:
*wp = WwanAuthProtocolNone
case evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_PAP:
*wp = WwanAuthProtocolPAP
case evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_CHAP:
*wp = WwanAuthProtocolCHAP
case evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_PAP_AND_CHAP:
*wp = WwanAuthProtocolPAPAndCHAP
default:
*wp = WwanAuthProtocolNone
return fmt.Errorf("unrecognized cellular AuthProtocol: %+v", authProtocol)
}
return nil
}
// ToProto converts WwanAuthProtocol into the corresponding proto enum CellularAuthProtocol.
func (wp WwanAuthProtocol) ToProto() evecommon.CellularAuthProtocol {
switch wp {
case WwanAuthProtocolNone:
return evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_NONE
case WwanAuthProtocolPAP:
return evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_PAP
case WwanAuthProtocolCHAP:
return evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_CHAP
case WwanAuthProtocolPAPAndCHAP:
return evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_PAP_AND_CHAP
default:
// Return NONE as a safe default for unknown values.
return evecommon.CellularAuthProtocol_CELLULAR_AUTH_PROTOCOL_NONE
}
}
// WwanRAT : Radio Access Technology.
type WwanRAT string
const (
// WwanRATUnspecified : select RAT automatically.
WwanRATUnspecified WwanRAT = ""
// WwanRATGSM : Global System for Mobile Communications (2G).
WwanRATGSM WwanRAT = "gsm"
// WwanRATUMTS : Universal Mobile Telecommunications System (3G).
WwanRATUMTS WwanRAT = "umts"
// WwanRATLTE : Long-Term Evolution (4G).
WwanRATLTE WwanRAT = "lte"
// WwanRAT5GNR : 5th Generation New Radio (5G).
WwanRAT5GNR WwanRAT = "5gnr"
)
// WwanIPType : the IP addressing type to use for a given attach or default bearer.
type WwanIPType string
const (
// WwanIPTypeUnspecified : IP type is not specified.
WwanIPTypeUnspecified WwanIPType = ""
// WwanIPTypeIPv4 : IPv4 only.
WwanIPTypeIPv4 WwanIPType = "ipv4"
// WwanIPTypeIPv4AndIPv6 : IPv4 and IPv6.
WwanIPTypeIPv4AndIPv6 WwanIPType = "ipv4v6"
// WwanIPTypeIPv6 : IPv6 only.
WwanIPTypeIPv6 WwanIPType = "ipv6"
)
// FromProto converts proto enum CellularIPType to the corresponding WwanIPType.
func (ipt *WwanIPType) FromProto(ipType evecommon.CellularIPType) error {
switch ipType {
case evecommon.CellularIPType_CELLULAR_IP_TYPE_UNSPECIFIED:
*ipt = WwanIPTypeUnspecified
case evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV4:
*ipt = WwanIPTypeIPv4
case evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV4_AND_IPV6:
*ipt = WwanIPTypeIPv4AndIPv6
case evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV6:
*ipt = WwanIPTypeIPv6
default:
*ipt = WwanIPTypeUnspecified
return fmt.Errorf("unrecognized cellular IP type: %+v", ipType)
}
return nil
}
// ToProto converts a WwanIPType to its corresponding protobuf value.
func (ipt WwanIPType) ToProto(log *base.LogObject) evecommon.CellularIPType {
switch ipt {
case WwanIPTypeUnspecified:
return evecommon.CellularIPType_CELLULAR_IP_TYPE_UNSPECIFIED
case WwanIPTypeIPv4:
return evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV4
case WwanIPTypeIPv4AndIPv6:
return evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV4_AND_IPV6
case WwanIPTypeIPv6:
return evecommon.CellularIPType_CELLULAR_IP_TYPE_IPV6
default:
log.Errorf("Invalid wwan IP type: %v", ipt)
}
return evecommon.CellularIPType_CELLULAR_IP_TYPE_UNSPECIFIED
}
// WwanProbe : cellular connectivity verification probe.
type WwanProbe struct {
// If true, then probing is disabled.
Disable bool
// User-defined probe for cellular connectivity testing.
UserDefinedProbe ConnectivityProbe
}
// WwanCleartextCredentials stores plain-text APN credentials.
// Used only with LPS where cipher context is unavailable.
// Must never be transmitted outside of secure local use.
type WwanCleartextCredentials struct {
Username string
Password string
}
// Equal compares two instances of WwanNetworkConfig for equality.
func (wnc WwanNetworkConfig) Equal(wnc2 WwanNetworkConfig) bool {
if wnc.LogicalLabel != wnc2.LogicalLabel ||
wnc.PhysAddrs != wnc2.PhysAddrs {
return false
}
if !wnc.AccessPoint.Equal(wnc2.AccessPoint) {
return false
}
if !generics.EqualLists(wnc.Proxies, wnc2.Proxies) {
return false
}
if wnc.Probe != wnc2.Probe ||
wnc.LocationTracking != wnc2.LocationTracking ||
wnc.MTU != wnc2.MTU ||
wnc.RouteMetric != wnc2.RouteMetric {
return false
}
return true
}
// WwanPhysAddrs is a physical address of a cellular modem.
// Not all fields have to be defined. Empty WwanPhysAddrs will match the first modem found in sysfs.
// With multiple LTE modems the USB address is the most unambiguous and reliable.
type WwanPhysAddrs struct {
// Interface name.
// For example: wwan0
Interface string
// USB address in the format "<BUS>:[<PORT>]", with nested ports separated by dots.
// For example: 1:2.3
USB string
// PCI address in the long format.
// For example: 0000:00:15.0
PCI string
// Dev : device file representing the modem (e.g. /dev/cdc-wdm0).
// This address is only published as part of the wwan status
// and can't be configured from the controller.
Dev string
}
// WwanStatus is published by the wwan service and consumed by nim, zedagent and zedrouter.
type WwanStatus struct {
// DPCKey is just copied from the last applied WwanConfig.
DPCKey string
// DPCTimestamp is just copied from the last applied WwanConfig.
DPCTimestamp time.Time
// RSConfigTimestamp is just copied from the last applied WwanConfig.
RSConfigTimestamp time.Time
// One entry for every cellular modem.
Networks []WwanNetworkStatus
}
// Equal compares two instances of WwanStatus for equality.
func (ws WwanStatus) Equal(ws2 WwanStatus) bool {
if ws.DPCKey != ws2.DPCKey ||
!ws.DPCTimestamp.Equal(ws2.DPCTimestamp) ||
!ws.RSConfigTimestamp.Equal(ws2.RSConfigTimestamp) {
return false
}
return generics.EqualSetsFn(ws.Networks, ws2.Networks,
func(wns1, wns2 WwanNetworkStatus) bool {
return wns1.Equal(wns2)
})
}
// GetNetworkStatus returns pointer to the network status corresponding to the modem
// with the given logical label.
func (ws WwanStatus) GetNetworkStatus(logicalLabel string) *WwanNetworkStatus {
for i := range ws.Networks {
if ws.Networks[i].LogicalLabel == logicalLabel {
return &ws.Networks[i]
}
}
return nil
}
// DoSanitize fills in logical names for cellular modules and SIM cards.
func (ws WwanStatus) DoSanitize() {
uniqueModel := func(model string) bool {
var counter int
for i := range ws.Networks {
if ws.Networks[i].Module.Model == model {
counter++
}
}
return counter == 1
}
for i := range ws.Networks {
network := &ws.Networks[i]
if network.Module.Name == "" {
switch {
case network.Module.IMEI != "":
network.Module.Name = network.Module.IMEI
case uniqueModel(network.Module.Model):
network.Module.Name = network.Module.Model
default:
network.Module.Name = network.PhysAddrs.USB
}
}
for j := range network.SimCards {
simCard := &network.SimCards[j]
if simCard.Name == "" {
if simCard.ICCID != "" {
simCard.Name = simCard.ICCID
} else {
simCard.Name = fmt.Sprintf("%s-SIM%d",
network.Module.Name, simCard.SlotNumber)
}
}
}
}
}
// Key is used for pubsub
func (ws WwanStatus) Key() string {
return "global"
}
// LogCreate :
func (ws WwanStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.WwanStatusLogType, "",
nilUUID, ws.LogKey())
if logObject == nil {
return
}
logObject.Metricf("Wwan status create")
}
// LogModify :
func (ws WwanStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.WwanStatusLogType, "",
nilUUID, ws.LogKey())
oldWs, ok := old.(WwanStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object passed is not of WwanStatus type")
}
logObject.CloneAndAddField("diff", cmp.Diff(oldWs, ws)).
Metricf("Wwan status modify")
}
// LogDelete :
func (ws WwanStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.WwanStatusLogType, "",
nilUUID, ws.LogKey())
logObject.Metricf("Wwan status delete")
base.DeleteLogObject(logBase, ws.LogKey())
}
// LogKey :
func (ws WwanStatus) LogKey() string {
return string(base.WwanStatusLogType) + "-" + ws.Key()
}
// WwanNetworkStatus contains status information for a single cellular network
// (i.e. one modem but possibly multiple SIM slots/cards).
type WwanNetworkStatus struct {
// Logical label of the cellular modem in PhysicalIO.
// Can be empty if this device is not configured by the controller
// (and hence logical label does not exist).
LogicalLabel string
PhysAddrs WwanPhysAddrs
Module WwanCellModule
// One entry for every SIM slot (incl. those without SIM card).
SimCards []WwanSimCard
// Non-empty if the wwan microservice failed to apply config submitted by NIM.
ConfigError string
// Error message from the last connectivity probing.
ProbeError string
// Network where the modem is currently registered.
CurrentProvider WwanProvider
// All networks that the modem is able to detect.
// This will include the currently used provider as well as other visible networks.
VisibleProviders []WwanProvider
// The list of Radio Access Technologies (RATs) currently used for registering/connecting
// to the network (typically just one).
CurrentRATs []WwanRAT
// Unix timestamp in seconds made when the current connection was established.
// Zero value if the modem is not connected.
ConnectedAt uint64
// IP settings received from the network when connection is established.
IPSettings WwanIPSettings
// True if location tracking is successfully running.
LocationTracking bool
// Contains all bearers currently associated with the cellular connection,
// including the attach (initial) bearer.
Bearers []WwanBearer
// Cellular connection profiles stored on the modem.
Profiles []WwanProfile
}
// WwanCellModule contains cellular module specs.
type WwanCellModule struct {
// Name is a module identifier. For example IMEI if available.
// Guaranteed to be unique among all modems attached to the edge node.
Name string
// International Mobile Equipment Identity.
IMEI string
Model string
Manufacturer string
// Firmware version identifier.
Revision string
// QMI or MBIM.
ControlProtocol WwanCtrlProt
OpMode WwanOpMode
}
// ToProto converts internal representation of the cellular module spec
// into the corresponding proto definition from EVE API.
func (m WwanCellModule) ToProto(log *base.LogObject) *info.ZCellularModuleInfo {
var opState info.ZCellularOperatingState
switch m.OpMode {
case WwanOpModeUnspecified:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_UNSPECIFIED
case WwanOpModeOnline:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_ONLINE
case WwanOpModeConnected:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_ONLINE_AND_CONNECTED
case WwanOpModeRadioOff:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_RADIO_OFF
case WwanOpModeOffline:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_OFFLINE
case WwanOpModeUnrecognized:
opState = info.ZCellularOperatingState_Z_CELLULAR_OPERATING_STATE_UNRECOGNIZED
default:
log.Errorf("Invalid wwan module operating state: %v", m.OpMode)
}
var ctrlProto info.ZCellularControlProtocol
switch m.ControlProtocol {
case WwanCtrlProtUnspecified:
ctrlProto = info.ZCellularControlProtocol_Z_CELLULAR_CONTROL_PROTOCOL_UNSPECIFIED
case WwanCtrlProtQMI:
ctrlProto = info.ZCellularControlProtocol_Z_CELLULAR_CONTROL_PROTOCOL_QMI
case WwanCtrlProtMBIM:
ctrlProto = info.ZCellularControlProtocol_Z_CELLULAR_CONTROL_PROTOCOL_MBIM
default:
log.Errorf("Invalid wwan module control protocol: %v", m.ControlProtocol)
}
return &info.ZCellularModuleInfo{
Name: m.Name,
Imei: m.IMEI,
FirmwareVersion: m.Revision,
Model: m.Model,
Manufacturer: m.Manufacturer,
OperatingState: opState,
ControlProtocol: ctrlProto,
}
}
// WwanSimCard describes either empty SIM slot or a slot with a SIM card inserted.
type WwanSimCard struct {
// Name is a SIM card/slot identifier.
// Guaranteed to be unique across all modems and their SIM slots attached
// to the edge node.
Name string
// SIM slot number which this WwanSimCard instance describes.
SlotNumber uint8
// True if this SIM slot is activated, i.e. the inserted SIM card (if any) can be used
// to connect to a cellular network.
SlotActivated bool
// Integrated Circuit Card Identifier.
// Empty if no SIM card is inserted into the slot or if the SIM card is not recognized.
ICCID string
// International Mobile Subscriber Identity.
// Empty if no SIM card is inserted into the slot or if the SIM card is not recognized.
IMSI string
// Type of the SIM card.
Type SimType
// The current state of the SIM card (absent, initialized, not recognized, etc.).
// This state is not modeled using enum because the set of possible values differs
// between QMI and MBIM protocols (used to control cellular modules) and there is
// no 1:1 mapping between them.
State string
}
// SimType : type of the SIM card.
type SimType int32
// The values here should be same as the ones defined in info.proto of EVE API.
const (
// SimTypeUnspecified : SIM card type is not specified/known.
SimTypeUnspecified SimType = iota
// SimTypePhysical : physical SIM card.
SimTypePhysical
// SimTypeEmbedded : embedded SIM card (eSIM).
SimTypeEmbedded
)
// WwanProvider contains information about a cellular connectivity provider.
type WwanProvider struct {
// Public Land Mobile Network identifier.
PLMN string
// Human-readable label identifying the provider.
Description string
// True if this is the provider currently being used.
CurrentServing bool
// True if data roaming is ON.
Roaming bool
// True if this provider is forbidden by SIM card config.
Forbidden bool
}
// ToProto converts internal representation of the cellular network provider spec
// into the corresponding proto definition from EVE API.
func (wp WwanProvider) ToProto() (provider *info.ZCellularProvider) {
return &info.ZCellularProvider{
Plmn: wp.PLMN,
Description: wp.Description,
CurrentServing: wp.CurrentServing,
Roaming: wp.Roaming,
Forbidden: wp.Forbidden,
}
}
// WwanOpMode : wwan operating mode
type WwanOpMode string
const (
// WwanOpModeUnspecified : operating mode is not specified
WwanOpModeUnspecified WwanOpMode = ""
// WwanOpModeOnline : modem is online but not connected
WwanOpModeOnline WwanOpMode = "online"
// WwanOpModeConnected : modem is online and connected
WwanOpModeConnected WwanOpMode = "online-and-connected"
// WwanOpModeRadioOff : modem has disabled radio transmission
WwanOpModeRadioOff WwanOpMode = "radio-off"
// WwanOpModeOffline : modem is offline
WwanOpModeOffline WwanOpMode = "offline"
// WwanOpModeUnrecognized : unrecognized operating mode
WwanOpModeUnrecognized WwanOpMode = "unrecognized"
)
// WwanCtrlProt : wwan control protocol
type WwanCtrlProt string
const (
// WwanCtrlProtUnspecified : control protocol is not specified
WwanCtrlProtUnspecified WwanCtrlProt = ""
// WwanCtrlProtQMI : modem is controlled using the QMI protocol
WwanCtrlProtQMI WwanCtrlProt = "qmi"
// WwanCtrlProtMBIM : modem is controlled using the MBIM protocol
WwanCtrlProtMBIM WwanCtrlProt = "mbim"
)
// WwanIPSettings : IP settings received from the connected network.
type WwanIPSettings struct {
Address *net.IPNet
Gateway net.IP
DNSServers []net.IP
MTU uint16
}
// Equal compares two instances of WwanIPSettings for equality.
func (wips WwanIPSettings) Equal(wips2 WwanIPSettings) bool {
return netutils.EqualIPNets(wips.Address, wips2.Address) &&
netutils.EqualIPs(wips.Gateway, wips2.Gateway) &&
generics.EqualSetsFn(wips.DNSServers, wips2.DNSServers, netutils.EqualIPs) &&
wips.MTU == wips2.MTU
}
// WwanBearer represents a logical connection established between a User Equipment (UE)
// and a cellular network.
type WwanBearer struct {
// Access Point Network of the bearer.
APN string
// Purpose of the bearer.
Type BearerType
// The IP addressing type to use for the bearer.
IPType WwanIPType
// Indicates whether or not the bearer is connected.
Connected bool
// Provides additional information specifying the reason why the modem is not connected
// (either due to a failed connection attempt, or due to a network initiated disconnection).
ConnectionError string
// Unix timestamp in seconds made when the current connection was established.
// Zero value if the bearer is not connected.
ConnectedAt uint64
}
// BearerType : purpose of a given cellular bearer.
type BearerType int32
// The values here should be same as the ones defined in info.proto of EVE API.
const (
// BearerTypeUnspecified : bearer type is not specified/known.
BearerTypeUnspecified BearerType = iota
// BearerTypeAttach : bearer used for the initial attach procedure.
BearerTypeAttach
// BearerTypeDefault : default connection bearer providing packet data access
// to the network.
BearerTypeDefault
// BearerTypeDedicated : secondary context (2G/3G) or dedicated bearer (4G),
// defined by the user of the API. These bearers use the same IP address used
// by a primary context or default bearer and provide a dedicated flow for specific
// traffic with different QoS settings.
BearerTypeDedicated
)
// ToProto converts a BearerType to its corresponding protobuf enum representation.
func (bt BearerType) ToProto(log *base.LogObject) evecommon.BearerType {
switch bt {
case BearerTypeUnspecified:
return evecommon.BearerType_BEARER_TYPE_UNSPECIFIED
case BearerTypeAttach:
return evecommon.BearerType_BEARER_TYPE_ATTACH
case BearerTypeDefault:
return evecommon.BearerType_BEARER_TYPE_DEFAULT
case BearerTypeDedicated:
return evecommon.BearerType_BEARER_TYPE_DEDICATED
default:
log.Errorf("Invalid wwan bearer type: %v", bt)
}
return evecommon.BearerType_BEARER_TYPE_UNSPECIFIED
}
// WwanProfile is a modem-stored configuration that defines how the device
// connects to a network. It is used mostly during the initial attach procedure.
type WwanProfile struct {
// The name of the profile.
Name string
// Access Point Name used by the profile.
APN string
// Which bearer type this profile is for.
BearerType BearerType
// The IP addressing type used by the profile.
IPType WwanIPType
// When true, the modem will not connect to networks that require roaming
// when using this profile.
ForbidRoaming bool
}
// Equal compares two instances of WwanNetworkStatus for equality.
func (wns WwanNetworkStatus) Equal(wns2 WwanNetworkStatus) bool {
if wns.LogicalLabel != wns2.LogicalLabel ||
wns.PhysAddrs != wns2.PhysAddrs {
return false
}
if wns.Module != wns2.Module {
return false
}
if !generics.EqualSets(wns.SimCards, wns2.SimCards) {
return false
}
if wns.ConfigError != wns2.ConfigError ||
wns.ProbeError != wns2.ProbeError {
return false
}
if wns.CurrentProvider != wns2.CurrentProvider ||
!generics.EqualSets(wns.VisibleProviders, wns2.VisibleProviders) {
return false
}
if !generics.EqualSets(wns.CurrentRATs, wns2.CurrentRATs) {
return false
}
if wns.ConnectedAt != wns2.ConnectedAt ||
!wns.IPSettings.Equal(wns2.IPSettings) ||
wns.LocationTracking != wns2.LocationTracking {
return false
}
if !generics.EqualSets(wns.Bearers, wns2.Bearers) ||
!generics.EqualSets(wns.Profiles, wns2.Profiles) {
return false
}
return true
}
// CellProvidersToProto exports proto-representation of all network providers listed inside
// the WwanNetworkStatus.
func (wns WwanNetworkStatus) CellProvidersToProto() (providers []*info.ZCellularProvider) {
var includedCurrentProvider bool
for _, provider := range wns.VisibleProviders {
if provider == wns.CurrentProvider {
includedCurrentProvider = true
}
providers = append(providers, provider.ToProto())
}
if !includedCurrentProvider && wns.CurrentProvider.PLMN != "" {
providers = append(providers, wns.CurrentProvider.ToProto())
}
return providers
}
// SimCardsToProto converts internal representation of the cellular SIM cards info
// into the corresponding proto definition from EVE API.
func (wns WwanNetworkStatus) SimCardsToProto() (simCards []*info.ZSimcardInfo) {
for _, simCard := range wns.SimCards {
simCards = append(simCards, &info.ZSimcardInfo{
Name: simCard.Name,
CellModuleName: wns.Module.Name,
Imsi: simCard.IMSI,
Iccid: simCard.ICCID,
Type: info.SimType(simCard.Type),
State: simCard.State,
SlotNumber: uint32(simCard.SlotNumber),
SlotActivated: simCard.SlotActivated,
})
}
return simCards
}
// CellBearersToProto converts internal representation of the cellular bearers info
// into the corresponding proto definition from EVE API.
func (wns WwanNetworkStatus) CellBearersToProto(
log *base.LogObject) (bearers []*info.CellularBearer) {
for _, bearer := range wns.Bearers {
var connectedAt *timestamppb.Timestamp
if bearer.ConnectedAt != 0 {
connectedAt = timestamppb.New(time.Unix(int64(bearer.ConnectedAt), 0))
}
bearers = append(bearers, &info.CellularBearer{
Apn: bearer.APN,
BearerType: bearer.Type.ToProto(log),
IpType: bearer.IPType.ToProto(log),
Connected: bearer.Connected,
ConnectionError: bearer.ConnectionError,
ConnectedAt: connectedAt,
})
}
return bearers
}
// CellProfilesToProto converts internal representation of the cellular profiles info
// into the corresponding proto definition from EVE API.
func (wns WwanNetworkStatus) CellProfilesToProto(
log *base.LogObject) (profiles []*info.CellularProfile) {
for _, profile := range wns.Profiles {
profiles = append(profiles, &info.CellularProfile{
ProfileName: profile.Name,
Apn: profile.APN,
BearerType: profile.BearerType.ToProto(log),
IpType: profile.IPType.ToProto(log),
ForbidRoaming: profile.ForbidRoaming,
})
}
return profiles
}
// WwanMetrics is published by the wwan service.
type WwanMetrics struct {
Networks []WwanNetworkMetrics
}
// GetNetworkMetrics returns pointer to the network metrics corresponding to the modem
// with the given logical label.
func (wm WwanMetrics) GetNetworkMetrics(logicalLabel string) *WwanNetworkMetrics {
for i := range wm.Networks {
if wm.Networks[i].LogicalLabel == logicalLabel {
return &wm.Networks[i]
}
}
return nil
}
// Equal compares two instances of WwanMetrics for equality.
func (wm WwanMetrics) Equal(wm2 WwanMetrics) bool {
return generics.EqualSets(wm.Networks, wm2.Networks)
}
// LookupNetworkMetrics returns metrics corresponding to the given cellular network.
func (wm WwanMetrics) LookupNetworkMetrics(logicalLabel string) (WwanNetworkMetrics, bool) {
for _, metrics := range wm.Networks {
if logicalLabel == metrics.LogicalLabel {
return metrics, true
}
}
return WwanNetworkMetrics{}, false
}
// Key is used for pubsub
func (wm WwanMetrics) Key() string {
return "global"
}
// LogCreate :
func (wm WwanMetrics) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.WwanMetricsLogType, "",
nilUUID, wm.LogKey())
if logObject == nil {
return
}
logObject.Metricf("Wwan metrics create")
}
// LogModify :
func (wm WwanMetrics) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.WwanMetricsLogType, "",
nilUUID, wm.LogKey())
oldWm, ok := old.(WwanMetrics)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object passed is not of WwanMetrics type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldWm, wm)).
Metricf("Wwan metrics modify")
}
// LogDelete :
func (wm WwanMetrics) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.WwanMetricsLogType, "",
nilUUID, wm.LogKey())
logObject.Metricf("Wwan metrics delete")
base.DeleteLogObject(logBase, wm.LogKey())
}
// LogKey :
func (wm WwanMetrics) LogKey() string {
return string(base.WwanMetricsLogType) + "-" + wm.Key()
}
// ToProto converts internal representation of the cellular metrics
// into the corresponding proto definition from EVE API.
func (wm WwanMetrics) ToProto(log *base.LogObject) []*metrics.CellularMetric {
var cellularMetrics []*metrics.CellularMetric
for _, network := range wm.Networks {
if network.LogicalLabel == "" {
// skip unmanaged modems for now
continue
}
cellularMetrics = append(cellularMetrics,
&metrics.CellularMetric{
Logicallabel: network.LogicalLabel,
SignalStrength: &metrics.CellularSignalStrength{
Rssi: network.SignalInfo.RSSI,
Rsrq: network.SignalInfo.RSRQ,
Rsrp: network.SignalInfo.RSRP,
Snr: network.SignalInfo.SNR,
},
PacketStats: &metrics.CellularPacketStats{
Rx: &metrics.NetworkStats{
TotalPackets: network.PacketStats.RxPackets,
Drops: network.PacketStats.RxDrops,
TotalBytes: network.PacketStats.RxBytes,
},
Tx: &metrics.NetworkStats{
TotalPackets: network.PacketStats.TxPackets,
Drops: network.PacketStats.TxDrops,
TotalBytes: network.PacketStats.TxBytes,
},
},
})
}
return cellularMetrics
}
// WwanNetworkMetrics contains metrics for a single cellular network.
type WwanNetworkMetrics struct {
// Logical label of the cellular modem in PhysicalIO.
// Can be empty if this device is not configured by the controller
// (and hence logical label does not exist).
LogicalLabel string
PhysAddrs WwanPhysAddrs
PacketStats WwanPacketStats
SignalInfo WwanSignalInfo
}
// WwanPacketStats contains packet statistics recorded by a cellular modem.
type WwanPacketStats struct {
RxBytes uint64
RxPackets uint64
RxDrops uint64
TxBytes uint64
TxPackets uint64
TxDrops uint64
}
// WwanSignalInfo contains cellular signal strength information.
// The maximum value of int32 (0x7FFFFFFF) represents unspecified/unavailable metric.
type WwanSignalInfo struct {
// Received signal strength indicator (RSSI) measured in dBm (decibel-milliwatts).
RSSI int32
// Reference Signal Received Quality (RSRQ) measured in dB (decibels).
RSRQ int32
// Reference Signal Receive Power (RSRP) measured in dBm (decibel-milliwatts).
RSRP int32
// Signal-to-Noise Ratio (SNR) measured in dB (decibels).
SNR int32
}
// WwanLocationInfo contains device location information obtained from a GNSS
// receiver integrated into an LTE modem.
type WwanLocationInfo struct {
// Logical label of the device used to obtain this location information.
LogicalLabel string
// Latitude in the Decimal degrees (DD) notation.
// Valid values are in the range <-90, 90>. Anything outside of this range
// should be treated as an unavailable value.
// Note that wwan microservice uses -32768 specifically when latitude is not known.
Latitude float64
// Longitude in the Decimal degrees (DD) notation.
// Valid values are in the range <-180, 180>. Anything outside of this range
// should be treated as an unavailable value.
// Note that wwan microservice uses -32768 specifically when longitude is not known.
Longitude float64
// Altitude w.r.t. mean sea level in meters.
// Negative value of -32768 is returned when altitude is not known.
Altitude float64
// Circular horizontal position uncertainty in meters.
// Negative values are not valid and represent unavailable uncertainty.
// Note that wwan microservice uses -32768 specifically when horizontal
// uncertainty is not known.
HorizontalUncertainty float32
// Reliability of the provided information for latitude and longitude.
HorizontalReliability LocReliability
// Vertical position uncertainty in meters.
// Negative values are not valid and represent unavailable uncertainty.
// Note that wwan microservice uses -32768 specifically when vertical
// uncertainty is not known.
VerticalUncertainty float32
// Reliability of the provided information for altitude.
VerticalReliability LocReliability
// Unix timestamp in milliseconds.
// Zero value represents unavailable UTC timestamp.
UTCTimestamp uint64
}
// Key is used for pubsub
func (wli WwanLocationInfo) Key() string {
return "global"
}
// LogCreate :
func (wli WwanLocationInfo) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.WwanLocationInfoLogType, "",
nilUUID, wli.LogKey())
if logObject == nil {
return
}
logObject.Metricf("Wwan location info create")
}
// LogModify :
func (wli WwanLocationInfo) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.WwanLocationInfoLogType, "",
nilUUID, wli.LogKey())
oldWli, ok := old.(WwanLocationInfo)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object passed is not of WwanLocationInfo type")
}
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldWli, wli)).