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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
#include <map>
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros/network_constants.h"
#include "chrome/browser/chromeos/cros/network_ui_data.h"
#include "chromeos/network/network_ip_config.h"
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_constants.h"
namespace base {
class DictionaryValue;
class Value;
} // namespace base
namespace chromeos {
class NetworkDeviceParser;
class NetworkParser;
class CertificatePattern;
// This is the list of all implementation classes that are allowed
// access to the internals of the network library classes.
#define NETWORK_LIBRARY_IMPL_FRIENDS \
friend class NetworkLibraryImplBase; \
friend class NetworkLibraryImplCros; \
friend class NetworkLibraryImplStub;
// Simple wrapper for property Cellular.FoundNetworks.
struct FoundCellularNetwork {
FoundCellularNetwork();
~FoundCellularNetwork();
std::string status;
std::string network_id;
std::string short_name;
std::string long_name;
std::string technology;
};
typedef std::vector<FoundCellularNetwork> CellularNetworkList;
struct CellularApn {
std::string apn;
std::string network_id;
std::string username;
std::string password;
std::string name;
std::string localized_name;
std::string language;
CellularApn();
CellularApn(const std::string& apn, const std::string& network_id,
const std::string& username, const std::string& password);
~CellularApn();
void Set(const base::DictionaryValue& dict);
};
typedef std::vector<CellularApn> CellularApnList;
// The value of priority if it is not set.
const int kPriorityNotSet = 0;
// The value of priority if network is preferred.
const int kPriorityPreferred = 1;
// Contains data related to the shill.Device interface,
// e.g. ethernet, wifi, cellular.
// TODO(dpolukhin): refactor to make base class and device specific derivatives.
class NetworkDevice {
public:
explicit NetworkDevice(const std::string& device_path);
~NetworkDevice();
NetworkDeviceParser* device_parser() { return device_parser_.get(); }
void SetNetworkDeviceParser(NetworkDeviceParser* parser);
// Device info.
const std::string& device_path() const { return device_path_; }
const std::string& name() const { return name_; }
const std::string& unique_id() const { return unique_id_; }
ConnectionType type() const { return type_; }
bool scanning() const { return scanning_; }
const std::string& meid() const { return meid_; }
const std::string& iccid() const { return iccid_; }
const std::string& imei() const { return imei_; }
const std::string& imsi() const { return imsi_; }
const std::string& esn() const { return esn_; }
const std::string& mdn() const { return mdn_; }
const std::string& min() const { return min_; }
const std::string& model_id() const { return model_id_; }
const std::string& manufacturer() const { return manufacturer_; }
SimLockState sim_lock_state() const { return sim_lock_state_; }
bool is_sim_locked() const {
return sim_lock_state_ == SIM_LOCKED_PIN ||
sim_lock_state_ == SIM_LOCKED_PUK;
}
// Returns true if GSM modem and SIM as absent, otherwise
// returns false: GSM modem and SIM card is present or CDMA modem.
bool is_sim_absent() const {
return technology_family() == TECHNOLOGY_FAMILY_GSM &&
!is_sim_locked() && !sim_present_;
}
int sim_retries_left() const { return sim_retries_left_; }
SimPinRequire sim_pin_required() const { return sim_pin_required_; }
bool powered() const { return powered_; }
const std::string& firmware_revision() const { return firmware_revision_; }
const std::string& hardware_revision() const { return hardware_revision_; }
const unsigned int prl_version() const { return prl_version_; }
const std::string& home_provider_code() const { return home_provider_code_; }
const std::string& home_provider_country() const {
return home_provider_country_;
}
const std::string& home_provider_id() const { return home_provider_id_; }
const std::string& home_provider_name() const { return home_provider_name_; }
const bool provider_requires_roaming() const {
return provider_requires_roaming_;
}
const std::string& selected_cellular_network() const {
return selected_cellular_network_;
}
const CellularNetworkList& found_cellular_networks() const {
return found_cellular_networks_;
}
bool data_roaming_allowed() const { return data_roaming_allowed_; }
bool support_network_scan() const { return support_network_scan_; }
std::string carrier() const { return carrier_; }
base::ListValue* supported_carriers() const {
return supported_carriers_.get();
}
enum TechnologyFamily technology_family() const { return technology_family_; }
const CellularApnList& provider_apn_list() const {
return provider_apn_list_;
}
// Updates the property specified by |key| with the contents of
// |value|. Returns false on failure. Upon success, returns the
// PropertyIndex that was updated in |index|. |index| may be NULL
// if not needed.
bool UpdateStatus(const std::string& key,
const base::Value& value,
PropertyIndex* index);
protected:
void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; }
private:
// This allows NetworkDeviceParser and its subclasses access to
// device privates so that they can be reconstituted during parsing.
// The parsers only access things through the private set_ functions
// so that this class can evolve without having to change all the
// parsers.
friend class NativeNetworkDeviceParser;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
// Use these functions at your peril. They are used by the various
// parsers to set state, and really shouldn't be used by anyone
// else.
void set_device_path(const std::string& device_path) {
device_path_ = device_path;
}
void set_name(const std::string& name) { name_ = name; }
void set_type(ConnectionType type) { type_ = type; }
void set_scanning(bool scanning) { scanning_ = scanning; }
void set_meid(const std::string& meid) { meid_ = meid; }
void set_iccid(const std::string& iccid) { iccid_ = iccid; }
void set_imei(const std::string& imei) { imei_ = imei; }
void set_imsi(const std::string& imsi) { imsi_ = imsi; }
void set_esn(const std::string& esn) { esn_ = esn; }
void set_mdn(const std::string& mdn) { mdn_ = mdn; }
void set_min(const std::string& min) { min_ = min; }
void set_technology_family(TechnologyFamily technology_family) {
technology_family_ = technology_family;
}
void set_carrier(const std::string& carrier) { carrier_ = carrier; }
void set_supported_carriers(const base::ListValue& supported_carriers) {
supported_carriers_.reset(supported_carriers.DeepCopy());
}
void set_home_provider_code(const std::string& home_provider_code) {
home_provider_code_ = home_provider_code;
}
void set_home_provider_country(const std::string& home_provider_country) {
home_provider_country_ = home_provider_country;
}
void set_home_provider_id(const std::string& home_provider_id) {
home_provider_id_ = home_provider_id;
}
void set_home_provider_name(const std::string& home_provider_name) {
home_provider_name_ = home_provider_name;
}
void set_provider_requires_roaming(bool provider_requires_roaming) {
provider_requires_roaming_ = provider_requires_roaming;
}
void set_model_id(const std::string& model_id) { model_id_ = model_id; }
void set_manufacturer(const std::string& manufacturer) {
manufacturer_ = manufacturer;
}
void set_prl_version(int prl_version) {
prl_version_ = prl_version;
}
void set_sim_lock_state(SimLockState sim_lock_state) {
sim_lock_state_ = sim_lock_state;
}
void set_sim_retries_left(int sim_retries_left) {
sim_retries_left_ = sim_retries_left;
}
void set_sim_pin_required(SimPinRequire sim_pin_required) {
sim_pin_required_ = sim_pin_required;
}
void set_sim_present(bool sim_present) {
sim_present_ = sim_present;
}
void set_powered(bool powered) {
powered_ = powered;
}
void set_firmware_revision(const std::string& firmware_revision) {
firmware_revision_ = firmware_revision;
}
void set_hardware_revision(const std::string& hardware_revision) {
hardware_revision_ = hardware_revision;
}
void set_selected_cellular_network(
const std::string& selected_cellular_network) {
selected_cellular_network_ = selected_cellular_network;
}
void set_found_cellular_networks(
const CellularNetworkList& found_cellular_networks) {
found_cellular_networks_ = found_cellular_networks;
}
void set_data_roaming_allowed(bool data_roaming_allowed) {
data_roaming_allowed_ = data_roaming_allowed;
}
void set_support_network_scan(bool support_network_scan) {
support_network_scan_ = support_network_scan;
}
void set_provider_apn_list(const CellularApnList& provider_apn_list) {
provider_apn_list_ = provider_apn_list;
}
void ParseInfo(const base::DictionaryValue& info);
// General device info.
std::string device_path_;
std::string name_;
std::string unique_id_;
ConnectionType type_;
bool scanning_;
// Cellular specific device info.
TechnologyFamily technology_family_;
std::string carrier_;
scoped_ptr<base::ListValue> supported_carriers_;
std::string home_provider_code_;
std::string home_provider_country_;
std::string home_provider_id_;
std::string home_provider_name_;
bool provider_requires_roaming_;
std::string meid_;
std::string imei_;
std::string iccid_;
std::string imsi_;
std::string esn_;
std::string mdn_;
std::string min_;
std::string model_id_;
std::string manufacturer_;
SimLockState sim_lock_state_;
int sim_retries_left_;
SimPinRequire sim_pin_required_;
bool sim_present_;
bool powered_;
std::string firmware_revision_;
std::string hardware_revision_;
int prl_version_;
std::string selected_cellular_network_;
CellularNetworkList found_cellular_networks_;
bool data_roaming_allowed_;
bool support_network_scan_;
CellularApnList provider_apn_list_;
// This is the parser we use to parse messages from the native
// network layer.
scoped_ptr<NetworkDeviceParser> device_parser_;
DISALLOW_COPY_AND_ASSIGN(NetworkDevice);
};
// A virtual class that can be used to handle certificate enrollment URIs when
// encountered. Also used by unit tests to avoid opening browser windows
// when testing.
class EnrollmentDelegate {
public:
EnrollmentDelegate() {}
virtual ~EnrollmentDelegate() {}
// Implemented to handle a given certificate enrollment URI. Returns false
// if the enrollment URI doesn't use a scheme that we can handle, and in
// that case, this will be called for any remaining enrollment URIs.
// If enrollment succeeds, then the enrollment handler must run
// |post_action| to finish connecting.
virtual void Enroll(const std::vector<std::string>& uri_list,
const base::Closure& post_action) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(EnrollmentDelegate);
};
// Contains data common to all network service types.
class Network {
public:
virtual ~Network();
// Test API for accessing setters in tests.
class TestApi {
public:
explicit TestApi(Network* network) : network_(network) {}
void SetBehindPortal() {
network_->set_is_behind_portal_for_testing(true);
network_->set_behind_portal();
}
void SetConnected() {
network_->set_is_behind_portal_for_testing(false);
network_->set_connected();
}
void SetConnecting() {
network_->set_connecting();
}
void SetDisconnected() {
network_->set_disconnected();
}
void SetUserConnectState(UserConnectState user_connect_state) {
network_->set_user_connect_state(user_connect_state);
}
private:
Network* network_;
};
friend class TestApi;
// Structure used only for parsing ONC's ProxySettings value.
struct ProxyOncConfig {
ProxyOncConfig();
ProxyOncType type;
std::string pac_url; // Only for PROXY_TYPE_PAC.
// Concatenated string of manual proxies only for PROXY_TYPE_MANUAL,
// formatted using chromeos::ProxyConfigServiceImpl::ProxyConfig::
// EncodeAndAppendProxyServer.
std::string manual_spec;
std::string bypass_rules; // Only for PROXY_TYPE_MANUAL.
};
const std::string& service_path() const { return service_path_; }
const std::string& name() const { return name_; }
const std::string& device_path() const { return device_path_; }
const std::string& ip_address() const { return ip_address_; }
ConnectionType type() const { return type_; }
ConnectionMode mode() const { return mode_; }
ConnectionState connection_state() const { return state_; }
bool connecting() const { return IsConnectingState(state_); }
bool configuring() const { return state_ == STATE_CONFIGURATION; }
bool connected() const { return IsConnectedState(state_); }
bool connecting_or_connected() const { return connecting() || connected(); }
// True when a user-initiated connection attempt is in progress
bool connection_started() const {
return user_connect_state_ == USER_CONNECT_STARTED;
}
UserConnectState user_connect_state() const { return user_connect_state_; }
bool failed() const { return state_ == STATE_FAILURE; }
bool disconnected() const { return IsDisconnectedState(state_); }
bool ready() const { return state_ == STATE_READY; }
bool online() const { return state_ == STATE_ONLINE; }
bool restricted_pool() const { return state_ == STATE_PORTAL; }
ConnectionError error() const { return error_; }
ConnectionState state() const { return state_; }
// Is this network connectable. Currently, this is mainly used by 802.1x
// networks to specify that the network is not configured yet.
bool connectable() const { return connectable_; }
// Is this the active network, i.e, the one through which
// network traffic is being routed? A network can be connected,
// but not be carrying traffic.
bool is_active() const { return is_active_; }
bool preferred() const { return priority_ != kPriorityNotSet; }
bool auto_connect() const { return auto_connect_; }
bool save_credentials() const { return save_credentials_; }
bool added() const { return added_; }
bool notify_failure() const { return notify_failure_; }
const std::string& profile_path() const { return profile_path_; }
NetworkProfileType profile_type() const { return profile_type_; }
const std::string& unique_id() const { return unique_id_; }
int priority_order() const { return priority_order_; }
const std::string& proxy_config() const { return proxy_config_; }
const NetworkUIData& ui_data() const { return ui_data_; }
ProxyOncConfig& proxy_onc_config() { return proxy_onc_config_; }
void set_notify_failure(bool state) { notify_failure_ = state; }
void SetPreferred(bool preferred);
void SetAutoConnect(bool auto_connect);
void SetName(const std::string& name);
void SetSaveCredentials(bool save_credentials);
void ClearUIData();
// This will resolve any automatic configuration that has to occur
// (provisioning certificates, etc.) before attempting to connect to the
// network. When configuration is complete, calls the closure to finish the
// connection or show the config dialog to collect user-supplied info.
virtual void AttemptConnection(const base::Closure& connect);
// Return a string representation of the state code.
std::string GetStateString() const;
// Return a string representation of the error code.
std::string GetErrorString() const;
void SetProxyConfig(const std::string& proxy_config);
// Return true if the network must be in the user profile (e.g. has certs).
virtual bool RequiresUserProfile() const;
// Copy any credentials from a remembered network that are unset in |this|.
virtual void CopyCredentialsFromRemembered(Network* remembered);
// Static helper functions.
static bool IsConnectedState(ConnectionState state) {
return (state == STATE_READY ||
state == STATE_ONLINE ||
state == STATE_PORTAL);
}
static bool IsConnectingState(ConnectionState state) {
return (state == STATE_CONNECT_REQUESTED ||
state == STATE_ASSOCIATION ||
state == STATE_CONFIGURATION ||
state == STATE_CARRIER);
}
static bool IsDisconnectedState(ConnectionState state) {
return (state == STATE_UNKNOWN ||
state == STATE_IDLE ||
state == STATE_DISCONNECT ||
state == STATE_FAILURE ||
state == STATE_ACTIVATION_FAILURE);
}
// Adopts the given enrollment handler to handle any certificate enrollment
// URIs encountered during network connection.
void SetEnrollmentDelegate(EnrollmentDelegate* delegate) {
enrollment_delegate_.reset(delegate);
}
virtual bool UpdateStatus(const std::string& key,
const base::Value& value,
PropertyIndex* index);
// Retrieves a property from the property_map_. If |value| is NULL,
// just returns whether or not the given property was found.
bool GetProperty(PropertyIndex index, const base::Value** value) const;
// Creates a Network object for the given type for testing.
static Network* CreateForTesting(ConnectionType type);
protected:
Network(const std::string& service_path,
ConnectionType type);
NetworkParser* network_parser() { return network_parser_.get(); }
void SetNetworkParser(NetworkParser* parser);
// Updates |property_map_| for the corresponding property |index|. If |value|
// is non-NULL, it's put into the map. Otherwise, the entry is removed.
void UpdatePropertyMap(PropertyIndex index, const base::Value* value);
// Set the state and update flags if necessary.
void SetState(ConnectionState state);
// Set the error state and update notify_failure_
void SetError(ConnectionError error);
// Parse name/value pairs from libcros.
virtual void ParseInfo(const base::DictionaryValue& info);
// Erase cached credentials, used when "Save password" is unchecked.
virtual void EraseCredentials();
// Calculate a unique identifier for the network.
virtual void CalculateUniqueId();
// Methods to asynchronously set network service properties
virtual void SetStringProperty(const char* prop, const std::string& str,
std::string* dest);
virtual void SetBooleanProperty(const char* prop, bool b, bool* dest);
virtual void SetIntegerProperty(const char* prop, int i, int* dest);
virtual void SetValueProperty(const char* prop, const base::Value& val);
virtual void ClearProperty(const char* prop);
// This will clear the property if string is empty. Otherwise, it will set it.
virtual void SetOrClearStringProperty(const char* prop,
const std::string& str,
std::string* dest);
void set_unique_id(const std::string& unique_id) { unique_id_ = unique_id; }
const CertificatePattern& client_cert_pattern() const {
return ui_data_.certificate_pattern();
}
ClientCertType client_cert_type() const {
return ui_data_.certificate_type();
}
EnrollmentDelegate* enrollment_delegate() const {
return enrollment_delegate_.get();
}
private:
typedef std::map<PropertyIndex, base::Value*> PropertyMap;
// This allows NetworkParser and its subclasses access to device
// privates so that they can be reconstituted during parsing. The
// parsers only access things through the private set_ functions so
// that this class can evolve without having to change all the
// parsers.
friend class NetworkParser;
friend class NativeNetworkParser;
friend class NativeVirtualNetworkParser;
friend class OncWifiNetworkParser;
friend class OncVirtualNetworkParser;
// We reach directly into the network for testing purposes.
friend class MobileActivatorTest;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
FRIEND_TEST_ALL_PREFIXES(NetworkLibraryTest, GetUserExpandedValue);
FRIEND_TEST_ALL_PREFIXES(NetworkLibraryStubTest, NetworkConnectOncWifi);
FRIEND_TEST_ALL_PREFIXES(NetworkLibraryStubTest, NetworkConnectOncVPN);
// Use these functions at your peril. They are used by the various
// parsers to set state, and really shouldn't be used by anything else
// because they don't do the error checking and sending to the
// network layer that the other setters do.
void set_device_path(const std::string& device_path) {
device_path_ = device_path;
}
void set_name(const std::string& name) { name_ = name; }
void set_mode(ConnectionMode mode) { mode_ = mode; }
void set_connecting() {
state_ = STATE_CONNECT_REQUESTED;
}
void set_is_behind_portal_for_testing(bool value) {
is_behind_portal_for_testing_ = value;
}
bool is_behind_portal_for_testing() const {
return is_behind_portal_for_testing_;
}
void set_behind_portal() {
state_ = STATE_PORTAL;
}
void set_connected() {
state_ = STATE_ONLINE;
}
void set_disconnected() {
state_ = STATE_IDLE;
}
void set_connectable(bool connectable) { connectable_ = connectable; }
void set_user_connect_state(UserConnectState user_connect_state) {
user_connect_state_ = user_connect_state;
}
void set_is_active(bool is_active) { is_active_ = is_active; }
void set_added(bool added) { added_ = added; }
void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; }
void set_save_credentials(bool save_credentials) {
save_credentials_ = save_credentials;
}
void set_profile_path(const std::string& path) { profile_path_ = path; }
void set_profile_type(NetworkProfileType type) { profile_type_ = type; }
void set_proxy_config(const std::string& proxy) { proxy_config_ = proxy; }
void set_ui_data(const NetworkUIData& ui_data) {
ui_data_ = ui_data;
}
void set_client_cert_pattern(const CertificatePattern& pattern) {
ui_data_.set_certificate_pattern(pattern);
}
void set_client_cert_type(ClientCertType type) {
ui_data_.set_certificate_type(type);
}
// Set the profile path and update the flimflam property.
void SetProfilePath(const std::string& profile_path);
// Trigger an asynchronous initialization the IP address field.
void InitIPAddress();
// Initialize the IP address field.
static void InitIPAddressCallback(
const std::string& service_path,
const NetworkIPConfigVector& ip_configs,
const std::string& hardware_address);
std::string device_path_;
std::string name_;
std::string ip_address_;
ConnectionMode mode_;
ConnectionState state_;
ConnectionError error_;
bool connectable_;
UserConnectState user_connect_state_;
bool is_active_;
int priority_; // determines order in network list.
bool auto_connect_;
bool save_credentials_; // save passphrase and EAP credentials to disk.
std::string proxy_config_; // ProxyConfig property in shill.
ProxyOncConfig proxy_onc_config_; // Only used for parsing ONC proxy value.
scoped_ptr<EnrollmentDelegate> enrollment_delegate_;
// Unique identifier, set the first time the network is parsed.
std::string unique_id_;
// Priority value, corresponds to index in list from shill (0 = first)
int priority_order_;
// Set to true if the UI requested this as a new network.
bool added_;
// Set to true when a new connection failure occurs; cleared when observers
// are notified.
bool notify_failure_;
// Profile path for networks.
std::string profile_path_;
// Set to profile type based on profile_path_.
NetworkProfileType profile_type_;
// These must not be modified after construction.
std::string service_path_;
ConnectionType type_;
// UI-level state that is opaque to the connection manager. The value is
// stored in JSON-serialized from in the connection manager.
NetworkUIData ui_data_;
// This is the parser we use to parse messages from the native
// network layer.
scoped_ptr<NetworkParser> network_parser_;
// This map stores the set of properties for the network.
// Not all properties in this map are exposed via get methods.
PropertyMap property_map_;
bool is_behind_portal_for_testing_;
DISALLOW_COPY_AND_ASSIGN(Network);
};
// Class for networks of TYPE_ETHERNET.
class EthernetNetwork : public Network {
public:
explicit EthernetNetwork(const std::string& service_path);
private:
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
DISALLOW_COPY_AND_ASSIGN(EthernetNetwork);
};
// Class for networks of TYPE_VPN.
class VirtualNetwork : public Network {
public:
explicit VirtualNetwork(const std::string& service_path);
virtual ~VirtualNetwork();
const std::string& server_hostname() const { return server_hostname_; }
ProviderType provider_type() const { return provider_type_; }
const std::string& ca_cert_nss() const { return ca_cert_nss_; }
const std::string& psk_passphrase() const { return psk_passphrase_; }
bool psk_passphrase_required() const { return psk_passphrase_required_; }
const std::string& client_cert_id() const { return client_cert_id_; }
const std::string& username() const { return username_; }
const std::string& user_passphrase() const { return user_passphrase_; }
bool user_passphrase_required() const { return user_passphrase_required_; }
const std::string& group_name() const { return group_name_; }
// Sets the well-known PKCS#11 slot and PIN for accessing certificates.
void SetCertificateSlotAndPin(
const std::string& slot, const std::string& pin);
// Network overrides.
virtual bool RequiresUserProfile() const OVERRIDE;
virtual void CopyCredentialsFromRemembered(Network* remembered) OVERRIDE;
virtual void AttemptConnection(const base::Closure& connect) OVERRIDE;
// Public getters.
bool NeedMoreInfoToConnect() const;
std::string GetProviderTypeString() const;
// Returns true if a PSK passphrase is required to connect.
bool IsPSKPassphraseRequired() const;
// Returns true if a user passphrase is required to connect.
bool IsUserPassphraseRequired() const;
// Public setters.
void SetCACertNSS(const std::string& ca_cert_nss);
void SetL2TPIPsecPSKCredentials(const std::string& psk_passphrase,
const std::string& username,
const std::string& user_passphrase,
const std::string& group_name);
void SetL2TPIPsecCertCredentials(const std::string& client_cert_id,
const std::string& username,
const std::string& user_passphrase,
const std::string& group_name);
void SetOpenVPNCredentials(const std::string& client_cert_id,
const std::string& username,
const std::string& user_passphrase,
const std::string& otp);
void SetServerHostname(const std::string& server_hostname);
private:
// This allows NetworkParser and its subclasses access to
// device privates so that they can be reconstituted during parsing.
// The parsers only access things through the private set_ functions
// so that this class can evolve without having to change all the
// parsers.
friend class NativeNetworkParser;
friend class NativeVirtualNetworkParser;
friend class OncVirtualNetworkParser;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
// Use these functions at your peril. They are used by the various
// parsers to set state, and really shouldn't be used by anything else
// because they don't do the error checking and sending to the
// network layer that the other setters do.
void set_server_hostname(const std::string& server_hostname) {
server_hostname_ = server_hostname;
}
void set_provider_type(ProviderType provider_type) {
provider_type_ = provider_type;
}
void set_ca_cert_nss(const std::string& ca_cert_nss) {
ca_cert_nss_ = ca_cert_nss;
}
void set_psk_passphrase(const std::string& psk_passphrase) {
psk_passphrase_ = psk_passphrase;
}
void set_psk_passphrase_required(bool psk_passphrase_required) {
psk_passphrase_required_ = psk_passphrase_required;
}
void set_client_cert_id(const std::string& client_cert_id) {
client_cert_id_ = client_cert_id;
}
void set_username(const std::string& username) { username_ = username; }
void set_user_passphrase(const std::string& user_passphrase) {
user_passphrase_ = user_passphrase;
}
void set_user_passphrase_required(bool user_passphrase_required) {
user_passphrase_required_ = user_passphrase_required;
}
void set_group_name(const std::string& group_name) {
group_name_ = group_name;
}
// Matches the client certificate pattern by checking to see if a certificate
// exists that meets the pattern criteria. If it finds one, it sets the
// appropriate network property. If not, it passes |connect| to the
// EnrollmentDelegate to do something with the enrollment URI (e.g. launch a
// dialog) to install the certificate, and then invoke |connect|. If
// |allow_enroll| is false, then the enrollment handler will not be invoked in
// the case of a missing certificate.
void MatchCertificatePattern(bool allow_enroll, const base::Closure& connect);
// Network overrides.
virtual void EraseCredentials() OVERRIDE;
virtual void CalculateUniqueId() OVERRIDE;
// VirtualNetwork private methods.
bool ParseProviderValue(int index, const base::Value* value);
std::string server_hostname_;
ProviderType provider_type_;
// NSS nickname for server CA certificate.
std::string ca_cert_nss_;
std::string psk_passphrase_;
bool psk_passphrase_required_;
// PKCS#11 ID for client certificate.
std::string client_cert_id_;
std::string username_;
std::string user_passphrase_;
bool user_passphrase_required_;
std::string group_name_;
// Weak pointer factory for wrapping pointers to this network in callbacks.
base::WeakPtrFactory<VirtualNetwork> weak_pointer_factory_;
DISALLOW_COPY_AND_ASSIGN(VirtualNetwork);
};
typedef std::vector<VirtualNetwork*> VirtualNetworkVector;
// Base class for networks of TYPE_WIFI or TYPE_CELLULAR.
class WirelessNetwork : public Network {
public:
// Test API for accessing setters in tests.
class TestApi {
public:
explicit TestApi(WirelessNetwork* network) : network_(network) {}
void SetStrength(int strength) { network_->set_strength(strength); }
private:
WirelessNetwork* network_;
};
friend class TestApi;
int strength() const { return strength_; }
protected:
WirelessNetwork(const std::string& service_path,
ConnectionType type)
: Network(service_path, type), strength_(0) {}
private:
// This allows NativeWirelessNetworkParser access to device privates
// so that they can be reconstituted during parsing. The parsers
// only access things through the private set_ functions so that
// this class can evolve without having to change all the parsers.
friend class NativeWirelessNetworkParser;
friend class OncWirelessNetworkParser;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
// The friend parsers use this.
void set_strength(int strength) { strength_ = strength; }
int strength_; // 0-100
DISALLOW_COPY_AND_ASSIGN(WirelessNetwork);
};
// Class for networks of TYPE_CELLULAR.
class CellularNetwork : public WirelessNetwork {
public:
// Test API for accessing setters in tests.
class TestApi {
public:
explicit TestApi(CellularNetwork* network) : network_(network) {}
void SetRoamingState(NetworkRoamingState roaming_state) {
network_->set_roaming_state(roaming_state);
}
private:
CellularNetwork* network_;
};
friend class TestApi;
explicit CellularNetwork(const std::string& service_path);
virtual ~CellularNetwork();
// Starts device activation process. Returns false if the device state does
// not permit activation.
virtual bool StartActivation();
virtual void CompleteActivation();
bool activate_over_non_cellular_network() const {
return activate_over_non_cellular_network_;
}
const ActivationState activation_state() const { return activation_state_; }
bool activated() const {
return activation_state() == ACTIVATION_STATE_ACTIVATED;
}
const NetworkTechnology network_technology() const {
return network_technology_;
}
const NetworkRoamingState roaming_state() const { return roaming_state_; }
const std::string& operator_name() const { return operator_name_; }
const std::string& operator_code() const { return operator_code_; }
const std::string& operator_country() const { return operator_country_; }
const std::string& payment_url() const { return payment_url_; }
const std::string& usage_url() const { return usage_url_; }
const std::string& post_data() const { return post_data_; }
const bool using_post() const { return using_post_; }
const CellularApn& apn() const { return apn_; }
const CellularApn& last_good_apn() const { return last_good_apn_; }
// Sets the APN to use in establishing data connections. Only
// the fields of the APN that are needed for making connections
// are passed to shill. The name, localized_name, and language
// fields are ignored.
void SetApn(const CellularApn& apn);
// Returns true if network supports activation.
bool SupportsActivation() const;
// Returns whether the network needs to be activated.
bool NeedsActivation() const;
// Return a string representation of network technology.
std::string GetNetworkTechnologyString() const;
// Return a string representation of activation state.
std::string GetActivationStateString() const;
// Return a string representation of roaming state.
std::string GetRoamingStateString() const;
// Return a string representation of |activation_state|.
static std::string ActivationStateToString(ActivationState activation_state);
private:
// This allows NativeCellularNetworkParser access to device privates
// so that they can be reconstituted during parsing. The parsers
// only access things through the private set_ functions so that
// this class can evolve without having to change all the parsers.
friend class NativeCellularNetworkParser;
friend class OncCellularNetworkParser;
// We reach directly into the network for testing purposes.
friend class MobileActivatorTest;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
// Use these functions at your peril. They are used by the various
// parsers to set state, and really shouldn't be used by anything else
// because they don't do the error checking and sending to the
// network layer that the other setters do.
void set_activate_over_non_cellular_network(bool value) {
activate_over_non_cellular_network_ = value;
}
void set_activation_state(ActivationState activation_state) {
activation_state_ = activation_state;
}
void set_network_technology(NetworkTechnology network_technology) {
network_technology_ = network_technology;
}
void set_roaming_state(NetworkRoamingState roaming_state) {
roaming_state_ = roaming_state;
}
void set_operator_name(const std::string& operator_name) {
operator_name_ = operator_name;
}
void set_operator_code(const std::string& operator_code) {
operator_code_ = operator_code;
}
void set_operator_country(const std::string& operator_country) {
operator_country_ = operator_country;
}
void set_payment_url(const std::string& payment_url) {
payment_url_ = payment_url;
}
void set_post_data(const std::string& post_data) {
post_data_ = post_data;
}
void set_using_post(bool using_post) {
using_post_ = using_post;
}
void set_usage_url(const std::string& usage_url) { usage_url_ = usage_url; }
void set_apn(const base::DictionaryValue& apn) { apn_.Set(apn); }
void set_last_good_apn(const base::DictionaryValue& last_good_apn) {
last_good_apn_.Set(last_good_apn);
}
bool activate_over_non_cellular_network_;
ActivationState activation_state_;
NetworkTechnology network_technology_;
NetworkRoamingState roaming_state_;
// Carrier Info
std::string operator_name_;
std::string operator_code_;
std::string operator_country_;
std::string payment_url_;
std::string usage_url_;
std::string post_data_;
bool using_post_;
// Cached values
CellularApn apn_;
CellularApn last_good_apn_;
DISALLOW_COPY_AND_ASSIGN(CellularNetwork);
};
typedef std::vector<CellularNetwork*> CellularNetworkVector;
// Class for networks of TYPE_WIFI.
class WifiNetwork : public WirelessNetwork {
public:
// Test API for accessing setters in tests.
class TestApi {
public:
explicit TestApi(WifiNetwork* network) : network_(network) {}
void SetEncryption(ConnectionSecurity encryption) {
network_->set_encryption(encryption);
}
void SetSsid(const std::string& ssid) {
network_->SetSsid(ssid);
}
void SetHexSsid(const std::string& ssid_hex) {
network_->SetHexSsid(ssid_hex);
}
private:
WifiNetwork* network_;
};
friend class TestApi;
explicit WifiNetwork(const std::string& service_path);
virtual ~WifiNetwork();
bool encrypted() const { return encryption_ != SECURITY_NONE; }
ConnectionSecurity encryption() const { return encryption_; }
const std::string& passphrase() const { return passphrase_; }
const std::string& identity() const { return identity_; }
bool passphrase_required() const { return passphrase_required_; }
bool hidden_ssid() const { return hidden_ssid_; }
const std::string& bssid() const { return bssid_; }
int frequency() const { return frequency_; }
EAPMethod eap_method() const { return eap_method_; }
EAPPhase2Auth eap_phase_2_auth() const { return eap_phase_2_auth_; }
const std::string& eap_server_ca_cert_nss_nickname() const {
return eap_server_ca_cert_nss_nickname_; }
const std::string& eap_client_cert_pkcs11_id() const {
return eap_client_cert_pkcs11_id_; }
const bool eap_use_system_cas() const { return eap_use_system_cas_; }
const std::string& eap_identity() const { return eap_identity_; }
const std::string& eap_anonymous_identity() const {
return eap_anonymous_identity_;
}
const std::string& eap_passphrase() const { return eap_passphrase_; }
const bool eap_save_credentials() const { return eap_save_credentials_; }
const std::string& GetPassphrase() const;
// Set property and call SetNetworkServiceProperty:
void SetPassphrase(const std::string& passphrase);
void SetIdentity(const std::string& identity);
void SetHiddenSSID(bool hidden_ssid);
// 802.1x properties
void SetEAPMethod(EAPMethod method);
void SetEAPPhase2Auth(EAPPhase2Auth auth);
void SetEAPServerCaCertNssNickname(const std::string& nss_nickname);
void SetEAPClientCertPkcs11Id(const std::string& pkcs11_id);
void SetEAPUseSystemCAs(bool use_system_cas);
void SetEAPIdentity(const std::string& identity);
void SetEAPAnonymousIdentity(const std::string& identity);
void SetEAPPassphrase(const std::string& passphrase);
// Sets the well-known PKCS#11 PIN for accessing certificates.
void SetCertificatePin(const std::string& pin);
// Network overrides.
virtual bool RequiresUserProfile() const OVERRIDE;
virtual void AttemptConnection(const base::Closure& connect) OVERRIDE;
// Return a string representation of the encryption code.
// This not translated and should be only used for debugging purposes.
std::string GetEncryptionString() const;
// Return true if a passphrase or other input is required to connect.
bool IsPassphraseRequired() const;
protected:
// This allows NativeWifiNetworkParser access to device privates so
// that they can be reconstituted during parsing. The parsers only
// access things through the private set_ functions so that this
// class can evolve without having to change all the parsers.
friend class NativeWifiNetworkParser;
friend class OncWifiNetworkParser;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
// Use these functions at your peril. They are used by the various
// parsers to set state, and really shouldn't be used by anything else
// because they don't do the error checking and sending to the
// network layer that the other setters do.
bool SetSsid(const std::string& ssid);
bool SetHexSsid(const std::string& ssid_hex);
void set_encryption(ConnectionSecurity encryption) {
encryption_ = encryption;
}
void set_passphrase(const std::string& passphrase) {
passphrase_ = passphrase;
user_passphrase_ = passphrase;
}
void set_passphrase_required(bool passphrase_required) {
passphrase_required_ = passphrase_required;
}
void set_identity(const std::string& identity) {
identity_ = identity;
}
void set_hidden_ssid(bool hidden_ssid) {
hidden_ssid_ = hidden_ssid;
}
void set_bssid(const std::string& bssid) { bssid_ = bssid; }
void set_frequency(int frequency) { frequency_ = frequency; }
void set_eap_method(EAPMethod eap_method) { eap_method_ = eap_method; }
void set_eap_phase_2_auth(EAPPhase2Auth eap_phase_2_auth) {
eap_phase_2_auth_ = eap_phase_2_auth;
}
void set_eap_server_ca_cert_nss_nickname(
const std::string& eap_server_ca_cert_nss_nickname) {
eap_server_ca_cert_nss_nickname_ = eap_server_ca_cert_nss_nickname;
}
void set_eap_client_cert_pkcs11_id(
const std::string& eap_client_cert_pkcs11_id) {
eap_client_cert_pkcs11_id_ = eap_client_cert_pkcs11_id;
}
void set_eap_use_system_cas(bool eap_use_system_cas) {
eap_use_system_cas_ = eap_use_system_cas;
}
void set_eap_identity(const std::string& eap_identity) {
eap_identity_ = eap_identity;
}
void set_eap_anonymous_identity(const std::string& eap_anonymous_identity) {
eap_anonymous_identity_ = eap_anonymous_identity;
}
void set_eap_passphrase(const std::string& eap_passphrase) {
eap_passphrase_ = eap_passphrase;
}
void set_eap_save_credentials(bool save_credentials) {
eap_save_credentials_ = save_credentials;
}
// Matches the client certificate pattern by checking to see if a certificate
// exists that meets the pattern criteria. If it finds one, it sets the
// appropriate network property. If not, it passes |connect| to the
// EnrollmentDelegate to do something with the enrollment URI (e.g. launch a
// dialog) to install the certificate, and then invoke |connect|. If
// |allow_enroll| is false, then the enrollment handler will not be invoked in
// the case of a missing certificate.
void MatchCertificatePattern(bool allow_enroll, const base::Closure& connect);
// Network overrides.
virtual void EraseCredentials() OVERRIDE;
virtual void CalculateUniqueId() OVERRIDE;
ConnectionSecurity encryption_;
std::string passphrase_;
bool passphrase_required_;
std::string identity_;
bool hidden_ssid_;
std::string bssid_;
int frequency_;
EAPMethod eap_method_;
EAPPhase2Auth eap_phase_2_auth_;
std::string eap_server_ca_cert_nss_nickname_;
std::string eap_client_cert_pkcs11_id_;
bool eap_use_system_cas_;
std::string eap_identity_;
std::string eap_anonymous_identity_;
std::string eap_passphrase_;
bool eap_save_credentials_;
// Internal state (not stored in shill).
// Passphrase set by user (stored for UI).
std::string user_passphrase_;
// Weak pointer factory for wrapping pointers to this network in callbacks.
base::WeakPtrFactory<WifiNetwork> weak_pointer_factory_;
DISALLOW_COPY_AND_ASSIGN(WifiNetwork);
};
typedef std::vector<WifiNetwork*> WifiNetworkVector;
// Class for networks of TYPE_WIMAX.
class WimaxNetwork : public WirelessNetwork {
public:
explicit WimaxNetwork(const std::string& service_path);
virtual ~WimaxNetwork();
bool passphrase_required() const { return passphrase_required_; }
const std::string& eap_identity() const { return eap_identity_; }
const std::string& eap_passphrase() const { return eap_passphrase_; }
void SetEAPIdentity(const std::string& identity);
void SetEAPPassphrase(const std::string& passphrase);
protected:
// This allows NativeWimaxNetworkParser access to device privates so
// that they can be reconstituted during parsing. The parsers only
// access things through the private set_ functions so that this
// class can evolve without having to change all the parsers.
friend class NativeWimaxNetworkParser;
// This allows the implementation classes access to privates.
NETWORK_LIBRARY_IMPL_FRIENDS;
void set_eap_identity(const std::string& identity) {
eap_identity_ = identity;
}
void set_eap_passphrase(const std::string& passphrase) {
eap_passphrase_ = passphrase;
}
void set_passphrase_required(bool passphrase_required) {
passphrase_required_ = passphrase_required;
}
// Network overrides.
virtual void EraseCredentials() OVERRIDE;
virtual void CalculateUniqueId() OVERRIDE;
bool passphrase_required_;
std::string eap_identity_;
std::string eap_passphrase_;
DISALLOW_COPY_AND_ASSIGN(WimaxNetwork);
};
typedef std::vector<WimaxNetwork*> WimaxNetworkVector;
// Geolocation data.
struct CellTower {
CellTower();
enum RadioType {
RADIOTYPE_GSM,
RADIOTYPE_CDMA,
RADIOTYPE_WCDMA,
} radio_type; // GSM/WCDMA CDMA
int mobile_country_code; // MCC MCC
int mobile_network_code; // MNC SID
int location_area_code; // LAC NID
int cell_id; // CID BID
base::Time timestamp; // Timestamp when this cell was primary
int signal_strength; // Radio signal strength measured in dBm.
int timing_advance; // Represents the distance from the cell tower.
// Each unit is roughly 550 meters.
};
typedef std::vector<CellTower> CellTowerVector;
// This class handles the interaction with the ChromeOS network library APIs.
// Classes can add themselves as observers. Users can get an instance of the
// library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary()
class NetworkLibrary {
public:
enum HardwareAddressFormat {
FORMAT_RAW_HEX,
FORMAT_COLON_SEPARATED_HEX
};
// Used to configure which IP parameters will be specified by DHCP and which
// will be set by the user.
enum UseDHCP {
USE_DHCP_ADDRESS = 0x1,
USE_DHCP_NETMASK = 0x1 << 1,
USE_DHCP_GATEWAY = 0x1 << 2,
USE_DHCP_NAME_SERVERS = 0x1 << 3,
USE_DHCP_ALL_ROUTING_INFO =
(USE_DHCP_ADDRESS |
USE_DHCP_NETMASK |
USE_DHCP_GATEWAY),
};
class NetworkProfileObserver {
public:
// Called when the list of network profiles was changed.
virtual void OnProfileListChanged() = 0;
protected:
virtual ~NetworkProfileObserver() {}
};
class NetworkManagerObserver {
public:
// Called when the state of the network manager has changed,
// for example, networks have appeared or disappeared.
virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0;
protected:
virtual ~NetworkManagerObserver() {}
};
class NetworkObserver {
public:
// Called when the state of a single network has changed,
// for example signal strength or connection state.
virtual void OnNetworkChanged(NetworkLibrary* cros,
const Network* network) = 0;
protected:
virtual ~NetworkObserver() {}
};
class NetworkDeviceObserver {
public:
// Called when the state of a single device has changed.
virtual void OnNetworkDeviceChanged(NetworkLibrary* cros,
const NetworkDevice* device) {}
// Called when |device| got notification about new networks available.
virtual void OnNetworkDeviceFoundNetworks(NetworkLibrary* cros,
const NetworkDevice* device) {}
// Called when |device| got notification about SIM lock change.
virtual void OnNetworkDeviceSimLockChanged(NetworkLibrary* cros,
const NetworkDevice* device) {}
protected:
virtual ~NetworkDeviceObserver() {}
};
class PinOperationObserver {
public:
// Called when pin async operation has completed.
// Network is NULL when we don't have an associated Network object.
virtual void OnPinOperationCompleted(NetworkLibrary* cros,
PinOperationError error) = 0;
protected:
virtual ~PinOperationObserver() {}
};
class UserActionObserver {
public:
// Called when user initiates a new connection.
// Network is NULL when we don't have an associated Network object.
virtual void OnConnectionInitiated(NetworkLibrary* cros,
const Network* network) = 0;
protected:
virtual ~UserActionObserver() {}
};
virtual ~NetworkLibrary() {}
virtual void Init() = 0;
// Returns true if libcros was loaded instead of stubbed out.
virtual bool IsCros() const = 0;
virtual void AddNetworkProfileObserver(NetworkProfileObserver* observer) = 0;
virtual void RemoveNetworkProfileObserver(
NetworkProfileObserver* observer) = 0;
virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0;
virtual void RemoveNetworkManagerObserver(
NetworkManagerObserver* observer) = 0;
// An attempt to add an observer that has already been added for a
// give service path will be ignored.
virtual void AddNetworkObserver(const std::string& service_path,
NetworkObserver* observer) = 0;
// Remove an observer of a single network
virtual void RemoveNetworkObserver(const std::string& service_path,
NetworkObserver* observer) = 0;
// Stop |observer| from observing any networks
virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0;
// Add an observer for a single network device.
virtual void AddNetworkDeviceObserver(const std::string& device_path,
NetworkDeviceObserver* observer) = 0;
// Remove an observer for a single network device.
virtual void RemoveNetworkDeviceObserver(const std::string& device_path,
NetworkDeviceObserver* observer) = 0;
// Temporarily locks down certain functionality in network library to prevent
// unplanned side effects. During the lock down, Enable*Device() calls cannot
// be made.
virtual void Lock() = 0;
// Removes temporarily lock of network library.
virtual void Unlock() = 0;
// Checks if access to network library is locked.
virtual bool IsLocked() = 0;
virtual void AddPinOperationObserver(PinOperationObserver* observer) = 0;
virtual void RemovePinOperationObserver(PinOperationObserver* observer) = 0;
virtual void AddUserActionObserver(UserActionObserver* observer) = 0;
virtual void RemoveUserActionObserver(UserActionObserver* observer) = 0;
// Return the active or default Ethernet network (or NULL if none).
virtual const EthernetNetwork* ethernet_network() const = 0;
virtual bool ethernet_connecting() const = 0;
virtual bool ethernet_connected() const = 0;
// Return the active Wifi network (or NULL if none active).
virtual const WifiNetwork* wifi_network() const = 0;
virtual bool wifi_connecting() const = 0;
virtual bool wifi_connected() const = 0;
// Return the active Cellular network (or NULL if none active).
virtual const CellularNetwork* cellular_network() const = 0;
virtual bool cellular_connecting() const = 0;
virtual bool cellular_connected() const = 0;
// Return the active Wimax network (or NULL if none active).
virtual const WimaxNetwork* wimax_network() const = 0;
virtual bool wimax_connecting() const = 0;
virtual bool wimax_connected() const = 0;
// Return the active mobile (cellular or WiMax) network
// (or NULL if none active).
virtual const Network* mobile_network() const = 0;
virtual bool mobile_connecting() const = 0;
virtual bool mobile_connected() const = 0;
// Return the active virtual network (or NULL if none active).
virtual const VirtualNetwork* virtual_network() const = 0;
virtual bool virtual_network_connecting() const = 0;
virtual bool virtual_network_connected() const = 0;
// Return true if any network is currently connected.
virtual bool Connected() const = 0;
// Return true if any network is currently connecting.
virtual bool Connecting() const = 0;
// Returns the current list of wifi networks.
virtual const WifiNetworkVector& wifi_networks() const = 0;
// Returns the list of remembered wifi networks.
virtual const WifiNetworkVector& remembered_wifi_networks() const = 0;
// Returns the current list of cellular networks.
virtual const CellularNetworkVector& cellular_networks() const = 0;
// Returns the current list of Wimax networks.
virtual const WimaxNetworkVector& wimax_networks() const = 0;
// Returns the current list of virtual networks.
virtual const VirtualNetworkVector& virtual_networks() const = 0;
// Returns the current list of virtual networks.
virtual const VirtualNetworkVector& remembered_virtual_networks() const = 0;
virtual const Network* active_network() const = 0;
virtual const Network* active_nonvirtual_network() const = 0;
virtual const Network* connected_network() const = 0;
virtual const Network* connecting_network() const = 0;
virtual bool ethernet_available() const = 0;
virtual bool wifi_available() const = 0;
virtual bool wimax_available() const = 0;
virtual bool cellular_available() const = 0;
virtual bool mobile_available() const = 0;
virtual bool ethernet_enabled() const = 0;
virtual bool wifi_enabled() const = 0;
virtual bool wimax_enabled() const = 0;
virtual bool cellular_enabled() const = 0;
virtual bool mobile_enabled() const = 0;
virtual bool ethernet_busy() const = 0;
virtual bool wifi_busy() const = 0;
virtual bool wimax_busy() const = 0;
virtual bool cellular_busy() const = 0;
virtual bool mobile_busy() const = 0;
virtual bool wifi_scanning() const = 0;
virtual bool cellular_initializing() const = 0;
virtual bool offline_mode() const = 0;
// Returns list of technologies for which captive portal checking is enabled.
// This is a comma-separated string; e.g. "ethernet,wifi,cellular".
// See kDefaultCheckPortalList in portal_detector.cc.
virtual std::string GetCheckPortalList() const = 0;
// Sets comma-separated list of interfaces that have portal check enabled.
// Setting to empty string would disable portal check.
virtual void SetCheckPortalList(const std::string& check_portal_list) = 0;
// Enables portal checking on a default set of interfaces:
// "ethernet,wifi,cellular".
virtual void SetDefaultCheckPortalList() = 0;
// Returns the current IP address if connected. If not, returns empty string.
virtual const std::string& IPAddress() const = 0;
// Return a pointer to the device, if it exists, or NULL.
virtual const NetworkDevice* FindNetworkDeviceByPath(
const std::string& path) const = 0;
// Returns device with TYPE_CELLULAR or TYPE_WIMAX.
// Returns NULL if none exists.
virtual const NetworkDevice* FindMobileDevice() const = 0;
// Returns device with TYPE_WIMAX. Returns NULL if none exists.
virtual const NetworkDevice* FindWimaxDevice() const = 0;
// Returns device with TYPE_CELLULAR. Returns NULL if none exists.
virtual const NetworkDevice* FindCellularDevice() const = 0;
// Returns device with TYPE_ETHERNET. Returns NULL if none exists.
virtual const NetworkDevice* FindEthernetDevice() const = 0;
// Returns device with TYPE_WIFI. Returns NULL if none exists.
virtual const NetworkDevice* FindWifiDevice() const = 0;
// Return a pointer to the network, if it exists, or NULL.
// NOTE: Never store these results, store service paths instead.
// The pattern for doing an operation on a Network is:
// Network* network = cros->FindNetworkByPath(service_path);
// network->SetFoo();
// network->Connect();
// As long as this is done in sequence on the UI thread it will be safe;
// the network list only gets updated on the UI thread.
virtual Network* FindNetworkByPath(const std::string& path) const = 0;
virtual Network* FindNetworkByUniqueId(
const std::string& unique_id) const = 0;
virtual WifiNetwork* FindWifiNetworkByPath(const std::string& path) const = 0;
virtual CellularNetwork* FindCellularNetworkByPath(
const std::string& path) const = 0;
virtual WimaxNetwork* FindWimaxNetworkByPath(
const std::string& path) const = 0;
virtual VirtualNetwork* FindVirtualNetworkByPath(
const std::string& path) const = 0;
// Return a pointer to the remembered network, if it exists, or NULL.
virtual Network* FindRememberedNetworkByPath(
const std::string& path) const = 0;
// Return a pointer to the ONC dictionary for a network identified by unique
// ID. Returns NULL if there is no ONC dictionary available for that network.
// The ONC dictionary is usually only present for policy-configure networks
// which get reconfigured at startup.
virtual const base::DictionaryValue* FindOncForNetwork(
const std::string& unique_id) const = 0;
// Records information that cellular plan payment has happened.
virtual void SignalCellularPlanPayment() = 0;
// Returns true if cellular plan payment has been recorded recently.
virtual bool HasRecentCellularPlanPayment() = 0;
// Returns home carrier ID if available, otherwise empty string is returned.
// Carrier ID format: <carrier name> (country). Ex.: "Verizon (us)".
virtual const std::string& GetCellularHomeCarrierId() const = 0;
// Passes |old_pin|, |new_pin| to change SIM card PIM.
virtual void ChangePin(const std::string& old_pin,
const std::string& new_pin) = 0;
// Passes |pin|, |require_pin| value to change SIM card RequirePin setting.
virtual void ChangeRequirePin(bool require_pin,
const std::string& pin) = 0;
// Passes |pin| to unlock SIM card.
virtual void EnterPin(const std::string& pin) = 0;
// Passes |puk|, |new_pin| to unblock SIM card.
virtual void UnblockPin(const std::string& puk,
const std::string& new_pin) = 0;
// Request a scan for available cellular networks.
virtual void RequestCellularScan() = 0;
// Request a register in cellular network with |network_id|.
virtual void RequestCellularRegister(const std::string& network_id) = 0;
// Change data roaming restriction for current cellular device.
virtual void SetCellularDataRoamingAllowed(bool new_value) = 0;
// Changes the active cellular carrier to the one provided, calls the closure
// once the transition is complete.
virtual void SetCarrier(const std::string& carrier,
const NetworkOperationCallback& completed) = 0;
// Resets the cellular device, calls the closure once the transition is
// complete.
virtual void ResetModem() = 0;
// Return true if GSM SIM card can work only with enabled roaming.
virtual bool IsCellularAlwaysInRoaming() = 0;
// Request a scan for new wifi networks.
virtual void RequestNetworkScan() = 0;
// TODO(joth): Add GetCellTowers to retrieve a CellTowerVector.
// Return true if a profile matching |type| is loaded.
virtual bool HasProfileType(NetworkProfileType type) const = 0;
// Returns false if there is no way to connect to this network, even with
// user input (e.g. it requires a user profile but none is available).
virtual bool CanConnectToNetwork(const Network* network) const = 0;
// Refresh the IP configuration of the given network after changes. Puts
// newly configured properties into effect and renews DHCP lease.
virtual void RefreshIPConfig(Network* network) = 0;
// Connect to the specified wireless network.
virtual void ConnectToWifiNetwork(WifiNetwork* network) = 0;
// Connect to the specified wireless network and set its profile
// to SHARED if |shared| is true, otherwise to USER.
virtual void ConnectToWifiNetwork(WifiNetwork* network, bool shared) = 0;
// Connect to the specified cellular network.
virtual void ConnectToCellularNetwork(CellularNetwork* network) = 0;
// Connect to the specified WiMAX network.
virtual void ConnectToWimaxNetwork(WimaxNetwork* network) = 0;
// Connect to the specified WiMAX network and set its profile
// to SHARED if |shared| is true, otherwise to USER.
virtual void ConnectToWimaxNetwork(WimaxNetwork* network, bool shared) = 0;
// Connect to the specified virtual network.
virtual void ConnectToVirtualNetwork(VirtualNetwork* network) = 0;
// Connect to an unconfigured network with given SSID, security, passphrase,
// and optional EAP configuration. If |security| is SECURITY_8021X,
// |eap_config| must be provided.
struct EAPConfigData {
EAPConfigData();
~EAPConfigData();
EAPMethod method;
EAPPhase2Auth auth;
std::string server_ca_cert_nss_nickname;
bool use_system_cas;
std::string client_cert_pkcs11_id;
std::string identity;
std::string anonymous_identity;
};
virtual void ConnectToUnconfiguredWifiNetwork(
const std::string& ssid,
ConnectionSecurity security,
const std::string& passphrase,
const EAPConfigData* eap_config,
bool save_credentials,
bool shared) = 0;
// Connect to the specified virtual network with service name.
// VPNConfigData must be provided.
struct VPNConfigData {
VPNConfigData();
~VPNConfigData();
std::string psk;
std::string server_ca_cert_nss_nickname;
std::string client_cert_pkcs11_id;
std::string username;
std::string user_passphrase;
std::string otp;
std::string group_name;
bool save_credentials;
};
virtual void ConnectToUnconfiguredVirtualNetwork(
const std::string& service_name,
const std::string& server_hostname,
ProviderType provider_type,
const VPNConfigData& config) = 0;
// Disconnect from the specified network.
virtual void DisconnectFromNetwork(const Network* network) = 0;
// Forget the network corresponding to service_path.
virtual void ForgetNetwork(const std::string& service_path) = 0;
// Enables/disables the ethernet network device.
virtual void EnableEthernetNetworkDevice(bool enable) = 0;
// Enables/disables the wifi network device.
virtual void EnableWifiNetworkDevice(bool enable) = 0;
// Enables/disables mobile (cellular, wimax) network device.
virtual void EnableMobileNetworkDevice(bool enable) = 0;
// Enables/disables the wimax network device.
virtual void EnableWimaxNetworkDevice(bool enable) = 0;
// Enables/disables the cellular network device.
virtual void EnableCellularNetworkDevice(bool enable) = 0;
// Enables/disables offline mode.
virtual void EnableOfflineMode(bool enable) = 0;
// Fetches IP configs and hardware address for a given device_path and returns
// them via the given callback.
virtual void GetIPConfigs(const std::string& device_path,
HardwareAddressFormat format,
const NetworkGetIPConfigsCallback& callback) = 0;
// DEPRECATED: DO NOT USE. Instead, use the asynchronous GetIPConfigs above.
// Fetches IP configs and hardware address for a given device_path. The
// hardware address is usually a MAC address like "0011AA22BB33".
// |hardware_address| will be an empty string, if no hardware address is
// found.
virtual NetworkIPConfigVector GetIPConfigsAndBlock(
const std::string& device_path,
std::string* hardware_address,
HardwareAddressFormat) = 0;
// Sets the configuration of the IP parameters. This is called when user
// changes IP settings from dhcp to static or vice versa or when user changes
// the ip config info. If nothing is changed, this method does nothing.
// |dhcp_usage_mask| is a bitmask composed of items from the UseDHCP enum, and
// indicates which of the supplied values are overridden by values given by
// the default IP acquisition technique for the service (DHCP, usually).
virtual void SetIPParameters(const std::string& service_path,
const std::string& address,
const std::string& netmask,
const std::string& gateway,
const std::string& name_servers,
int dhcp_usage_mask) = 0;
// Requests the service properties associated with |service_path|. Calls
// |callback| with the properties when competed.
typedef base::Callback<void(const std::string& service_path,
const base::DictionaryValue* properties)>
NetworkServicePropertiesCallback;
virtual void RequestNetworkServiceProperties(
const std::string& service_path,
const NetworkServicePropertiesCallback& callback) = 0;
// This will connect to a preferred network if the currently connected
// network is not preferred. This should be called when the active profile
// changes.
virtual void SwitchToPreferredNetwork() = 0;
// Load networks from an Open Network Configuration blob.
// If there was an error, returns false.
virtual bool LoadOncNetworks(const std::string& onc_blob,
const std::string& passcode,
onc::ONCSource source,
bool allow_web_trust_from_policy) = 0;
// This sets the active network for the network type. Note: priority order
// is unchanged (i.e. if a wifi network is set to active, but an ethernet
// network is still active, active_network() will still return the ethernet
// network). Other networks of the same type will become inactive.
// Used for testing.
virtual bool SetActiveNetwork(ConnectionType type,
const std::string& service_path) = 0;
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get().
static NetworkLibrary* GetImpl(bool stub);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
|