[layer23] Updated layer23 to current L1 support and forthcomming hopping.
[osmocom-bb.git] / src / host / layer23 / include / osmocom / gsm322.h
1 #ifndef _GSM322_H
2 #define _GSM322_H
3
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
12
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
20
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
34
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_CHOSE_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
60
61 enum {
62         PLMN_MODE_MANUAL,
63         PLMN_MODE_AUTO
64 };
65
66 /* node for each PLMN */
67 struct gsm322_plmn_list {
68         struct llist_head       entry;
69         uint16_t                mcc, mnc;
70         int8_t                  rxlev_db; /* rx level in real dB */
71         uint8_t                 cause; /* cause value, if PLMN is not allowed */
72 };
73
74 /* node for each forbidden LA */
75 struct gsm322_la_list {
76         struct llist_head       entry;
77         uint16_t                mcc, mnc, lac;
78         uint8_t                 cause;
79 };
80
81 /* node for each BA-List */
82 struct gsm322_ba_list {
83         struct llist_head       entry;
84         uint16_t                mcc, mnc;
85         /* Band allocation for 1024 frequencies.
86          * First bit of first index is frequency 0.
87          */
88         uint8_t                 freq[128];
89 };
90
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 */
99
100 /* Cell selection list */
101 struct gsm322_cs_list {
102         uint8_t                 flags; /* see GSM322_CS_FLAG_* */
103         int8_t                  rxlev_db; /* rx level in real dB */
104         struct gsm48_sysinfo    *sysinfo;
105 #if 0
106         int8_t                  min_db; /* 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 */
110 #endif
111 };
112
113 /* PLMN search process */
114 struct gsm322_plmn {
115         struct osmocom_ms       *ms;
116         int                     state; /* GSM322_Ax_* or GSM322_Mx_* */
117
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 */
121
122         struct timer_list       timer;
123
124         int                     plmn_curr; /* current index in sorted_plmn */
125         uint16_t                mcc, mnc; /* current network selected */
126 };
127
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 */
133
134 struct gsm48_sysinfo;
135 /* Cell selection process */
136 struct gsm322_cellsel {
137         struct osmocom_ms       *ms;
138         int                     state; /* GSM322_Cx_* */
139
140         struct llist_head       event_queue; /* event messages */
141         struct llist_head       ba_list; /* BCCH Allocation per PLMN */
142
143         struct timer_list       timer;
144
145         uint16_t                mcc, mnc; /* current network to search for */
146         struct gsm322_cs_list   list[1024]; /* cell selection list per freq. */
147
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 */
154
155         uint8_t                 selected; /* if a cell is selected */
156         uint16_t                sel_arfcn;
157         struct gsm48_sysinfo    sel_si; /* copy of selected cell, will update */
158         uint16_t                sel_mcc, sel_mnc, sel_lac, sel_id;
159 };
160
161 /* GSM 03.22 message */
162 struct gsm322_msg {
163         int                     msg_type;
164         uint16_t                mcc, mnc;
165         uint8_t                 sysinfo; /* system information type */
166         uint8_t                 reject; /* location update reject cause */
167 };
168
169 #define GSM322_ALLOC_SIZE       sizeof(struct gsm322_msg)
170 #define GSM322_ALLOC_HEADROOM   0
171
172 int gsm322_init(struct osmocom_ms *ms);
173 int gsm322_exit(struct osmocom_ms *ms);
174 struct msgb *gsm322_msgb_alloc(int msg_type);
175 int gsm322_plmn_sendmsg(struct osmocom_ms *ms, struct msgb *msg);
176 int gsm322_cs_sendmsg(struct osmocom_ms *ms, struct msgb *msg);
177 int gsm322_c_event(struct osmocom_ms *ms, struct msgb *msg);
178 int gsm322_plmn_dequeue(struct osmocom_ms *ms);
179 int gsm322_cs_dequeue(struct osmocom_ms *ms);
180 int gsm322_add_forbidden_la(struct osmocom_ms *ms, uint16_t mcc,
181         uint16_t mnc, uint16_t lac, uint8_t cause);
182 int gsm322_del_forbidden_la(struct osmocom_ms *ms, uint16_t mcc,
183         uint16_t mnc, uint16_t lac);
184 int gsm322_is_forbidden_la(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc,
185         uint16_t lac);
186 int gsm322_dump_sorted_plmn(struct osmocom_ms *ms);
187 int gsm322_dump_cs_list(struct gsm322_cellsel *cs, uint8_t flags,
188                         void (*print)(void *, const char *, ...), void *priv);
189 int gsm322_dump_forbidden_la(struct osmocom_ms *ms,
190                         void (*print)(void *, const char *, ...), void *priv);
191 int gsm322_dump_ba_list(struct gsm322_cellsel *cs, uint16_t mcc, uint16_t mnc,
192                         void (*print)(void *, const char *, ...), void *priv);
193 void start_cs_timer(struct gsm322_cellsel *cs, int sec, int micro);
194 void start_loss_timer(struct gsm322_cellsel *cs, int sec, int micro);
195 extern const char *plmn_a_state_names[];
196 extern const char *plmn_m_state_names[];
197 extern const char *cs_state_names[];
198
199 #endif /* _GSM322_H */