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