wireless/lib.rs
1#[macro_use]
2extern crate serde_derive;
3
4use std::collections::BTreeMap;
5
6pub type Countries = BTreeMap<MCC, Country>;
7#[allow(non_camel_case_types)]
8pub type eNBId = u32;
9pub type LTECellGlobalId = u64;
10pub type LTECellId = u32;
11pub type LTECells = BTreeMap<LTECellGlobalId, LTECell>;
12pub type LTECellShortId = u8;
13pub type MCC = u16;
14pub type MNC = u16;
15pub type NetworkId = u32;
16pub type Networks = BTreeMap<NetworkId, Network>;
17
18/// Represents a country.
19#[derive(Serialize, Deserialize)]
20pub struct Country {
21 /// The three-digit Mobile Country Code (MCC) representing the country. E.g. `530` for New
22 /// Zealand. Note that it is possible for a country to have more than one MCC representing it.
23 /// See the Wikipedia article about [Mobile Country Codes][1] for more information and a list of
24 /// valid codes.
25 /// [1]: https://en.wikipedia.org/wiki/Mobile_country_code
26 pub mcc: MCC,
27 /// The name of the country. E.g. `New Zealand`.
28 pub name: String,
29}
30
31/// Represents a LTE cell.
32#[derive(Serialize, Deserialize)]
33pub struct LTECell {
34 pub id: LTECellId,
35 pub mcc: MCC,
36 pub mnc: MNC,
37}
38
39/// Represents a network.
40#[derive(Serialize, Deserialize)]
41pub struct Network {
42 /// The three-digit Mobile Country Code (MCC) representing the country this network is located
43 /// in. See [wireless::Country.mcc](struct.Country.html#structfield.mcc) for more information.
44 pub mcc: MCC,
45 /// The three-digit Mobile Network Code (MNC) representing this network within its parent Mobile
46 /// Country Code (MCC). E.g. `240` for 2degrees within the MCC `530` for New Zealand (usually
47 /// formatted as `530-24` with a two-digit MNC omitting the third digit). See the Wikipedia
48 /// article about [Mobile Country Codes][1] for more information and a list of valid codes.
49 /// [1]: https://en.wikipedia.org/wiki/Mobile_country_code
50 pub mnc: MNC,
51 /// The name of the network. E.g. `2degrees`.
52 pub name: String,
53}
54
55impl LTECell {
56 pub fn short_cid(&self) -> LTECellShortId { (self.id & (2 ^ 8 - 1)) as LTECellShortId }
57 pub fn global_id(&self) -> LTECellGlobalId {
58 Network::generate_id(self.mcc, self.mnc) as LTECellGlobalId + self.id as LTECellGlobalId
59 }
60 pub fn enb_id(&self) -> eNBId { self.id >> 8 }
61}
62
63impl Network {
64 /// Derive a 24-bit global identifier from the given Mobile Country Code (MCC) and Mobile
65 /// Network Code (MNC). The MCC makes up the first 12 bits and the MNC makes up the last 12
66 /// bits. The identifier is useful as a key value in a key-value collection.
67 pub fn generate_id(mcc: MCC, mnc: MNC) -> NetworkId {
68 ((mcc as NetworkId) << 12) + (mnc as NetworkId)
69 }
70 /// Derive a global identifier for this network. See [generate_id()](#method.generate_id) for
71 /// more information.
72 pub fn id(&self) -> NetworkId { Network::generate_id(self.mcc, self.mnc) }
73}