Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | #ifndef _GSM_DATA_H |
| 2 | #define _GSM_DATA_H |
| 3 | |
| 4 | #include <sys/types.h> |
| 5 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 6 | #include <openbsc/timer.h> |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 7 | #include <openbsc/gsm_04_08.h> |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 8 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 9 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 10 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 11 | #define GSM_MAX_BTS 8 |
| 12 | #define BTS_MAX_TRX 8 |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 13 | #define TRX_NR_TS 8 |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 14 | #define TS_MAX_LCHAN 8 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 15 | |
| 16 | #define HARDCODED_ARFCN 123 |
| 17 | |
Harald Welte | 8e1e3ee | 2009-02-01 13:32:45 +0000 | [diff] [blame] | 18 | enum gsm_hooks { |
| 19 | GSM_HOOK_NM_SWLOAD, |
| 20 | }; |
| 21 | |
| 22 | struct msgb; |
| 23 | typedef int gsm_cbfn(unsigned int hooknum, |
| 24 | unsigned int event, |
| 25 | struct msgb *msg, |
| 26 | void *data, void *param); |
| 27 | |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Use the channel. As side effect the lchannel recycle timer |
| 30 | * will be started. |
| 31 | */ |
| 32 | #define LCHAN_RELEASE_TIMEOUT 4, 0 |
| 33 | #define use_lchan(lchan) \ |
| 34 | do { lchan->use_count++; \ |
| 35 | schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0); |
| 36 | |
| 37 | #define put_lchan(lchan) \ |
| 38 | do { lchan->use_count--; } while(0); |
| 39 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 40 | /* communications link with a BTS */ |
| 41 | struct gsm_bts_link { |
| 42 | struct gsm_bts *bts; |
| 43 | }; |
| 44 | |
Harald Welte | a3d0438 | 2008-12-27 17:02:56 +0000 | [diff] [blame] | 45 | enum gsm_call_type { |
| 46 | GSM_CT_NONE, |
| 47 | GSM_CT_MO, |
| 48 | GSM_CT_MT, |
| 49 | }; |
| 50 | |
| 51 | enum gsm_call_state { |
| 52 | GSM_CSTATE_NULL, |
| 53 | GSM_CSTATE_INITIATED, |
| 54 | GSM_CSTATE_ACTIVE, |
| 55 | GSM_CSTATE_RELEASE_REQ, |
| 56 | }; |
| 57 | |
| 58 | /* One end of a call */ |
| 59 | struct gsm_call { |
| 60 | enum gsm_call_type type; |
| 61 | enum gsm_call_state state; |
| 62 | u_int8_t transaction_id; /* 10.3.2 */ |
| 63 | |
| 64 | /* the 'local' subscriber */ |
| 65 | struct gsm_subscriber *subscr; |
| 66 | }; |
| 67 | |
| 68 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 69 | enum gsm_phys_chan_config { |
| 70 | GSM_PCHAN_NONE, |
| 71 | GSM_PCHAN_CCCH, |
| 72 | GSM_PCHAN_CCCH_SDCCH4, |
| 73 | GSM_PCHAN_TCH_F, |
| 74 | GSM_PCHAN_TCH_H, |
| 75 | GSM_PCHAN_SDCCH8_SACCH8C, |
| 76 | GSM_PCHAN_UNKNOWN, |
| 77 | }; |
| 78 | |
| 79 | enum gsm_chan_t { |
| 80 | GSM_LCHAN_NONE, |
| 81 | GSM_LCHAN_SDCCH, |
| 82 | GSM_LCHAN_TCH_F, |
| 83 | GSM_LCHAN_TCH_H, |
| 84 | GSM_LCHAN_UNKNOWN, |
| 85 | }; |
| 86 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 87 | |
| 88 | /* Channel Request reason */ |
| 89 | enum gsm_chreq_reason_t { |
| 90 | GSM_CHREQ_REASON_EMERG, |
| 91 | GSM_CHREQ_REASON_PAG, |
| 92 | GSM_CHREQ_REASON_CALL, |
| 93 | GSM_CHREQ_REASON_LOCATION_UPD, |
| 94 | GSM_CHREQ_REASON_OTHER, |
| 95 | }; |
| 96 | |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 97 | /* Network Management State */ |
| 98 | struct gsm_nm_state { |
| 99 | u_int8_t operational; |
| 100 | u_int8_t administrative; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 101 | u_int8_t availability; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 102 | }; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 103 | struct gsm_attr { |
| 104 | u_int8_t len; |
| 105 | u_int8_t data[0]; |
| 106 | }; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 107 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 108 | /* |
| 109 | * LOCATION UPDATING REQUEST state |
| 110 | * |
| 111 | * Our current operation is: |
| 112 | * - Get imei/tmsi |
| 113 | * - Accept/Reject according to global policy |
| 114 | */ |
| 115 | struct gsm_loc_updating_operation { |
| 116 | struct timer_list updating_timer; |
| 117 | int waiting_for_imsi : 1; |
| 118 | int waiting_for_imei : 1; |
| 119 | }; |
| 120 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 121 | struct gsm_lchan { |
| 122 | /* The TS that we're part of */ |
| 123 | struct gsm_bts_trx_ts *ts; |
| 124 | /* The logical subslot number in the TS */ |
| 125 | u_int8_t nr; |
| 126 | /* The lotical channel type */ |
| 127 | enum gsm_chan_t type; |
Harald Welte | d4c9bf3 | 2009-02-15 16:56:18 +0000 | [diff] [blame] | 128 | /* Power levels for MS and BTS */ |
| 129 | u_int8_t bs_power; |
| 130 | u_int8_t ms_power; |
| 131 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 132 | /* To whom we are allocated at the moment */ |
| 133 | struct gsm_subscriber *subscr; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 134 | |
| 135 | /* Timer started to release the channel */ |
| 136 | struct timer_list release_timer; |
Harald Welte | a3d0438 | 2008-12-27 17:02:56 +0000 | [diff] [blame] | 137 | |
| 138 | /* local end of a call, if any */ |
| 139 | struct gsm_call call; |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 140 | |
| 141 | /* temporary user data, to be removed... and merged into gsm_call */ |
| 142 | void *user_data; |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 143 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 144 | /* |
| 145 | * Operations that have a state and might be pending |
| 146 | */ |
| 147 | struct gsm_loc_updating_operation *loc_operation; |
| 148 | |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 149 | /* use count. how many users use this channel */ |
| 150 | unsigned int use_count; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 153 | struct gsm_e1_subslot { |
| 154 | /* Number of E1 link */ |
| 155 | u_int8_t e1_nr; |
| 156 | /* Number of E1 TS inside E1 link */ |
| 157 | u_int8_t e1_ts; |
| 158 | /* Sub-slot within the E1 TS, 0xff if full TS */ |
| 159 | u_int8_t e1_ts_ss; |
| 160 | }; |
| 161 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 162 | #define BTS_TRX_F_ACTIVATED 0x0001 |
| 163 | /* One Timeslot in a TRX */ |
| 164 | struct gsm_bts_trx_ts { |
| 165 | struct gsm_bts_trx *trx; |
| 166 | /* number of this timeslot at the TRX */ |
| 167 | u_int8_t nr; |
| 168 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 169 | enum gsm_phys_chan_config pchan; |
| 170 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 171 | unsigned int flags; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 172 | struct gsm_nm_state nm_state; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 173 | struct gsm_attr *nm_attr; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 174 | |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 175 | /* To which E1 subslot are we connected */ |
| 176 | struct gsm_e1_subslot e1_link; |
| 177 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 178 | struct gsm_lchan lchan[TS_MAX_LCHAN]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | /* One TRX in a BTS */ |
| 182 | struct gsm_bts_trx { |
| 183 | struct gsm_bts *bts; |
| 184 | /* number of this TRX in the BTS */ |
| 185 | u_int8_t nr; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 186 | /* how do we talk RSL with this TRX? */ |
| 187 | struct e1inp_sign_link *rsl_link; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 188 | struct gsm_nm_state nm_state; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 189 | struct gsm_attr *nm_attr; |
| 190 | struct { |
| 191 | struct gsm_nm_state nm_state; |
| 192 | } bb_transc; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 193 | |
| 194 | u_int16_t arfcn; |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 195 | struct gsm_bts_trx_ts ts[TRX_NR_TS]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 198 | enum gsm_bts_type { |
| 199 | GSM_BTS_TYPE_UNKNOWN, |
| 200 | GSM_BTS_TYPE_BS11, |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 201 | GSM_BTS_TYPE_NANOBTS_900, |
| 202 | GSM_BTS_TYPE_NANOBTS_1800, |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 205 | /** |
| 206 | * A pending paging request |
| 207 | */ |
| 208 | struct gsm_paging_request { |
| 209 | struct llist_head entry; |
| 210 | struct gsm_subscriber *subscr; |
| 211 | struct gsm_bts *bts; |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 212 | int chan_type; |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 213 | |
| 214 | /* Timer 3113: how long do we try to page? */ |
| 215 | struct timer_list T3113; |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 216 | }; |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 217 | #define T3113_VALUE 60, 0 |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 218 | |
| 219 | /* |
| 220 | * This keeps track of the paging status of one BTS. It |
| 221 | * includes a number of pending requests, a back pointer |
| 222 | * to the gsm_bts, a timer and some more state. |
| 223 | */ |
| 224 | struct gsm_bts_paging_state { |
| 225 | /* public callbacks */ |
| 226 | void (*channel_allocated)(struct gsm_lchan *lchan); |
| 227 | |
| 228 | /* pending requests */ |
| 229 | struct llist_head pending_requests; |
| 230 | struct gsm_paging_request *last_request; |
| 231 | struct gsm_bts *bts; |
| 232 | |
Holger Freyther | 392209c | 2009-02-10 00:06:19 +0000 | [diff] [blame] | 233 | /* load */ |
| 234 | u_int16_t available_slots; |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 237 | /* One BTS */ |
| 238 | struct gsm_bts { |
| 239 | struct gsm_network *network; |
| 240 | /* number of ths BTS in network */ |
| 241 | u_int8_t nr; |
| 242 | /* location area code of this BTS */ |
| 243 | u_int8_t location_area_code; |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 244 | /* type of BTS */ |
| 245 | enum gsm_bts_type type; |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 246 | /* how do we talk OML with this TRX? */ |
| 247 | struct e1inp_sign_link *oml_link; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 248 | |
| 249 | /* Abis network management O&M handle */ |
| 250 | struct abis_nm_h *nmh; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 251 | struct gsm_nm_state nm_state; |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 252 | struct gsm_attr *nm_attr; |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 253 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 254 | /* number of this BTS on given E1 link */ |
| 255 | u_int8_t bts_nr; |
| 256 | |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 257 | struct gsm48_control_channel_descr chan_desc; |
| 258 | |
Holger Freyther | ceb59b7 | 2009-02-06 18:54:00 +0000 | [diff] [blame] | 259 | /* paging state and control */ |
| 260 | struct gsm_bts_paging_state paging; |
| 261 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 262 | /* CCCH is on C0 */ |
| 263 | struct gsm_bts_trx *c0; |
Harald Welte | bbcc7a5 | 2009-02-14 19:45:44 +0000 | [diff] [blame] | 264 | |
| 265 | struct { |
| 266 | struct gsm_nm_state nm_state; |
| 267 | } site_mgr; |
| 268 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 269 | /* transceivers */ |
| 270 | int num_trx; |
| 271 | struct gsm_bts_trx trx[BTS_MAX_TRX+1]; |
| 272 | }; |
| 273 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 274 | struct gsm_network { |
| 275 | /* global parameters */ |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 276 | u_int16_t country_code; |
| 277 | u_int16_t network_code; |
Harald Welte | c6ba9c2 | 2008-12-30 18:01:02 +0000 | [diff] [blame] | 278 | char *name_long; |
| 279 | char *name_short; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 280 | |
| 281 | unsigned int num_bts; |
| 282 | /* private lists */ |
| 283 | struct gsm_bts bts[GSM_MAX_BTS+1]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 284 | }; |
| 285 | |
Harald Welte | 8c1d0e4 | 2009-02-15 03:38:12 +0000 | [diff] [blame] | 286 | struct gsm_network *gsm_network_init(unsigned int num_bts, enum gsm_bts_type bts_type, |
| 287 | u_int16_t country_code, u_int16_t network_code); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 288 | |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 289 | const char *gsm_pchan_name(enum gsm_phys_chan_config c); |
| 290 | const char *gsm_lchan_name(enum gsm_chan_t c); |
| 291 | const char *gsm_chreq_name(enum gsm_chreq_reason_t c); |
| 292 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 293 | enum gsm_e1_event { |
| 294 | EVT_E1_NONE, |
Harald Welte | 1fa60c8 | 2009-02-09 18:13:26 +0000 | [diff] [blame] | 295 | EVT_E1_TEI_UP, |
| 296 | EVT_E1_TEI_DN, |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
Harald Welte | cd06bfb | 2009-02-10 17:33:56 +0000 | [diff] [blame] | 299 | void set_ts_e1link(struct gsm_bts_trx_ts *ts, u_int8_t e1_nr, |
| 300 | u_int8_t e1_ts, u_int8_t e1_ts_ss); |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 301 | #endif |