4 /* 4.3.1.1 List of states for PLMN slection process (automatic mode) */
5 #define GSM322_A0_NULL 0
6 #define GSM322_A1_TRYING_RPLMN 1
7 #define GSM322_A2_ON_PLMN 2
8 #define GSM322_A3_TRYING_PLMN 3
9 #define GSM322_A4_WAIT_FOR_PLMN 4
10 #define GSM322_A5_HPLMN_SEARCH 5
11 #define GSM322_A6_NO_SIM 6
13 /* 4.3.1.2 List of states for PLMN slection process (manual mode) */
14 #define GSM322_M0_NULL 0
15 #define GSM322_M1_TRYING_RPLMN 1
16 #define GSM322_M2_ON_PLMN 2
17 #define GSM322_M3_NOT_ON_PLMN 3
18 #define GSM322_M4_TRYING_PLMN 4
19 #define GSM322_M5_NO_SIM 5
21 /* 4.3.2 List of states for cell selection process */
22 #define GSM322_C0_NULL 0
23 #define GSM322_C1_NORMAL_CELL_SEL 1
24 #define GSM322_C2_STORED_CELL_SEL 2
25 #define GSM322_C3_CAMPED_NORMALLY 3
26 #define GSM322_C4_NORMAL_CELL_RESEL 4
27 #define GSM322_C5_CHOOSE_CELL 5
28 #define GSM322_C6_ANY_CELL_SEL 6
29 #define GSM322_C7_CAMPED_ANY_CELL 7
30 #define GSM322_C8_ANY_CELL_RESEL 8
31 #define GSM322_C9_CHOOSE_ANY_CELL 9
32 #define GSM322_PLMN_SEARCH 10
33 #define GSM322_HPLMN_SEARCH 11
35 /* GSM 03.22 events */
36 #define GSM322_EVENT_SWITCH_ON 1
37 #define GSM322_EVENT_SWITCH_OFF 2
38 #define GSM322_EVENT_SIM_INSERT 3
39 #define GSM322_EVENT_SIM_REMOVE 4
40 #define GSM322_EVENT_REG_SUCCESS 5
41 #define GSM322_EVENT_REG_FAILED 6
42 #define GSM322_EVENT_ROAMING_NA 7
43 #define GSM322_EVENT_INVALID_SIM 8
44 #define GSM322_EVENT_NEW_PLMN 9
45 #define GSM322_EVENT_ON_PLMN 10
46 #define GSM322_EVENT_PLMN_SEARCH_START 11
47 #define GSM322_EVENT_PLMN_SEARCH_END 12
48 #define GSM322_EVENT_USER_RESEL 13
49 #define GSM322_EVENT_PLMN_AVAIL 14
50 #define GSM322_EVENT_CHOOSE_PLMN 15
51 #define GSM322_EVENT_SEL_MANUAL 16
52 #define GSM322_EVENT_SEL_AUTO 17
53 #define GSM322_EVENT_CELL_FOUND 18
54 #define GSM322_EVENT_NO_CELL_FOUND 19
55 #define GSM322_EVENT_LEAVE_IDLE 20
56 #define GSM322_EVENT_RET_IDLE 21
57 #define GSM322_EVENT_CELL_RESEL 22
58 #define GSM322_EVENT_SYSINFO 23
59 #define GSM322_EVENT_HPLMN_SEARCH 24
66 /* node for each PLMN */
67 struct gsm322_plmn_list {
68 struct llist_head entry;
70 int8_t rxlev; /* rx level in range format */
71 uint8_t cause; /* cause value, if PLMN is not allowed */
74 /* node for each forbidden LA */
75 struct gsm322_la_list {
76 struct llist_head entry;
77 uint16_t mcc, mnc, lac;
81 /* node for each BA-List */
82 struct gsm322_ba_list {
83 struct llist_head entry;
85 /* Band allocation for 1024 frequencies.
86 * First bit of first index is frequency 0.
91 #define GSM322_CS_FLAG_SUPPORT 0x01 /* frequency is supported by radio */
92 #define GSM322_CS_FLAG_BA 0x02 /* frequency is part of the current ba */
93 #define GSM322_CS_FLAG_POWER 0x04 /* frequency was power scanned */
94 #define GSM322_CS_FLAG_SIGNAL 0x08 /* valid signal detected */
95 #define GSM322_CS_FLAG_SYSINFO 0x10 /* complete sysinfo received */
96 #define GSM322_CS_FLAG_BARRED 0x20 /* cell is barred */
97 #define GSM322_CS_FLAG_FORBIDD 0x40 /* cell in list of forbidden LAs */
98 #define GSM322_CS_FLAG_TEMP_AA 0x80 /* if temporary available and allowable */
100 /* Cell selection list */
101 struct gsm322_cs_list {
102 uint8_t flags; /* see GSM322_CS_FLAG_* */
103 int8_t rxlev; /* rx level range format */
104 struct gsm48_sysinfo *sysinfo;
106 int8_t min_dbm; /* minimum level to enter cell */
107 int8_t max_pwr; /* maximum power to access cell */
108 uint16_t class_barr; /* barred classes */
109 uint16_t mcc, mnc, lac; /* received mcc, mnc, lac */
113 /* PLMN search process */
115 struct osmocom_ms *ms;
116 int state; /* GSM322_Ax_* or GSM322_Mx_* */
118 struct llist_head event_queue; /* event messages */
119 struct llist_head sorted_plmn; /* list of sorted PLMN */
120 struct llist_head forbidden_la; /* forbidden LAs */
122 struct timer_list timer;
124 int plmn_curr; /* current index in sorted_plmn */
125 uint16_t mcc, mnc; /* current network selected */
128 /* state of CCCH activation */
129 #define GSM322_CCCH_ST_IDLE 0 /* no connection */
130 #define GSM322_CCCH_ST_INIT 1 /* initalized */
131 #define GSM322_CCCH_ST_SYNC 2 /* got sync */
132 #define GSM322_CCCH_ST_DATA 3 /* receiveing data */
134 struct gsm48_sysinfo;
135 /* Cell selection process */
136 struct gsm322_cellsel {
137 struct osmocom_ms *ms;
138 int state; /* GSM322_Cx_* */
140 struct llist_head event_queue; /* event messages */
141 struct llist_head ba_list; /* BCCH Allocation per PLMN */
143 struct timer_list timer;
145 uint16_t mcc, mnc; /* current network to search for */
146 struct gsm322_cs_list list[1024]; /* cell selection list per freq. */
148 uint8_t powerscan; /* currently scanning for power */
149 uint32_t scan_state; /* special state of current scan */
150 uint8_t ccch_state; /* special state of current ccch */
151 uint16_t arfcn; /* current tuned idle mode arfcn */
152 uint8_t ccch_mode; /* curren CCCH_MODE_* */
153 struct gsm48_sysinfo *si; /* current sysinfo */
155 uint8_t selected; /* if a cell is selected */
157 struct gsm48_sysinfo sel_si; /* copy of selected cell, will update */
158 uint16_t sel_mcc, sel_mnc, sel_lac, sel_id;
161 /* GSM 03.22 message */
165 uint8_t sysinfo; /* system information type */
166 uint8_t same_cell; /* select same cell when RET_IDLE */
167 uint8_t reject; /* location update reject cause */
170 #define GSM322_ALLOC_SIZE sizeof(struct gsm322_msg)
171 #define GSM322_ALLOC_HEADROOM 0
173 int gsm322_init(struct osmocom_ms *ms);
174 int gsm322_exit(struct osmocom_ms *ms);
175 struct msgb *gsm322_msgb_alloc(int msg_type);
176 int gsm322_plmn_sendmsg(struct osmocom_ms *ms, struct msgb *msg);
177 int gsm322_cs_sendmsg(struct osmocom_ms *ms, struct msgb *msg);
178 int gsm322_c_event(struct osmocom_ms *ms, struct msgb *msg);
179 int gsm322_plmn_dequeue(struct osmocom_ms *ms);
180 int gsm322_cs_dequeue(struct osmocom_ms *ms);
181 int gsm322_add_forbidden_la(struct osmocom_ms *ms, uint16_t mcc,
182 uint16_t mnc, uint16_t lac, uint8_t cause);
183 int gsm322_del_forbidden_la(struct osmocom_ms *ms, uint16_t mcc,
184 uint16_t mnc, uint16_t lac);
185 int gsm322_is_forbidden_la(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc,
187 int gsm322_dump_sorted_plmn(struct osmocom_ms *ms);
188 int gsm322_dump_cs_list(struct gsm322_cellsel *cs, uint8_t flags,
189 void (*print)(void *, const char *, ...), void *priv);
190 int gsm322_dump_forbidden_la(struct osmocom_ms *ms,
191 void (*print)(void *, const char *, ...), void *priv);
192 int gsm322_dump_ba_list(struct gsm322_cellsel *cs, uint16_t mcc, uint16_t mnc,
193 void (*print)(void *, const char *, ...), void *priv);
194 void start_cs_timer(struct gsm322_cellsel *cs, int sec, int micro);
195 void start_loss_timer(struct gsm322_cellsel *cs, int sec, int micro);
196 extern const char *plmn_a_state_names[];
197 extern const char *plmn_m_state_names[];
198 extern const char *cs_state_names[];
200 char *gsm_print_rxlev(uint8_t rxlev);
202 #endif /* _GSM322_H */