Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 1 | /* GSM 08.08 like API for OpenBSC. The bridge from MSC to BSC */ |
| 2 | |
| 3 | /* (C) 2010 by Holger Hans Peter Freyther |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 4 | * (C) 2010 by On Waves |
Holger Hans Peter Freyther | a7d3e8e | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 5 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <openbsc/bsc_api.h> |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 26 | #include <openbsc/bsc_rll.h> |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 27 | #include <openbsc/gsm_data.h> |
| 28 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 29 | #include <openbsc/abis_rsl.h> |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 30 | #include <openbsc/chan_alloc.h> |
Holger Hans Peter Freyther | 69fdcd8 | 2010-06-21 15:35:03 +0800 | [diff] [blame^] | 31 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 32 | |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 33 | #include <osmocore/talloc.h> |
| 34 | |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 35 | static void rll_ind_cb(struct gsm_lchan *, uint8_t, void *, enum bsc_rllr_ind); |
| 36 | static void send_sapi_reject(struct gsm_subscriber_connection *conn, int link_id); |
| 37 | |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 38 | int bsc_api_init(struct gsm_network *network, struct bsc_api *api) |
| 39 | { |
| 40 | network->bsc_api = api; |
| 41 | return 0; |
| 42 | } |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 43 | |
| 44 | int gsm0808_submit_dtap(struct gsm_subscriber_connection *conn, |
| 45 | struct msgb *msg, int link_id) |
| 46 | { |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 47 | uint8_t sapi = link_id & 0x7; |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 48 | msg->lchan = conn->lchan; |
| 49 | msg->trx = msg->lchan->ts->trx; |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | a76bcb0 | 2010-06-17 17:48:13 +0800 | [diff] [blame] | 51 | msg->l3h = msg->data; |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 52 | if (conn->lchan->sapis[sapi] == LCHAN_SAPI_UNUSED) { |
| 53 | OBSC_LINKID_CB(msg) = link_id; |
| 54 | if (rll_establish(msg->lchan, sapi, rll_ind_cb, msg) != 0) { |
| 55 | msgb_free(msg); |
| 56 | send_sapi_reject(conn, link_id); |
| 57 | return -1; |
| 58 | } |
| 59 | return 0; |
| 60 | } else { |
| 61 | return rsl_data_request(msg, link_id); |
| 62 | } |
Holger Hans Peter Freyther | 7cdff24 | 2010-03-23 07:40:46 +0100 | [diff] [blame] | 63 | } |
Holger Hans Peter Freyther | a7d3e8e | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 64 | |
Holger Hans Peter Freyther | 897ad9a | 2010-06-16 14:10:45 +0800 | [diff] [blame] | 65 | int gsm0808_page(struct gsm_bts *bts, unsigned int page_group, unsigned int mi_len, |
| 66 | uint8_t *mi, int chan_type) |
| 67 | { |
| 68 | return rsl_paging_cmd(bts, page_group, mi_len, mi, chan_type); |
| 69 | } |
| 70 | |
Holger Hans Peter Freyther | a7d3e8e | 2010-06-14 18:03:06 +0800 | [diff] [blame] | 71 | /* dequeue messages to layer 4 */ |
| 72 | int bsc_upqueue(struct gsm_network *net) |
| 73 | { |
| 74 | struct gsm_mncc *mncc; |
| 75 | struct msgb *msg; |
| 76 | int work = 0; |
| 77 | |
| 78 | if (net) |
| 79 | while ((msg = msgb_dequeue(&net->upqueue))) { |
| 80 | mncc = (struct gsm_mncc *)msg->data; |
| 81 | if (net->mncc_recv) |
| 82 | net->mncc_recv(net, mncc->msg_type, mncc); |
| 83 | work = 1; /* work done */ |
| 84 | talloc_free(msg); |
| 85 | } |
| 86 | |
| 87 | return work; |
| 88 | } |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 89 | |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 90 | int gsm0408_rcvmsg(struct msgb *msg, uint8_t link_id) |
| 91 | { |
| 92 | int rc; |
| 93 | struct gsm_subscriber_connection *conn; |
| 94 | struct bsc_api *api = msg->lchan->ts->trx->bts->network->bsc_api; |
| 95 | |
| 96 | conn = &msg->lchan->conn; |
| 97 | if (conn->allocated) { |
Holger Hans Peter Freyther | 69fdcd8 | 2010-06-21 15:35:03 +0800 | [diff] [blame^] | 98 | log_set_context(BSC_CTX_SUBSCR, conn->subscr); |
Holger Hans Peter Freyther | b979579 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 99 | api->dtap(conn, msg); |
| 100 | } else { |
| 101 | /* accept the connection or close the lchan */ |
| 102 | rc = api->compl_l3(conn, msg, 0); |
| 103 | if (rc == BSC_API_CONN_POL_ACCEPT) |
| 104 | conn->allocated = 1; |
| 105 | else |
| 106 | lchan_auto_release(msg->lchan); |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Holger Hans Peter Freyther | ee2be4c | 2010-06-15 11:20:52 +0800 | [diff] [blame] | 112 | static void send_sapi_reject(struct gsm_subscriber_connection *conn, int link_id) |
| 113 | { |
| 114 | struct bsc_api *api; |
| 115 | |
| 116 | api = conn->bts->network->bsc_api; |
| 117 | if (!api || !api->sapi_n_reject) |
| 118 | return; |
| 119 | |
| 120 | api->sapi_n_reject(conn, link_id); |
| 121 | } |
| 122 | |
| 123 | static void rll_ind_cb(struct gsm_lchan *lchan, uint8_t link_id, void *_data, enum bsc_rllr_ind rllr_ind) |
| 124 | { |
| 125 | struct msgb *msg = _data; |
| 126 | |
| 127 | switch (rllr_ind) { |
| 128 | case BSC_RLLR_IND_EST_CONF: |
| 129 | rsl_data_request(msg, OBSC_LINKID_CB(msg)); |
| 130 | break; |
| 131 | case BSC_RLLR_IND_REL_IND: |
| 132 | case BSC_RLLR_IND_ERR_IND: |
| 133 | case BSC_RLLR_IND_TIMEOUT: |
| 134 | send_sapi_reject(&lchan->conn, OBSC_LINKID_CB(msg)); |
| 135 | msgb_free(msg); |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
Holger Hans Peter Freyther | 39c90ef | 2010-06-14 18:20:15 +0800 | [diff] [blame] | 140 | static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal, |
| 141 | void *handler_data, void *signal_data) |
| 142 | { |
| 143 | struct bsc_api *bsc; |
| 144 | struct gsm_lchan *lchan; |
| 145 | |
| 146 | if (subsys != SS_LCHAN || signal != S_LCHAN_UNEXPECTED_RELEASE) |
| 147 | return 0; |
| 148 | |
| 149 | lchan = (struct gsm_lchan *)signal_data; |
| 150 | if (!lchan) |
| 151 | return 0; |
| 152 | |
| 153 | |
| 154 | bsc = lchan->ts->trx->bts->network->bsc_api; |
| 155 | if (!bsc || !bsc->clear_request) |
| 156 | return 0; |
| 157 | |
| 158 | bsc->clear_request(&lchan->conn, 0); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static __attribute__((constructor)) void on_dso_load_bsc(void) |
| 163 | { |
| 164 | register_signal_handler(SS_LCHAN, bsc_handle_lchan_signal, NULL); |
Holger Hans Peter Freyther | b2f49a5 | 2010-06-15 11:20:24 +0800 | [diff] [blame] | 165 | } |