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 | |
Vadim Yanitskiy | fa6c2b9 | 2017-08-09 17:38:39 +0600 | [diff] [blame] | 10 | /** |
| 11 | * According to the GSM 04.80 (version 5.0.0) specification Annex A |
| 12 | * "Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD |
| 13 | * OCTET STRING field is 160 bytes. |
| 14 | */ |
| 15 | #define GSM0480_USSD_OCTET_STRING_LEN 160 |
| 16 | |
| 17 | /** |
| 18 | * Thus according to ETSI TS 123 038 (version 10.0.0) specification |
| 19 | * 6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's |
| 20 | * possible to pack (160 * 8) / 7 = 182.8, that is 182 characters. |
| 21 | * The remaining 6 bits are set to zero. |
| 22 | */ |
| 23 | #define GSM0480_USSD_7BIT_STRING_LEN 182 |
| 24 | |
| 25 | /** |
| 26 | * DEPRECATED: this definition doesn't follow any specification, |
| 27 | * so we only keep it for compatibility reasons. It's strongly |
| 28 | * recommended to use correct definitions above. |
| 29 | */ |
| 30 | #define MAX_LEN_USSD_STRING 31 |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 31 | |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 32 | /* deprecated */ |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 33 | struct ussd_request { |
Harald Welte | 1f87d75 | 2012-09-07 12:07:10 +0200 | [diff] [blame] | 34 | char text[MAX_LEN_USSD_STRING + 1]; |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 35 | uint8_t transaction_id; |
| 36 | uint8_t invoke_id; |
| 37 | }; |
| 38 | |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 39 | /* deprecated */ |
Holger Hans Peter Freyther | daa653f | 2010-10-11 07:56:06 +0200 | [diff] [blame] | 40 | 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] | 41 | struct ussd_request *request) OSMO_DEPRECATED("Use gsm0480_decode_ss_request() instead"); |
| 42 | |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 43 | /** |
| 44 | * This structure represents some meaningful parts of |
| 45 | * a decoded and/or to be encoded GSM 04.80 message. |
| 46 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 47 | struct ss_request { |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 48 | /** |
| 49 | * GSM TS 04.80, section 3.6.4 "Operation code" |
| 50 | * See GSM0480_OP_CODE_* for possible values. |
| 51 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 52 | uint8_t opcode; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 53 | /** |
| 54 | * GSM TS 04.80, section 4.4.3.9 "ss-Code" |
| 55 | * The ss-Code identifier refers to the code which identify |
| 56 | * a supplementary service or a group of supplementary services. |
| 57 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 58 | uint8_t ss_code; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * A rudiment of deprecated 'ussd_request' structure. |
| 62 | * Represents the data of either an INVOKE, either |
| 63 | * a RETURN_RESULT component, encoded as ASCII in |
| 64 | * case if DCS is 0x0f (i.e. decoded by the code |
| 65 | * itself), otherwise raw bytes 'as is'. |
| 66 | */ |
Vadim Yanitskiy | fa6c2b9 | 2017-08-09 17:38:39 +0600 | [diff] [blame] | 67 | uint8_t ussd_text[GSM0480_USSD_OCTET_STRING_LEN]; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 68 | |
| 69 | /** |
Vadim Yanitskiy | a24ead0 | 2018-04-04 10:34:41 +0700 | [diff] [blame] | 70 | * Represents the data of either an INVOKE, either |
| 71 | * a RETURN_RESULT component 'as is'. Useful when |
| 72 | * decoding is not supported or not desired. |
| 73 | * |
| 74 | * Shall be always followed by its length (in bytes) |
| 75 | * and DCS (Data Coding Scheme). |
| 76 | */ |
| 77 | uint8_t ussd_data[GSM0480_USSD_OCTET_STRING_LEN]; |
| 78 | uint8_t ussd_data_len; /* Length in bytes */ |
| 79 | uint8_t ussd_data_dcs; /* Data Coding Scheme */ |
| 80 | |
| 81 | /** |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 82 | * GSM TS 04.80, section 3.3 "Transaction identifier" |
| 83 | * See GSM TS 04.07, section 11.2.3 for details. |
| 84 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 85 | uint8_t transaction_id; |
Vadim Yanitskiy | 9fb7e3a | 2018-04-04 10:08:18 +0700 | [diff] [blame] | 86 | /** |
| 87 | * GSM TS 04.80, section 3.6.3 "Component ID tag" |
| 88 | * The term Component ID refers to the Invoke ID or |
| 89 | * the Linked ID. |
| 90 | */ |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 91 | uint8_t invoke_id; |
| 92 | }; |
| 93 | |
Vadim Yanitskiy | 52e4412 | 2018-06-11 03:51:11 +0700 | [diff] [blame] | 94 | int gsm0480_extract_ie_by_tag(const struct gsm48_hdr *hdr, uint16_t msg_len, |
| 95 | uint8_t **ie, uint16_t *ie_len, uint8_t ie_tag); |
Vadim Yanitskiy | 5a09f75 | 2018-06-11 04:58:53 +0700 | [diff] [blame] | 96 | int gsm0480_parse_facility_ie(const uint8_t *facility_ie, uint16_t length, |
| 97 | struct ss_request *req); |
Tobias Engel | 419684e | 2012-03-08 13:31:52 +0100 | [diff] [blame] | 98 | int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len, |
| 99 | struct ss_request *request); |
Holger Hans Peter Freyther | 00cb570 | 2010-10-09 01:47:15 +0800 | [diff] [blame] | 100 | |
Holger Hans Peter Freyther | c64970e | 2010-10-18 16:56:43 +0200 | [diff] [blame] | 101 | 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] | 102 | struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text); |
| 103 | struct msgb *gsm0480_create_notifySS(const char *text); |
Neels Hofmeyr | bc1d758 | 2016-11-26 15:21:15 +0100 | [diff] [blame] | 104 | struct msgb *gsm0480_create_ussd_notify(int level, const char *text); |
| 105 | struct msgb *gsm0480_create_ussd_release_complete(void); |
Holger Hans Peter Freyther | 55aea50 | 2010-09-30 18:30:41 +0800 | [diff] [blame] | 106 | |
| 107 | int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id); |
| 108 | int gsm0480_wrap_facility(struct msgb *msg); |
Neels Hofmeyr | 25774b9 | 2016-11-26 15:21:05 +0100 | [diff] [blame] | 109 | |
| 110 | struct gsm48_hdr *gsm0480_l3hdr_push(struct msgb *msg, uint8_t proto_discr, |
| 111 | uint8_t msg_type); |