blob: b31f8a717500978a60226cb1d0bc2191b201ac3d [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
Vadim Yanitskiyfa6c2b92017-08-09 17:38:39 +060010/**
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 Freyther00cb5702010-10-09 01:47:15 +080031
Tobias Engel419684e2012-03-08 13:31:52 +010032/* deprecated */
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080033struct ussd_request {
Harald Welte1f87d752012-09-07 12:07:10 +020034 char text[MAX_LEN_USSD_STRING + 1];
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080035 uint8_t transaction_id;
36 uint8_t invoke_id;
37};
38
Tobias Engel419684e2012-03-08 13:31:52 +010039/* deprecated */
Holger Hans Peter Freytherdaa653f2010-10-11 07:56:06 +020040int gsm0480_decode_ussd_request(const struct gsm48_hdr *hdr, uint16_t len,
Tobias Engel419684e2012-03-08 13:31:52 +010041 struct ussd_request *request) OSMO_DEPRECATED("Use gsm0480_decode_ss_request() instead");
42
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070043/**
44 * This structure represents some meaningful parts of
45 * a decoded and/or to be encoded GSM 04.80 message.
46 */
Tobias Engel419684e2012-03-08 13:31:52 +010047struct ss_request {
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070048 /**
49 * GSM TS 04.80, section 3.6.4 "Operation code"
50 * See GSM0480_OP_CODE_* for possible values.
51 */
Tobias Engel419684e2012-03-08 13:31:52 +010052 uint8_t opcode;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070053 /**
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 Engel419684e2012-03-08 13:31:52 +010058 uint8_t ss_code;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070059
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 Yanitskiyfa6c2b92017-08-09 17:38:39 +060067 uint8_t ussd_text[GSM0480_USSD_OCTET_STRING_LEN];
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070068
69 /**
Vadim Yanitskiya24ead02018-04-04 10:34:41 +070070 * 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 Yanitskiy9fb7e3a2018-04-04 10:08:18 +070082 * GSM TS 04.80, section 3.3 "Transaction identifier"
83 * See GSM TS 04.07, section 11.2.3 for details.
84 */
Tobias Engel419684e2012-03-08 13:31:52 +010085 uint8_t transaction_id;
Vadim Yanitskiy9fb7e3a2018-04-04 10:08:18 +070086 /**
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 Engel419684e2012-03-08 13:31:52 +010091 uint8_t invoke_id;
92};
93
Vadim Yanitskiy52e44122018-06-11 03:51:11 +070094int 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);
Tobias Engel419684e2012-03-08 13:31:52 +010096int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t len,
97 struct ss_request *request);
Holger Hans Peter Freyther00cb5702010-10-09 01:47:15 +080098
Holger Hans Peter Freytherc64970e2010-10-18 16:56:43 +020099struct 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 +0800100struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text);
101struct msgb *gsm0480_create_notifySS(const char *text);
Neels Hofmeyrbc1d7582016-11-26 15:21:15 +0100102struct msgb *gsm0480_create_ussd_notify(int level, const char *text);
103struct msgb *gsm0480_create_ussd_release_complete(void);
Holger Hans Peter Freyther55aea502010-09-30 18:30:41 +0800104
105int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id);
106int gsm0480_wrap_facility(struct msgb *msg);
Neels Hofmeyr25774b92016-11-26 15:21:05 +0100107
108struct gsm48_hdr *gsm0480_l3hdr_push(struct msgb *msg, uint8_t proto_discr,
109 uint8_t msg_type);