Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm0480.h */ |
| 2 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 3 | #pragma once |
Holger Hans Peter Freyther | 55aea50 | 2010-09-30 18:30:41 +0800 | [diff] [blame] | 4 | |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 5 | #include <osmocom/core/defs.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 6 | #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 Freyther | 55aea50 | 2010-09-30 18:30:41 +0800 | [diff] [blame] | 9 | |
Harald Welte | b1a35d6 | 2018-06-16 18:34:52 +0200 | [diff] [blame] | 10 | extern const struct value_string gsm0480_comp_type_names[]; |
| 11 | static inline const char *gsm0480_comp_type_name(uint8_t comp_type) { |
| 12 | return get_value_string(gsm0480_comp_type_names, comp_type); |
| 13 | } |
| 14 | |
| 15 | extern const struct value_string gsm0480_op_code_names[]; |
| 16 | static 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 Yanitskiy | fa6c2b9 | 2017-08-09 17:38:39 +0600 | [diff] [blame] | 20 | /** |
| 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 Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 41 | |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 42 | /* deprecated */ |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 43 | struct ussd_request { |
Harald Welte | 1f87d75 | 2012-09-07 12:07:10 +0200 | [diff] [blame] | 44 | char text[MAX_LEN_USSD_STRING + 1]; |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 45 | uint8_t transaction_id; |
| 46 | uint8_t invoke_id; |
| 47 | }; |
| 48 | |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 49 | /* deprecated */ |
Holger Hans Peter Freyther | daa653f | 2010-10-11 07:56:06 +0200 | [diff] [blame] | 50 | int gsm0480_decode_ussd_request(const struct gsm48_hdr *hdr, uint16_t len, |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 51 | struct ussd_request *request) OSMO_DEPRECATED("Use gsm0480_decode_ss_request() instead"); |
| 52 | |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 53 | /** |
| 54 | * This structure represents some meaningful parts of |
| 55 | * a decoded and/or to be encoded GSM 04.80 message. |
| 56 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 57 | struct ss_request { |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 58 | /** |
| 59 | * GSM TS 04.80, section 3.6.4 "Operation code" |
| 60 | * See GSM0480_OP_CODE_* for possible values. |
| 61 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 62 | uint8_t opcode; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 63 | /** |
| 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 Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 68 | uint8_t ss_code; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 69 | |
| 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 Yanitskiy | fa6c2b9 | 2017-08-09 17:38:39 +0600 | [diff] [blame] | 77 | uint8_t ussd_text[GSM0480_USSD_OCTET_STRING_LEN]; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 78 | |
| 79 | /** |
Vadim Yanitskiy | a24ead0 | 2018-04-04 10:34:41 +0700 | [diff] [blame] | 80 | * 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 Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 92 | * GSM TS 04.80, section 3.3 "Transaction identifier" |
| 93 | * See GSM TS 04.07, section 11.2.3 for details. |
| 94 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 95 | uint8_t transaction_id; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 96 | /** |
| 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 Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 101 | uint8_t invoke_id; |
| 102 | }; |
| 103 | |
Vadim Yanitskiy | 52e4412 | 2018-06-11 03:51:11 +0700 | [diff] [blame] | 104 | int 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 Yanitskiy | 5a09f75 | 2018-06-11 04:58:53 +0700 | [diff] [blame] | 106 | int gsm0480_parse_facility_ie(const uint8_t *facility_ie, uint16_t length, |
| 107 | struct ss_request *req); |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 108 | int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len, |
| 109 | struct ss_request *request); |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 110 | |
Harald Welte | 88fa5a3 | 2018-07-28 22:55:43 +0200 | [diff] [blame] | 111 | struct msgb *gsm0480_msgb_alloc_name(const char *name); |
Harald Welte | b0d9594 | 2018-07-28 23:02:48 +0200 | [diff] [blame] | 112 | struct msgb *gsm0480_gen_ussd_resp_7bit(uint8_t invoke_id, const char *text); |
Harald Welte | 7ecc4a3 | 2018-07-28 23:05:36 +0200 | [diff] [blame] | 113 | struct msgb *gsm0480_gen_return_error(uint8_t invoke_id, uint8_t error_code); |
| 114 | struct msgb *gsm0480_gen_reject(int invoke_id, uint8_t problem_tag, uint8_t problem_code); |
Harald Welte | 88fa5a3 | 2018-07-28 22:55:43 +0200 | [diff] [blame] | 115 | |
Holger Hans Peter Freyther | c64970e | 2010-10-18 16:56:43 +0200 | [diff] [blame] | 116 | struct msgb *gsm0480_create_ussd_resp(uint8_t invoke_id, uint8_t trans_id, const char *text); |
Holger Hans Peter Freyther | 55aea50 | 2010-09-30 18:30:41 +0800 | [diff] [blame] | 117 | struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text); |
| 118 | struct msgb *gsm0480_create_notifySS(const char *text); |
Neels Hofmeyr | bc1d758 | 2016-11-26 15:21:15 +0100 | [diff] [blame] | 119 | struct msgb *gsm0480_create_ussd_notify(int level, const char *text); |
Vadim Yanitskiy | 6b4895f | 2019-02-06 02:29:55 +0700 | [diff] [blame] | 120 | struct msgb *gsm0480_create_ussd_release_complete(void) |
| 121 | OSMO_DEPRECATED("Use gsm0480_create_release_complete() instead."); |
| 122 | struct msgb *gsm0480_create_release_complete(uint8_t trans_id); |
Holger Hans Peter Freyther | 55aea50 | 2010-09-30 18:30:41 +0800 | [diff] [blame] | 123 | |
| 124 | int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id); |
| 125 | int gsm0480_wrap_facility(struct msgb *msg); |