blob: 4200189dbc97267108f92cc560e08993199a7cf5 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm0480.h */
2
Sylvain Munaut12ba7782014-06-16 10:13:40 +02003#pragma once
Holger Hans Peter Freyther55aea502010-09-30 18:30:41 +08004
Tobias Engel419684e2012-03-08 13:31:52 +01005#include <osmocom/core/defs.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +01006#include <osmocom/core/msgb.h>
7#include <osmocom/gsm/protocol/gsm_04_08.h>
8#include <osmocom/gsm/protocol/gsm_04_80.h>
Holger Hans Peter Freyther55aea502010-09-30 18:30:41 +08009
Harald Welteb1a35d62018-06-16 18:34:52 +020010extern const struct value_string gsm0480_comp_type_names[];
11static inline const char *gsm0480_comp_type_name(uint8_t comp_type) {
12 return get_value_string(gsm0480_comp_type_names, comp_type);
13}
14
15extern const struct value_string gsm0480_op_code_names[];
16static inline const char *gsm0480_op_code_name(uint8_t op_code) {
17 return get_value_string(gsm0480_op_code_names, op_code);
18}
19
Vadim Yanitskiyfa6c2b92017-08-09 17:38:39 +060020/**
21 * According to the GSM 04.80 (version 5.0.0) specification Annex A
22 * "Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD
23 * OCTET STRING field is 160 bytes.
24 */
25#define GSM0480_USSD_OCTET_STRING_LEN 160
26
27/**
28 * Thus according to ETSI TS 123 038 (version 10.0.0) specification
29 * 6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's
30 * possible to pack (160 * 8) / 7 = 182.8, that is 182 characters.
31 * The remaining 6 bits are set to zero.
32 */
33#define GSM0480_USSD_7BIT_STRING_LEN 182
34
35/**
36 * DEPRECATED: this definition doesn't follow any specification,
37 * so we only keep it for compatibility reasons. It's strongly
38 * recommended to use correct definitions above.
39 */
40#define MAX_LEN_USSD_STRING 31
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080041
Tobias Engel419684e2012-03-08 13:31:52 +010042/* deprecated */
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080043struct ussd_request {
Harald Welte1f87d752012-09-07 12:07:10 +020044 char text[MAX_LEN_USSD_STRING + 1];
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080045 uint8_t transaction_id;
46 uint8_t invoke_id;
47};
48
Tobias Engel419684e2012-03-08 13:31:52 +010049/* deprecated */
Holger Hans Peter Freytherdaa653f2010-10-11 07:56:06 +020050int gsm0480_decode_ussd_request(const struct gsm48_hdr *hdr, uint16_t len,
Tobias Engel419684e2012-03-08 13:31:52 +010051 struct ussd_request *request) OSMO_DEPRECATED("Use gsm0480_decode_ss_request() instead");
52
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070053/**
54 * This structure represents some meaningful parts of
55 * a decoded and/or to be encoded GSM 04.80 message.
56 */
Tobias Engel419684e2012-03-08 13:31:52 +010057struct ss_request {
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070058 /**
59 * GSM TS 04.80, section 3.6.4 "Operation code"
60 * See GSM0480_OP_CODE_* for possible values.
61 */
Tobias Engel419684e2012-03-08 13:31:52 +010062 uint8_t opcode;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070063 /**
64 * GSM TS 04.80, section 4.4.3.9 "ss-Code"
65 * The ss-Code identifier refers to the code which identify
66 * a supplementary service or a group of supplementary services.
67 */
Tobias Engel419684e2012-03-08 13:31:52 +010068 uint8_t ss_code;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070069
70 /**
71 * A rudiment of deprecated 'ussd_request' structure.
72 * Represents the data of either an INVOKE, either
73 * a RETURN_RESULT component, encoded as ASCII in
74 * case if DCS is 0x0f (i.e. decoded by the code
75 * itself), otherwise raw bytes 'as is'.
76 */
Vadim Yanitskiyfa6c2b92017-08-09 17:38:39 +060077 uint8_t ussd_text[GSM0480_USSD_OCTET_STRING_LEN];
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070078
79 /**
Vadim Yanitskiya24ead02018-04-04 10:34:41 +070080 * Represents the data of either an INVOKE, either
81 * a RETURN_RESULT component 'as is'. Useful when
82 * decoding is not supported or not desired.
83 *
84 * Shall be always followed by its length (in bytes)
85 * and DCS (Data Coding Scheme).
86 */
87 uint8_t ussd_data[GSM0480_USSD_OCTET_STRING_LEN];
88 uint8_t ussd_data_len; /* Length in bytes */
89 uint8_t ussd_data_dcs; /* Data Coding Scheme */
90
91 /**
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070092 * GSM TS 04.80, section 3.3 "Transaction identifier"
93 * See GSM TS 04.07, section 11.2.3 for details.
94 */
Tobias Engel419684e2012-03-08 13:31:52 +010095 uint8_t transaction_id;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070096 /**
97 * GSM TS 04.80, section 3.6.3 "Component ID tag"
98 * The term Component ID refers to the Invoke ID or
99 * the Linked ID.
100 */
Tobias Engel419684e2012-03-08 13:31:52 +0100101 uint8_t invoke_id;
102};
103
Vadim Yanitskiy52e44122018-06-11 03:51:11 +0700104int gsm0480_extract_ie_by_tag(const struct gsm48_hdr *hdr, uint16_t msg_len,
105 uint8_t **ie, uint16_t *ie_len, uint8_t ie_tag);
Vadim Yanitskiy5a09f752018-06-11 04:58:53 +0700106int gsm0480_parse_facility_ie(const uint8_t *facility_ie, uint16_t length,
107 struct ss_request *req);
Tobias Engel419684e2012-03-08 13:31:52 +0100108int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len,
109 struct ss_request *request);
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +0800110
Harald Welte88fa5a32018-07-28 22:55:43 +0200111struct msgb *gsm0480_msgb_alloc_name(const char *name);
Harald Welteb0d95942018-07-28 23:02:48 +0200112struct msgb *gsm0480_gen_ussd_resp_7bit(uint8_t invoke_id, const char *text);
Harald Welte7ecc4a32018-07-28 23:05:36 +0200113struct msgb *gsm0480_gen_return_error(uint8_t invoke_id, uint8_t error_code);
114struct msgb *gsm0480_gen_reject(int invoke_id, uint8_t problem_tag, uint8_t problem_code);
Harald Welte88fa5a32018-07-28 22:55:43 +0200115
Holger Hans Peter Freytherc64970e2010-10-18 16:56:43 +0200116struct msgb *gsm0480_create_ussd_resp(uint8_t invoke_id, uint8_t trans_id, const char *text);
Holger Hans Peter Freyther55aea502010-09-30 18:30:41 +0800117struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text);
118struct msgb *gsm0480_create_notifySS(const char *text);
Neels Hofmeyrbc1d7582016-11-26 15:21:15 +0100119struct msgb *gsm0480_create_ussd_notify(int level, const char *text);
Vadim Yanitskiy6b4895f2019-02-06 02:29:55 +0700120struct msgb *gsm0480_create_ussd_release_complete(void)
121 OSMO_DEPRECATED("Use gsm0480_create_release_complete() instead.");
122struct msgb *gsm0480_create_release_complete(uint8_t trans_id);
Holger Hans Peter Freyther55aea502010-09-30 18:30:41 +0800123
124int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id);
125int gsm0480_wrap_facility(struct msgb *msg);