Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/bsc_nat.h> |
| 23 | #include <openbsc/gsm_data.h> |
| 24 | #include <openbsc/bssap.h> |
| 25 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame^] | 26 | #include <openbsc/mgcp.h> |
| 27 | #include <openbsc/mgcp_internal.h> |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 28 | |
| 29 | #include <netinet/in.h> |
| 30 | #include <arpa/inet.h> |
| 31 | |
| 32 | int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg) |
| 33 | { |
| 34 | struct tlv_parsed tp; |
| 35 | u_int16_t cic; |
| 36 | u_int8_t timeslot; |
| 37 | u_int8_t multiplex; |
| 38 | |
| 39 | if (!msg->l3h) { |
| 40 | LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n"); |
| 41 | return -1; |
| 42 | } |
| 43 | |
| 44 | if (msgb_l3len(msg) < 3) { |
| 45 | LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n"); |
| 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0); |
| 50 | if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) { |
| 51 | LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | cic = ntohs(*(u_int16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)); |
| 56 | timeslot = cic & 0x1f; |
| 57 | multiplex = (cic & ~0x1f) >> 5; |
| 58 | |
| 59 | con->msc_timeslot = (32 * multiplex) + timeslot; |
| 60 | con->bsc_timeslot = con->msc_timeslot; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | void bsc_mgcp_clear(struct sccp_connections *con) |
| 65 | { |
| 66 | con->msc_timeslot = -1; |
| 67 | con->bsc_timeslot = -1; |
| 68 | } |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame^] | 69 | |
| 70 | void bsc_mgcp_free_endpoints(struct bsc_nat *nat) |
| 71 | { |
| 72 | int i; |
| 73 | |
| 74 | for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i) |
| 75 | mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]); |
| 76 | } |