Harald Welte | 8c8f791 | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * (C) 2009 by Mike Haben <michael.haben@btinternet.com> |
| 7 | * |
| 8 | * All Rights Reserved |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | |
| 32 | #include <openbsc/msgb.h> |
| 33 | #include <openbsc/tlv.h> |
| 34 | #include <openbsc/debug.h> |
| 35 | #include <openbsc/gsm_data.h> |
| 36 | #include <openbsc/gsm_utils.h> |
| 37 | #include <openbsc/gsm_04_08.h> |
| 38 | #include <openbsc/gsm_04_80.h> |
| 39 | |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 40 | /* Forward declarations */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 41 | static int parse_ussd(u_int8_t *ussd, struct ussd_request *req); |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 42 | static int parse_ussd_info_elements(u_int8_t *ussd_ie, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 43 | struct ussd_request *req); |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 44 | static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 45 | struct ussd_request *req); |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 46 | static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 47 | struct ussd_request *req); |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 48 | static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 49 | struct ussd_request *req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 50 | |
| 51 | static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag) |
| 52 | { |
| 53 | msgb->data -= 2; |
| 54 | msgb->data[0] = tag; |
| 55 | msgb->data[1] = msgb->len; |
| 56 | msgb->len += 2; |
| 57 | return msgb->data; |
| 58 | } |
| 59 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 60 | static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag, |
| 61 | u_int8_t value) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 62 | { |
| 63 | msgb->data -= 3; |
| 64 | msgb->len += 3; |
| 65 | msgb->data[0] = tag; |
| 66 | msgb->data[1] = 1; |
| 67 | msgb->data[2] = value; |
| 68 | return msgb->data; |
| 69 | } |
| 70 | |
| 71 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 72 | /* Decode a mobile-originated USSD-request message */ |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 73 | int gsm0480_decode_ussd_request(const struct msgb *msg, struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 74 | { |
| 75 | int rc = 0; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 76 | u_int8_t *parse_ptr = msgb_l3(msg); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 77 | |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 78 | if ((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS) { |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 79 | req->transaction_id = *parse_ptr & 0x70; |
| 80 | rc = parse_ussd(parse_ptr+1, req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if (!rc) |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 84 | DEBUGP(DMM, "Error occurred while parsing received USSD!\n"); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 85 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 86 | return rc; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 89 | static int parse_ussd(u_int8_t *ussd, struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 90 | { |
| 91 | int rc = 1; |
| 92 | u_int8_t msg_type = ussd[0] & 0xBF; /* message-type - section 3.4 */ |
| 93 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 94 | switch (msg_type) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 95 | case GSM0480_MTYPE_RELEASE_COMPLETE: |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 96 | DEBUGP(DMM, "USS Release Complete\n"); |
| 97 | /* could also parse out the optional Cause/Facility data */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 98 | req->text[0] = 0xFF; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 99 | break; |
| 100 | case GSM0480_MTYPE_REGISTER: |
| 101 | case GSM0480_MTYPE_FACILITY: |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 102 | rc &= parse_ussd_info_elements(ussd+1, req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 103 | break; |
| 104 | default: |
| 105 | fprintf(stderr, "Unknown GSM 04.80 message-type field 0x%02x\n", |
| 106 | ussd[0]); |
| 107 | rc = 0; |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | return rc; |
| 112 | } |
| 113 | |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 114 | static int parse_ussd_info_elements(u_int8_t *ussd_ie, struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 115 | { |
| 116 | int rc; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 117 | /* Information Element Identifier - table 3.2 & GSM 04.08 section 10.5 */ |
| 118 | u_int8_t iei = ussd_ie[0]; |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 119 | u_int8_t iei_length = ussd_ie[1]; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 120 | |
| 121 | switch (iei) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 122 | case GSM48_IE_CAUSE: |
| 123 | break; |
| 124 | case GSM0480_IE_FACILITY: |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 125 | rc = parse_facility_ie(ussd_ie+2, iei_length, req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 126 | break; |
| 127 | case GSM0480_IE_SS_VERSION: |
| 128 | break; |
| 129 | default: |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 130 | fprintf(stderr, "Unhandled GSM 04.08 or 04.80 IEI 0x%02x\n", |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 131 | iei); |
| 132 | rc = 0; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | return rc; |
| 137 | } |
| 138 | |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 139 | static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 140 | struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 141 | { |
| 142 | int rc = 1; |
| 143 | u_int8_t offset = 0; |
| 144 | |
| 145 | do { |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 146 | /* Component Type tag - table 3.7 */ |
| 147 | u_int8_t component_type = facility_ie[offset]; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 148 | u_int8_t component_length = facility_ie[offset+1]; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 149 | |
| 150 | switch (component_type) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 151 | case GSM0480_CTYPE_INVOKE: |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 152 | rc &= parse_ss_invoke(facility_ie+2, |
| 153 | component_length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 154 | req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 155 | break; |
| 156 | case GSM0480_CTYPE_RETURN_RESULT: |
| 157 | break; |
| 158 | case GSM0480_CTYPE_RETURN_ERROR: |
| 159 | break; |
| 160 | case GSM0480_CTYPE_REJECT: |
| 161 | break; |
| 162 | default: |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 163 | fprintf(stderr, "Unknown GSM 04.80 Facility " |
| 164 | "Component Type 0x%02x\n", component_type); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 165 | rc = 0; |
| 166 | break; |
| 167 | } |
| 168 | offset += (component_length+2); |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 169 | } while (offset < length); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 170 | |
| 171 | return rc; |
| 172 | } |
| 173 | |
| 174 | /* Parse an Invoke component - see table 3.3 */ |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 175 | static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 176 | struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 177 | { |
| 178 | int rc = 1; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 179 | u_int8_t offset; |
| 180 | |
| 181 | /* mandatory part */ |
| 182 | if (invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) { |
| 183 | fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag " |
| 184 | "0x%02x (expecting Invoke ID tag)\n", invoke_data[0]); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 185 | } |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 186 | |
| 187 | offset = invoke_data[1] + 2; |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 188 | req->invoke_id = invoke_data[2]; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 189 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 190 | /* optional part */ |
| 191 | if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 192 | offset += invoke_data[offset+1] + 2; /* skip over it */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 193 | |
| 194 | /* mandatory part */ |
| 195 | if (invoke_data[offset] == GSM0480_OPERATION_CODE) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 196 | u_int8_t operation_code = invoke_data[offset+2]; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 197 | switch (operation_code) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 198 | case GSM0480_OP_CODE_PROCESS_USS_REQ: |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 199 | rc = parse_process_uss_req(invoke_data + offset + 3, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 200 | length - offset - 3, |
| 201 | req); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 202 | break; |
| 203 | default: |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 204 | fprintf(stderr, "GSM 04.80 operation code 0x%02x " |
| 205 | "is not yet handled\n", operation_code); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 206 | rc = 0; |
| 207 | break; |
| 208 | } |
| 209 | } else { |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 210 | fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x " |
| 211 | "(expecting Operation Code tag)\n", |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 212 | invoke_data[0]); |
| 213 | rc = 0; |
| 214 | } |
| 215 | |
| 216 | return rc; |
| 217 | } |
| 218 | |
| 219 | /* Parse the parameters of a Process UnstructuredSS Request */ |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 220 | static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 221 | struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 222 | { |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 223 | int rc = 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 224 | int num_chars; |
| 225 | u_int8_t dcs; |
| 226 | |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 227 | if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) { |
| 228 | if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) { |
| 229 | dcs = uss_req_data[4]; |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 230 | if ((dcs == 0x0F) && |
| 231 | (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) { |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 232 | num_chars = (uss_req_data[6] * 8) / 7; |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 233 | /* Prevent a mobile-originated buffer-overrun! */ |
| 234 | if (num_chars > MAX_LEN_USSD_STRING) |
| 235 | num_chars = MAX_LEN_USSD_STRING; |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 236 | gsm_7bit_decode(req->text, |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 237 | &(uss_req_data[7]), num_chars); |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 238 | /* append null-terminator */ |
| 239 | req->text[num_chars+1] = 0; |
| 240 | rc = 1; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 241 | } |
| 242 | } |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 243 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 244 | return rc; |
| 245 | } |
| 246 | |
| 247 | /* Send response to a mobile-originated ProcessUnstructuredSS-Request */ |
Harald Welte | 17e5f97 | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 248 | int gsm0480_send_ussd_response(const struct msgb *in_msg, const char *response_text, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 249 | const struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 250 | { |
| 251 | struct msgb *msg = gsm48_msgb_alloc(); |
| 252 | struct gsm48_hdr *gh; |
| 253 | u_int8_t *ptr8; |
| 254 | int response_len; |
| 255 | |
| 256 | response_len = (strlen(response_text) * 7) / 8; |
| 257 | if (((strlen(response_text) * 7) % 8) != 0) |
| 258 | response_len += 1; |
| 259 | |
| 260 | msg->bts_link = in_msg->bts_link; |
| 261 | msg->lchan = in_msg->lchan; |
| 262 | |
| 263 | /* First put the payload text into the message */ |
| 264 | ptr8 = msgb_put(msg, response_len); |
| 265 | gsm_7bit_encode(ptr8, response_text); |
| 266 | |
| 267 | /* Then wrap it as an Octet String */ |
| 268 | msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG); |
| 269 | |
| 270 | /* Pre-pend the DCS octet string */ |
| 271 | msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F); |
| 272 | |
| 273 | /* Then wrap these as a Sequence */ |
| 274 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 275 | |
| 276 | /* Pre-pend the operation code */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 277 | msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, |
| 278 | GSM0480_OP_CODE_PROCESS_USS_REQ); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 279 | |
| 280 | /* Wrap the operation code and IA5 string as a sequence */ |
| 281 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 282 | |
| 283 | /* Pre-pend the invoke ID */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 284 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 285 | |
| 286 | /* Wrap this up as a Return Result component */ |
| 287 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT); |
| 288 | |
| 289 | /* Wrap the component in a Facility message */ |
| 290 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 291 | |
| 292 | /* And finally pre-pend the L3 header */ |
| 293 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | 8c8f791 | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 294 | gh->proto_discr = GSM48_PDISC_NC_SS | req->transaction_id |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 295 | | (1<<7); /* TI direction = 1 */ |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 296 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 297 | |
| 298 | return gsm48_sendmsg(msg, NULL); |
| 299 | } |
| 300 | |
Harald Welte | 8c8f791 | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 301 | int gsm0480_send_ussd_reject(const struct msgb *in_msg, |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 302 | const struct ussd_request *req) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 303 | { |
| 304 | struct msgb *msg = gsm48_msgb_alloc(); |
| 305 | struct gsm48_hdr *gh; |
| 306 | |
| 307 | msg->bts_link = in_msg->bts_link; |
| 308 | msg->lchan = in_msg->lchan; |
| 309 | |
| 310 | /* First insert the problem code */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 311 | msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL, |
| 312 | GSM_0480_GEN_PROB_CODE_UNRECOGNISED); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 313 | |
| 314 | /* Before it insert the invoke ID */ |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 315 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 316 | |
| 317 | /* Wrap this up as a Reject component */ |
| 318 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT); |
| 319 | |
| 320 | /* Wrap the component in a Facility message */ |
| 321 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 322 | |
| 323 | /* And finally pre-pend the L3 header */ |
| 324 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 325 | gh->proto_discr = GSM48_PDISC_NC_SS; |
Mike Haben | dc329a6 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 326 | gh->proto_discr |= req->transaction_id | (1<<7); /* TI direction = 1 */ |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 327 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 328 | |
| 329 | return gsm48_sendmsg(msg, NULL); |
| 330 | } |