Loading...
Searching...
No Matches
gsm0480.c File Reference

Format functions for GSM 04.80. More...

`#include <osmocom/gsm/gsm48.h>`
`#include <osmocom/gsm/gsm0480.h>`
`#include <osmocom/gsm/gsm_utils.h>`
`#include <osmocom/core/logging.h>`
`#include <osmocom/gsm/protocol/gsm_04_08.h>`
`#include <osmocom/gsm/protocol/gsm_04_80.h>`
`#include <string.h>`
`#include <errno.h>`

## Functions

int | gsm0480_wrap_invoke (struct msgb *msg, int op, int link_id)
int | gsm0480_wrap_facility (struct msgb *msg)
struct msgb * | gsm0480_create_unstructuredSS_Notify (int alertPattern, const char *text)
struct msgb * | gsm0480_create_notifySS (const char *text)
static int | parse_ss (const struct gsm48_hdr *hdr, uint16_t len, struct ss_request *req)
static int | parse_ss_facility (const uint8_t *ss_facility, uint16_t len, struct ss_request *req)
static int | parse_ss_info_elements (const uint8_t *ss_ie, uint16_t len, struct ss_request *req)
static int | parse_ss_invoke (const uint8_t *invoke_data, uint16_t length, struct ss_request *req)
static int | parse_ss_return_result (const uint8_t *rr_data, uint16_t length, struct ss_request *req)
static int | parse_process_uss_data (const uint8_t *uss_req_data, uint16_t length, struct ss_request *req)
static int | parse_process_uss_req (const uint8_t *uss_req_data, uint16_t length, struct ss_request *req)
static int | parse_ss_for_bs_req (const uint8_t *ss_req_data, uint16_t length, struct ss_request *req)
int | gsm0480_extract_ie_by_tag (const struct gsm48_hdr *hdr, uint16_t msg_len, uint8_t **ie, uint16_t *ie_len, uint8_t ie_tag)
| Get pointer to the IE of a given type.
int | gsm0480_decode_ussd_request (const struct gsm48_hdr *hdr, uint16_t len, struct ussd_request *req)
int | gsm0480_decode_ss_request (const struct gsm48_hdr *hdr, uint16_t len, struct ss_request *req)
int | gsm0480_parse_facility_ie (const uint8_t *facility_ie, uint16_t length, struct ss_request *req)
| Parse the components of a given Facility IE.
struct msgb * | gsm0480_msgb_alloc_name (const char *name)
struct msgb * | gsm0480_gen_ussd_resp_7bit (uint8_t invoke_id, const char *text)
| Generate a USSD ReturnResult component containing a string in default GSM alphabet.
struct msgb * | gsm0480_create_ussd_resp (uint8_t invoke_id, uint8_t trans_id, const char *text)
| Legacy helper: Generate USSD response including FACILITY IE + L3 header.
struct msgb * | gsm0480_gen_return_error (uint8_t invoke_id, uint8_t error_code)
| Generate a ReturnError component (see section 3.6.1) and given error code (see section 3.6.6).
struct msgb * | gsm0480_gen_reject (int invoke_id, uint8_t problem_tag, uint8_t problem_code)
| Generate a Reject component (see section 3.6.1) and given error code (see section 3.6.7).
struct msgb * | gsm0480_create_ussd_notify (int level, const char *text)
struct msgb * | gsm0480_create_ussd_release_complete (void)
| Deprecated, use gsm0480_create_release_complete() instead.
struct msgb * | gsm0480_create_release_complete (uint8_t trans_id)
| Create a GSM 04.80 Release complete (see 2.5) message, prefixed by GSM 04.08 L3 header with a given transaction ID.

## Variables

const struct value_string | gsm0480_comp_type_names []
const struct value_string | gsm0480_op_code_names []

## Detailed Description

Format functions for GSM 04.80.

## Function Documentation

## gsm0480_create_notifySS()

struct msgb * gsm0480_create_notifySS | ( | const char * | text | ) |

References msgb::data, gsm0480_msgb_alloc_name(), GSM_0480_SEQUENCE_TAG, gsm_7bit_encode_n_ussd(), len, and msg.

## gsm0480_create_release_complete()

struct msgb * gsm0480_create_release_complete | ( | uint8_t | trans_id | ) |

Create a GSM 04.80 Release complete (see 2.5) message, prefixed by GSM 04.08 L3 header with a given transaction ID.

Parameters

  [in] | trans_id | GSM 04.07 transaction identifier (and TI flag)

Returns
  message buffer containing the Release complete message

References gsm0480_msgb_alloc_name(), GSM0480_MTYPE_RELEASE_COMPLETE, GSM48_PDISC_NC_SS, gsm48_push_l3hdr_tid, and msg.

## gsm0480_create_unstructuredSS_Notify()

struct msgb * gsm0480_create_unstructuredSS_Notify | ( | int | alertPattern,
|  | const char * | text
| ) |  |

References ASN1_OCTET_STRING_TAG, msgb::data, gsm0480_msgb_alloc_name(), GSM_0480_SEQUENCE_TAG, gsm_7bit_encode_n_ussd(), len, and msg.

Referenced by gsm0480_create_ussd_notify().

## gsm0480_create_ussd_notify()

struct msgb * gsm0480_create_ussd_notify | ( | int | level,
|  | const char * | text
| ) |  |

References gsm0480_create_unstructuredSS_Notify(), GSM0480_MTYPE_REGISTER, GSM0480_OP_CODE_USS_NOTIFY, gsm0480_wrap_facility(), gsm0480_wrap_invoke(), GSM48_PDISC_NC_SS, gsm48_push_l3hdr(), level, and msg.

## gsm0480_create_ussd_release_complete()

struct msgb * gsm0480_create_ussd_release_complete | ( | void |  | ) |

Deprecated, use gsm0480_create_release_complete() instead.

References gsm0480_msgb_alloc_name(), GSM0480_MTYPE_RELEASE_COMPLETE, GSM48_PDISC_NC_SS, gsm48_push_l3hdr(), and msg.

## gsm0480_create_ussd_resp()

struct msgb * gsm0480_create_ussd_resp | ( | uint8_t | invoke_id,
|  | uint8_t | trans_id,
|  | const char * | text
| ) |  |

Legacy helper: Generate USSD response including FACILITY IE + L3 header.

This function is just like gsm0480_gen_ussd_resp_7bit, but it generates not only the FACILITY value, but the full L3 message including message header and FACILITY IE Tag+Length.

References gsm0480_gen_ussd_resp_7bit(), GSM0480_IE_FACILITY, GSM0480_MTYPE_RELEASE_COMPLETE, GSM48_PDISC_NC_SS, gsm48_push_l3hdr_tid, and msg.

## gsm0480_decode_ss_request()

int gsm0480_decode_ss_request | ( | const struct gsm48_hdr * | hdr,
|  | uint16_t | len,
|  | struct ss_request * | req
| ) |  |

Check Protocol Discriminator see TS GSM 04.07 and GSM 04.80

References DLGLOBAL, gsm48_hdr_pdisc(), GSM48_PDISC_NC_SS, hdr, len, LOGL_ERROR, LOGP, and parse_ss().

## gsm0480_decode_ussd_request()

int gsm0480_decode_ussd_request | ( | const struct gsm48_hdr * | hdr,
|  | uint16_t | len,
|  | struct ussd_request * | req
| ) |  |

References DLGLOBAL, gsm48_hdr_pdisc(), GSM48_PDISC_NC_SS, hdr, len, LOGL_ERROR, LOGP, and parse_ss().

## gsm0480_extract_ie_by_tag()

int gsm0480_extract_ie_by_tag | ( | const struct gsm48_hdr * | hdr,
|  | uint16_t | msg_len,
|  | uint8_t ** | ie,
|  | uint16_t * | ie_len,
|  | uint8_t | ie_tag
| ) |  |

Get pointer to the IE of a given type.

Parameters

  [in] | hdr | Pointer to the message starting from header
  [in] | msg_len | Length of the whole message + header
  [out] | ie | External pointer to be set
  [out] | ie_len | External IE length variable
  [in] | ie_tag | Tag value of the required IE

Returns
  0 in case of success, otherwise -ERRNO

This function iterates over existing IEs within a given message (depending on its type), and looks for the one with given ie_tag value. If the IE is found, the external pointer pointed by ie will be set to its value part (omitting TL), and ie_len will be set to the length. Otherwise, e.g. in case of parsing error, both ie and ie_len are set to NULL and 0 respectively.

References GSM0480_IE_FACILITY, GSM0480_MTYPE_FACILITY, GSM0480_MTYPE_REGISTER, GSM0480_MTYPE_RELEASE_COMPLETE, gsm48_hdr_msg_type, gsm48_hdr_pdisc(), GSM48_PDISC_NC_SS, hdr, len, and msg_type.

## gsm0480_gen_reject()

struct msgb * gsm0480_gen_reject | ( | int | invoke_id,
|  | uint8_t | problem_tag,
|  | uint8_t | problem_code
| ) |  |

Generate a Reject component (see section 3.6.1) and given error code (see section 3.6.7).

Parameters

  [in] | invoke_id | InvokeID of the request
  [in] | problem_tag | Problem code tag (table 3.13)
  [in] | problem_code | Problem code (table 3.14-3.17)

Returns
  message buffer containing the Reject component

Note: if InvokeID is not available, e.g. when message parsing failed, any incorrect vlue can be passed (0x00 > x > 0xff), so the universal NULL-tag (see table 3.6) will be used instead.

References ASN1_NULL_TYPE_TAG, GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_CTYPE_REJECT, gsm0480_msgb_alloc_name(), len, msg, msgb_tlv1_push(), and msgb_tv_push().

## gsm0480_gen_return_error()

struct msgb * gsm0480_gen_return_error | ( | uint8_t | invoke_id,
|  | uint8_t | error_code
| ) |  |

Generate a ReturnError component (see section 3.6.1) and given error code (see section 3.6.6).

Parameters

  [in] | invoke_id | InvokeID of the request
  [in] | error_code | Error code (section 4.5)

Returns
  message buffer containing the Reject component

References GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_CTYPE_RETURN_ERROR, gsm0480_msgb_alloc_name(), GSM_0480_ERROR_CODE_TAG, len, msg, and msgb_tlv1_push().

## gsm0480_gen_ussd_resp_7bit()

struct msgb * gsm0480_gen_ussd_resp_7bit | ( | uint8_t | invoke_id,
|  | const char * | text
| ) |  |

Generate a USSD ReturnResult component containing a string in default GSM alphabet.

Parameters

  [in] | invoke_id | InvokeID of the request to which we respond
  [in] | text | USSD text in ASCII; to be encoded as GSM 7-but alphabet

References ASN1_OCTET_STRING_TAG, GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_CTYPE_RETURN_RESULT, gsm0480_msgb_alloc_name(), GSM0480_OP_CODE_PROCESS_USS_REQ, GSM0480_OPERATION_CODE, GSM_0480_SEQUENCE_TAG, gsm_7bit_encode_n_ussd(), len, msg, and msgb_tlv1_push().

Referenced by gsm0480_create_ussd_resp().

## gsm0480_msgb_alloc_name()

struct msgb * gsm0480_msgb_alloc_name | ( | const char * | name | ) |

References name.

Referenced by gsm0480_create_notifySS(), gsm0480_create_release_complete(), gsm0480_create_unstructuredSS_Notify(), gsm0480_create_ussd_release_complete(), gsm0480_gen_reject(), gsm0480_gen_return_error(), and gsm0480_gen_ussd_resp_7bit().

## gsm0480_parse_facility_ie()

int gsm0480_parse_facility_ie | ( | const uint8_t * | facility_ie,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

Parse the components of a given Facility IE.

Parameters

  [in] | facility_ie | The Facility IE
  [in] | length | The length of Facility IE
  [out] | req | Abstract representation of SS message

Returns
  0 in case of success, otherwise -ERRNO

The internal functions are using inverted return codes, where '0' means error/failure. While a common approach is to return negative errno in case of any failure, and '0' if all is ok.

References DLGLOBAL, GSM0480_CTYPE_INVOKE, GSM0480_CTYPE_REJECT, GSM0480_CTYPE_RETURN_ERROR, GSM0480_CTYPE_RETURN_RESULT, len, length, LOGL_ERROR, LOGP, parse_ss_invoke(), and parse_ss_return_result().

Referenced by parse_ss_facility(), and parse_ss_info_elements().

## gsm0480_wrap_facility()

int gsm0480_wrap_facility | ( | struct msgb * | msg | ) |

References GSM0480_IE_FACILITY, and msg.

Referenced by gsm0480_create_ussd_notify().

## gsm0480_wrap_invoke()

int gsm0480_wrap_invoke | ( | struct msgb * | msg,
|  | int | op,
|  | int | link_id
| ) |  |

References GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_CTYPE_INVOKE, GSM0480_OPERATION_CODE, link_id, msg, and msgb_tlv1_push().

Referenced by gsm0480_create_ussd_notify().

## parse_process_uss_data()

static int parse_process_uss_data | ( | const uint8_t * | uss_req_data,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

static

References ASN1_IA5_STRING_TAG, DLGLOBAL, GSM0480_USSD_OCTET_STRING_LEN, len, length, LOGL_ERROR, and LOGP.

Referenced by parse_ss_invoke(), and parse_ss_return_result().

## parse_process_uss_req()

static int parse_process_uss_req | ( | const uint8_t * | uss_req_data,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

static

According to GSM 04.08, 4.4.2 "ASN.1 data types": the USSD-DataCodingScheme shall indicate use of the default alphabet using the 0x0F value.

References ASN1_OCTET_STRING_TAG, dcs, DLGLOBAL, GSM0480_USSD_OCTET_STRING_LEN, GSM_0480_SEQUENCE_TAG, gsm_7bit_decode_n_ussd(), len, length, LOGL_ERROR, and LOGP.

Referenced by parse_ss_invoke(), and parse_ss_return_result().

## parse_ss()

static int parse_ss | ( | const struct gsm48_hdr * | hdr,
|  | uint16_t | len,
|  | struct ss_request * | req
| ) |  |

static

GSM 04.80 Section 2.5 'Release complete' Table 2.5 payload is optional for 'RELEASE COMPLETE' message

Indicates that there is no decoded message. To be overwriten by the message otherwise.

References DLGLOBAL, GSM0480_MTYPE_FACILITY, GSM0480_MTYPE_REGISTER, GSM0480_MTYPE_RELEASE_COMPLETE, hdr, len, LOGL_ERROR, LOGP, msg_type, parse_ss_facility(), and parse_ss_info_elements().

Referenced by gsm0480_decode_ss_request(), and gsm0480_decode_ussd_request().

## parse_ss_facility()

static int parse_ss_facility | ( | const uint8_t * | ss_facility,
|  | uint16_t | len,
|  | struct ss_request * | req
| ) |  |

static

References gsm0480_parse_facility_ie(), and len.

Referenced by parse_ss().

## parse_ss_for_bs_req()

static int parse_ss_for_bs_req | ( | const uint8_t * | ss_req_data,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

static

References ASN1_OCTET_STRING_TAG, GSM_0480_SEQUENCE_TAG, len, and length.

Referenced by parse_ss_invoke().

## parse_ss_info_elements()

static int parse_ss_info_elements | ( | const uint8_t * | ss_ie,
|  | uint16_t | len,
|  | struct ss_request * | req
| ) |  |

static

References DLGLOBAL, GSM0480_IE_FACILITY, GSM0480_IE_SS_VERSION, gsm0480_parse_facility_ie(), GSM48_IE_CAUSE, iei, len, LOGL_ERROR, LOGP, and parse_ss_info_elements().

Referenced by parse_ss(), and parse_ss_info_elements().

## parse_ss_invoke()

static int parse_ss_invoke | ( | const uint8_t * | invoke_data,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

static

References DLGLOBAL, GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_COMPIDTAG_LINKED_ID, GSM0480_OP_CODE_ACTIVATE_SS, GSM0480_OP_CODE_DEACTIVATE_SS, GSM0480_OP_CODE_INTERROGATE_SS, GSM0480_OP_CODE_PROCESS_USS_DATA, GSM0480_OP_CODE_PROCESS_USS_REQ, GSM0480_OP_CODE_USS_NOTIFY, GSM0480_OP_CODE_USS_REQUEST, GSM0480_OPERATION_CODE, len, length, LOGL_ERROR, LOGP, parse_process_uss_data(), parse_process_uss_req(), and parse_ss_for_bs_req().

Referenced by gsm0480_parse_facility_ie().

## parse_ss_return_result()

static int parse_ss_return_result | ( | const uint8_t * | rr_data,
|  | uint16_t | length,
|  | struct ss_request * | req
| ) |  |

static

References DLGLOBAL, GSM0480_COMPIDTAG_INVOKE_ID, GSM0480_OP_CODE_PROCESS_USS_DATA, GSM0480_OP_CODE_PROCESS_USS_REQ, GSM0480_OP_CODE_USS_NOTIFY, GSM0480_OP_CODE_USS_REQUEST, GSM_0480_SEQUENCE_TAG, len, length, LOGL_ERROR, LOGP, parse_process_uss_data(), and parse_process_uss_req().

Referenced by gsm0480_parse_facility_ie().

## Variable Documentation

## gsm0480_comp_type_names

const struct value_string gsm0480_comp_type_names[]

Initial value:
= {
{ GSM0480_CTYPE_INVOKE, "Invoke" },
{ GSM0480_CTYPE_RETURN_RESULT, "ReturnResult" },
{ GSM0480_CTYPE_RETURN_ERROR, "ReturnError" },
{ GSM0480_CTYPE_REJECT, "Reject" },
{ 0, NULL }
}
GSM0480_CTYPE_RETURN_RESULT
#define GSM0480_CTYPE_RETURN_RESULT
Definition gsm_04_80.h:17
GSM0480_CTYPE_RETURN_ERROR
#define GSM0480_CTYPE_RETURN_ERROR
Definition gsm_04_80.h:18
GSM0480_CTYPE_REJECT
#define GSM0480_CTYPE_REJECT
Definition gsm_04_80.h:19
GSM0480_CTYPE_INVOKE
#define GSM0480_CTYPE_INVOKE
Definition gsm_04_80.h:16

Referenced by gsm0480_comp_type_name().

## gsm0480_op_code_names

const struct value_string gsm0480_op_code_names[]

Initial value:
= {
{ GSM0480_OP_CODE_REGISTER_SS, "RegisterSS" },
{ GSM0480_OP_CODE_ERASE_SS, "EraseSS" },
{ GSM0480_OP_CODE_ACTIVATE_SS, "ActivateSS" },
{ GSM0480_OP_CODE_DEACTIVATE_SS, "DeactivateSS" },
{ GSM0480_OP_CODE_INTERROGATE_SS, "InterrogateSS" },
{ GSM0480_OP_CODE_NOTIFY_SS, "NotifySS" },
{ GSM0480_OP_CODE_REGISTER_PASSWORD, "RegisterPassword" },
{ GSM0480_OP_CODE_GET_PASSWORD, "GetPassword" },
{ GSM0480_OP_CODE_PROCESS_USS_DATA, "ProcessUSSD" },
{ GSM0480_OP_CODE_FORWARD_CHECK_SS_IND, "ForwardCheckSSind" },
{ GSM0480_OP_CODE_PROCESS_USS_REQ, "ProcessUssReq" },
{ GSM0480_OP_CODE_USS_REQUEST, "UssRequest" },
{ GSM0480_OP_CODE_USS_NOTIFY, "UssNotify" },
{ GSM0480_OP_CODE_FORWARD_CUG_INFO, "ForwardCugInfo" },
{ GSM0480_OP_CODE_SPLIT_MPTY, "SplitMPTY" },
{ GSM0480_OP_CODE_RETRIEVE_MPTY, "RetrieveMPTY" },
{ GSM0480_OP_CODE_HOLD_MPTY, "HoldMPTY" },
{ GSM0480_OP_CODE_BUILD_MPTY, "BuildMPTY" },
{ GSM0480_OP_CODE_FORWARD_CHARGE_ADVICE, "ForwardChargeAdvice" },
{ 0, NULL }
}
GSM0480_OP_CODE_REGISTER_PASSWORD
#define GSM0480_OP_CODE_REGISTER_PASSWORD
Definition gsm_04_80.h:76
GSM0480_OP_CODE_INTERROGATE_SS
#define GSM0480_OP_CODE_INTERROGATE_SS
Definition gsm_04_80.h:74
GSM0480_OP_CODE_DEACTIVATE_SS
#define GSM0480_OP_CODE_DEACTIVATE_SS
Definition gsm_04_80.h:73
GSM0480_OP_CODE_BUILD_MPTY
#define GSM0480_OP_CODE_BUILD_MPTY
Definition gsm_04_80.h:87
GSM0480_OP_CODE_GET_PASSWORD
#define GSM0480_OP_CODE_GET_PASSWORD
Definition gsm_04_80.h:77
GSM0480_OP_CODE_FORWARD_CUG_INFO
#define GSM0480_OP_CODE_FORWARD_CUG_INFO
Definition gsm_04_80.h:83
GSM0480_OP_CODE_REGISTER_SS
#define GSM0480_OP_CODE_REGISTER_SS
Definition gsm_04_80.h:70
GSM0480_OP_CODE_ACTIVATE_SS
#define GSM0480_OP_CODE_ACTIVATE_SS
Definition gsm_04_80.h:72
GSM0480_OP_CODE_RETRIEVE_MPTY
#define GSM0480_OP_CODE_RETRIEVE_MPTY
Definition gsm_04_80.h:85
GSM0480_OP_CODE_FORWARD_CHECK_SS_IND
#define GSM0480_OP_CODE_FORWARD_CHECK_SS_IND
Definition gsm_04_80.h:79
GSM0480_OP_CODE_USS_REQUEST
#define GSM0480_OP_CODE_USS_REQUEST
Definition gsm_04_80.h:81
GSM0480_OP_CODE_FORWARD_CHARGE_ADVICE
#define GSM0480_OP_CODE_FORWARD_CHARGE_ADVICE
Definition gsm_04_80.h:88
GSM0480_OP_CODE_HOLD_MPTY
#define GSM0480_OP_CODE_HOLD_MPTY
Definition gsm_04_80.h:86
GSM0480_OP_CODE_NOTIFY_SS
#define GSM0480_OP_CODE_NOTIFY_SS
Definition gsm_04_80.h:75
GSM0480_OP_CODE_PROCESS_USS_REQ
#define GSM0480_OP_CODE_PROCESS_USS_REQ
Definition gsm_04_80.h:80
GSM0480_OP_CODE_SPLIT_MPTY
#define GSM0480_OP_CODE_SPLIT_MPTY
Definition gsm_04_80.h:84
GSM0480_OP_CODE_PROCESS_USS_DATA
#define GSM0480_OP_CODE_PROCESS_USS_DATA
Definition gsm_04_80.h:78
GSM0480_OP_CODE_ERASE_SS
#define GSM0480_OP_CODE_ERASE_SS
Definition gsm_04_80.h:71
GSM0480_OP_CODE_USS_NOTIFY
#define GSM0480_OP_CODE_USS_NOTIFY
Definition gsm_04_80.h:82

Referenced by gsm0480_op_code_name().