Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 1 | /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ |
| 2 | |
Harald Welte | 605ac5d | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 3 | /* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 15 | * GNU General Public License for more details. |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include <netinet/in.h> |
| 26 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/msgb.h> |
| 28 | #include <osmocom/gsm/tlv.h> |
| 29 | #include <osmocom/core/talloc.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 30 | #include <osmocom/gprs/gprs_bssgp.h> |
| 31 | #include <osmocom/gprs/gprs_ns.h> |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 32 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 33 | #include "common_vty.h" |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 34 | |
| 35 | struct gprs_ns_inst *bssgp_nsi; |
| 36 | |
| 37 | /* BSSGP Protocol specific, not implementation specific */ |
| 38 | /* FIXME: This needs to go into libosmocore after finished */ |
| 39 | |
| 40 | /* Chapter 11.3.9 / Table 11.10: Cause coding */ |
| 41 | static const struct value_string bssgp_cause_strings[] = { |
| 42 | { BSSGP_CAUSE_PROC_OVERLOAD, "Processor overload" }, |
| 43 | { BSSGP_CAUSE_EQUIP_FAIL, "Equipment Failure" }, |
| 44 | { BSSGP_CAUSE_TRASIT_NET_FAIL, "Transit netowkr service failure" }, |
| 45 | { BSSGP_CAUSE_CAPA_GREATER_0KPBS,"Transmission capacity modified" }, |
| 46 | { BSSGP_CAUSE_UNKNOWN_MS, "Unknown MS" }, |
| 47 | { BSSGP_CAUSE_UNKNOWN_BVCI, "Unknown BVCI" }, |
| 48 | { BSSGP_CAUSE_CELL_TRAF_CONG, "Cell traffic congestion" }, |
| 49 | { BSSGP_CAUSE_SGSN_CONG, "SGSN congestion" }, |
| 50 | { BSSGP_CAUSE_OML_INTERV, "O&M intervention" }, |
| 51 | { BSSGP_CAUSE_BVCI_BLOCKED, "BVCI blocked" }, |
| 52 | { BSSGP_CAUSE_PFC_CREATE_FAIL, "PFC create failure" }, |
| 53 | { BSSGP_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" }, |
| 54 | { BSSGP_CAUSE_INV_MAND_INF, "Invalid mandatory information" }, |
| 55 | { BSSGP_CAUSE_MISSING_MAND_IE, "Missing mandatory IE" }, |
| 56 | { BSSGP_CAUSE_MISSING_COND_IE, "Missing conditional IE" }, |
| 57 | { BSSGP_CAUSE_UNEXP_COND_IE, "Unexpected conditional IE" }, |
| 58 | { BSSGP_CAUSE_COND_IE_ERR, "Conditional IE error" }, |
| 59 | { BSSGP_CAUSE_PDU_INCOMP_STATE, "PDU incompatible with protocol state" }, |
| 60 | { BSSGP_CAUSE_PROTO_ERR_UNSPEC, "Protocol error - unspecified" }, |
| 61 | { BSSGP_CAUSE_PDU_INCOMP_FEAT, "PDU not compatible with feature set" }, |
| 62 | { 0, NULL }, |
| 63 | }; |
| 64 | |
| 65 | const char *bssgp_cause_str(enum gprs_bssgp_cause cause) |
| 66 | { |
| 67 | return get_value_string(bssgp_cause_strings, cause); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | struct msgb *bssgp_msgb_alloc(void) |
| 72 | { |
Jacob Erlbeck | a39e2de | 2014-09-23 13:28:24 +0200 | [diff] [blame] | 73 | struct msgb *msg = msgb_alloc_headroom(4096, 128, "BSSGP"); |
Jacob Erlbeck | a84db61 | 2015-04-09 14:22:22 +0200 | [diff] [blame] | 74 | |
| 75 | /* TODO: Add handling of msg == NULL to this function and to all callers */ |
| 76 | OSMO_ASSERT(msg != NULL); |
| 77 | |
Jacob Erlbeck | a39e2de | 2014-09-23 13:28:24 +0200 | [diff] [blame] | 78 | msgb_bssgph(msg) = msg->data; |
| 79 | return msg; |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */ |
| 83 | int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, |
| 84 | uint16_t bvci, uint16_t ns_bvci) |
| 85 | { |
| 86 | struct msgb *msg = bssgp_msgb_alloc(); |
| 87 | struct bssgp_normal_hdr *bgph = |
| 88 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 89 | uint16_t _bvci; |
| 90 | |
| 91 | msgb_nsei(msg) = nsei; |
| 92 | msgb_bvci(msg) = ns_bvci; |
| 93 | |
| 94 | bgph->pdu_type = pdu_type; |
| 95 | _bvci = htons(bvci); |
| 96 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 97 | |
| 98 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 99 | } |
| 100 | |
| 101 | /* Chapter 10.4.14: Status */ |
| 102 | int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg) |
| 103 | { |
| 104 | struct msgb *msg = bssgp_msgb_alloc(); |
| 105 | struct bssgp_normal_hdr *bgph = |
| 106 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 107 | |
Jacob Erlbeck | a716577 | 2014-09-23 13:28:21 +0200 | [diff] [blame] | 108 | /* GSM 08.18, 10.4.14.1: The BVCI must be included if (and only if) the |
| 109 | cause is either "BVCI blocked" or "BVCI unknown" */ |
| 110 | if (cause == BSSGP_CAUSE_UNKNOWN_BVCI || cause == BSSGP_CAUSE_BVCI_BLOCKED) { |
| 111 | if (bvci == NULL) |
| 112 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: " |
| 113 | "missing conditional BVCI\n", |
| 114 | bssgp_cause_str(cause)); |
| 115 | } else { |
| 116 | if (bvci != NULL) |
| 117 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Tx STATUS, cause=%s: " |
| 118 | "unexpected conditional BVCI\n", |
| 119 | bssgp_cause_str(cause)); |
| 120 | } |
| 121 | |
Holger Hans Peter Freyther | 8e2e78e | 2010-06-08 16:05:20 +0800 | [diff] [blame] | 122 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n", |
Harald Welte | cfb545a | 2010-06-03 21:30:57 +0200 | [diff] [blame] | 123 | bvci ? *bvci : 0, bssgp_cause_str(cause)); |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 124 | msgb_nsei(msg) = msgb_nsei(orig_msg); |
| 125 | msgb_bvci(msg) = 0; |
| 126 | |
| 127 | bgph->pdu_type = BSSGP_PDUT_STATUS; |
| 128 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause); |
| 129 | if (bvci) { |
| 130 | uint16_t _bvci = htons(*bvci); |
| 131 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 132 | } |
Harald Welte | d83d1b6 | 2011-07-16 13:45:10 +0200 | [diff] [blame] | 133 | msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, |
| 134 | msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg)); |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 135 | |
| 136 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 137 | } |