---
openbsc/include/openbsc/gsm_04_80.h | 129 +++++++++++++++++--
openbsc/include/openbsc/ussd.h | 2 +
openbsc/src/gsm_04_80.c | 246 ++++++++++------------------------
openbsc/src/ussd.c | 16 ++-
4 files changed, 201 insertions(+), 192 deletions(-)
diff --git a/openbsc/include/openbsc/gsm_04_80.h b/openbsc/include/openbsc/gsm_04_80.h
index 43b5b74..11962d8 100755
--- a/openbsc/include/openbsc/gsm_04_80.h
+++ b/openbsc/include/openbsc/gsm_04_80.h
@@ -1,24 +1,129 @@
#ifndef _GSM_04_80_H
#define _GSM_04_80_H
-#include <openbsc/msgb.h>
+/* GSM TS 04.80 definitions (Supplementary Services Specification, Formats and Coding)
*/
+
+/* Section 3.4 */
+#define GSM0480_MTYPE_RELEASE_COMPLETE 0x2A
+#define GSM0480_MTYPE_FACILITY 0x3A
+#define GSM0480_MTYPE_REGISTER 0x3B
+
+/* Section 3.5 */
+#define GSM0480_IE_FACILITY 0x1C
+#define GSM0480_IE_SS_VERSION 0x7F
+
+/* Section 3.6.2 */
+#define GSM0480_CTYPE_INVOKE 0xA1
+#define GSM0480_CTYPE_RETURN_RESULT 0xA2
+#define GSM0480_CTYPE_RETURN_ERROR 0xA3
+#define GSM0480_CTYPE_REJECT 0xA4
+
+/* Section 3.6.3 */
+#define GSM0480_COMPIDTAG_INVOKE_ID 0x02
+#define GSM0480_COMPIDTAG_LINKED_ID 0x80
+
+/* Section 3.6.4 */
+#define GSM0480_OPERATION_CODE 0x02
-/* GSM TS 04.80 definitions (Supplementary Services specification, Formats and coding
*/
/* Section 3.6.5 */
#define GSM_0480_SEQUENCE_TAG 0x30
#define GSM_0480_SET_TAG 0x31
+/* Section 3.6.6 */
+#define GSM_0480_ERROR_CODE_TAG 0x02
+
+/* Section 3.6.7 */
+/* Table 3.13 */
+#define GSM_0480_PROBLEM_CODE_TAG_GENERAL 0x80
+#define GSM_0480_PROBLEM_CODE_TAG_INVOKE 0x81
+#define GSM_0480_PROBLEM_CODE_TAG_RETURN_RESULT 0x82
+#define GSM_0480_PROBLEM_CODE_TAG_RETURN_ERROR 0x83
+
+/* Table 3.14 */
+#define GSM_0480_GEN_PROB_CODE_UNRECOGNISED 0x00
+#define GSM_0480_GEN_PROB_CODE_MISTYPED 0x01
+#define GSM_0480_GEN_PROB_CODE_BAD_STRUCTURE 0x02
+
+/* Table 3.15 */
+#define GSM_0480_INVOKE_PROB_CODE_DUPLICATE_INVOKE_ID 0x00
+#define GSM_0480_INVOKE_PROB_CODE_UNRECOGNISED_OPERATION 0x01
+#define GSM_0480_INVOKE_PROB_CODE_MISTYPED_PARAMETER 0x02
+#define GSM_0480_INVOKE_PROB_CODE_RESOURCE_LIMITATION 0x03
+#define GSM_0480_INVOKE_PROB_CODE_INITIATING_RELEASE 0x04
+#define GSM_0480_INVOKE_PROB_CODE_UNRECOGNISED_LINKED_ID 0x05
+#define GSM_0480_INVOKE_PROB_CODE_UNEXPECTED_LINKED_RESPONSE 0x06
+#define GSM_0480_INVOKE_PROB_CODE_UNEXPECTED_LINKED_OPERATION 0x07
+
+/* Table 3.16 */
+#define GSM_0480_RESULT_PROB_CODE_UNRECOGNISED_INVOKE_ID 0x00
+#define GSM_0480_RESULT_PROB_CODE_RETURN_RESULT_UNEXPECTED 0x01
+#define GSM_0480_RESULT_PROB_CODE_MISTYPED_PARAMETER 0x02
+
+/* Table 3.17 */
+#define GSM_0480_ERROR_PROB_CODE_UNRECOGNISED_INVOKE_ID 0x00
+#define GSM_0480_ERROR_PROB_CODE_RETURN_ERROR_UNEXPECTED 0x01
+#define GSM_0480_ERROR_PROB_CODE_UNRECOGNISED_ERROR 0x02
+#define GSM_0480_ERROR_PROB_CODE_UNEXPECTED_ERROR 0x03
+#define GSM_0480_ERROR_PROB_CODE_MISTYPED_PARAMETER 0x04
+
+/* Section 4.5 */
+#define GSM0480_OP_CODE_REGISTER_SS 0x0A
+#define GSM0480_OP_CODE_ERASE_SS 0x0B
+#define GSM0480_OP_CODE_ACTIVATE_SS 0x0C
+#define GSM0480_OP_CODE_DEACTIVATE_SS 0x0D
+#define GSM0480_OP_CODE_INTERROGATE_SS 0x0E
+#define GSM0480_OP_CODE_NOTIFY_SS 0x10
+#define GSM0480_OP_CODE_REGISTER_PASSWORD 0x11
+#define GSM0480_OP_CODE_GET_PASSWORD 0x12
+#define GSM0480_OP_CODE_PROCESS_USS_DATA 0x13
+#define GSM0480_OP_CODE_FORWARD_CHECK_SS_IND 0x26
+#define GSM0480_OP_CODE_PROCESS_USS_REQ 0x3B
+#define GSM0480_OP_CODE_USS_REQUEST 0x3C
+#define GSM0480_OP_CODE_USS_NOTIFY 0x3D
+#define GSM0480_OP_CODE_FORWARD_CUG_INFO 0x78
+#define GSM0480_OP_CODE_SPLIT_MPTY 0x79
+#define GSM0480_OP_CODE_RETRIEVE_MPTY 0x7A
+#define GSM0480_OP_CODE_HOLD_MPTY 0x7B
+#define GSM0480_OP_CODE_BUILD_MPTY 0x7C
+#define GSM0480_OP_CODE_FORWARD_CHARGE_ADVICE 0x7D
+
+#define GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER 0x01
+#define GSM0480_ERR_CODE_ILLEGAL_SUBSCRIBER 0x09
+#define GSM0480_ERR_CODE_BEARER_SERVICE_NOT_PROVISIONED 0x0A
+#define GSM0480_ERR_CODE_TELESERVICE_NOT_PROVISIONED 0x0B
+#define GSM0480_ERR_CODE_ILLEGAL_EQUIPMENT 0x0C
+#define GSM0480_ERR_CODE_CALL_BARRED 0x0D
+#define GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION 0x10
+#define GSM0480_ERR_CODE_SS_ERROR_STATUS 0x11
+#define GSM0480_ERR_CODE_SS_NOT_AVAILABLE 0x12
+#define GSM0480_ERR_CODE_SS_SUBSCRIPTION_VIOLATION 0x13
+#define GSM0480_ERR_CODE_SS_INCOMPATIBILITY 0x14
+#define GSM0480_ERR_CODE_FACILITY_NOT_SUPPORTED 0x15
+#define GSM0480_ERR_CODE_ABSENT_SUBSCRIBER 0x1B
+#define GSM0480_ERR_CODE_SYSTEM_FAILURE 0x22
+#define GSM0480_ERR_CODE_DATA_MISSING 0x23
+#define GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE 0x24
+#define GSM0480_ERR_CODE_PW_REGISTRATION_FAILURE 0x25
+#define GSM0480_ERR_CODE_NEGATIVE_PW_CHECK 0x26
+#define GSM0480_ERR_CODE_NUM_PW_ATTEMPTS_VIOLATION 0x2B
+#define GSM0480_ERR_CODE_UNKNOWN_ALPHABET 0x47
+#define GSM0480_ERR_CODE_USSD_BUSY 0x48
+#define GSM0480_ERR_CODE_MAX_MPTY_PARTICIPANTS 0x7E
+#define GSM0480_ERR_CODE_RESOURCES_NOT_AVAILABLE 0x7F
+
/* ASN.1 type-tags */
-#define ASN1_BOOLEAN_TAG 0x01
-#define ASN1_INTEGER_TAG 0x02
-#define ASN1_BIT_STRING_TAG 0x03
-#define ASN1_OCTET_STRING_TAG 0x04
-#define ASN1_NULL_TYPE_TAG 0x05
-#define ASN1_OBJECT_ID_TAG 0x06
-#define ASN1_UTF8_STRING_TAG 0x0C
-#define ASN1_PRINTABLE_STRING_TAG 0x13
-#define ASN1_IA5_STRING_TAG 0x16
-#define ASN1_UNICODE_STRING_TAG 0x1E
+#define ASN1_BOOLEAN_TAG 0x01
+#define ASN1_INTEGER_TAG 0x02
+#define ASN1_BIT_STRING_TAG 0x03
+#define ASN1_OCTET_STRING_TAG 0x04
+#define ASN1_NULL_TYPE_TAG 0x05
+#define ASN1_OBJECT_ID_TAG 0x06
+#define ASN1_UTF8_STRING_TAG 0x0C
+#define ASN1_PRINTABLE_STRING_TAG 0x13
+#define ASN1_IA5_STRING_TAG 0x16
+#define ASN1_UNICODE_STRING_TAG 0x1E
+
+#include <openbsc/msgb.h>
char* gsm0480_rcv_ussd(struct msgb *msg);
int gsm0480_send_ussd_response(struct msgb *msg, const char* response_text);
diff --git a/openbsc/include/openbsc/ussd.h b/openbsc/include/openbsc/ussd.h
index dfd34f3..e7bd6d6 100755
--- a/openbsc/include/openbsc/ussd.h
+++ b/openbsc/include/openbsc/ussd.h
@@ -1,6 +1,8 @@
#ifndef _USSD_H
#define _USSD_H
+/* Handler function for mobile-originated USSD messages */
+
#include <openbsc/msgb.h>
int handle_rcv_ussd(struct msgb *msg);
diff --git a/openbsc/src/gsm_04_80.c b/openbsc/src/gsm_04_80.c
index a6dffa8..d922ae5 100755
--- a/openbsc/src/gsm_04_80.c
+++ b/openbsc/src/gsm_04_80.c
@@ -3,6 +3,7 @@
/* (C) 2008-2009 by Harald Welte <laforge(a)gnumonks.org>
* (C) 2008, 2009 by Holger Hans Peter Freyther <zecke(a)selfish.org>
+ * (C) 2009 by Mike Haben <michael.haben(a)btinternet.com>
*
* All Rights Reserved
*
@@ -36,112 +37,6 @@
#include <openbsc/gsm_04_08.h>
#include <openbsc/gsm_04_80.h>
-/* GSM TS 04.80 definitions (Supplementary Services specification, Formats and coding
*/
-
-/* Section 3.4 */
-#define GSM0480_MTYPE_RELEASE_COMPLETE 0x2A
-#define GSM0480_MTYPE_FACILITY 0x3A
-#define GSM0480_MTYPE_REGISTER 0x3B
-
-/* Section 3.5 */
-#define GSM0480_IE_FACILITY 0x1C
-#define GSM0480_IE_SS_VERSION 0x7F
-
-/* Section 3.6.2 */
-#define GSM0480_CTYPE_INVOKE 0xA1
-#define GSM0480_CTYPE_RETURN_RESULT 0xA2
-#define GSM0480_CTYPE_RETURN_ERROR 0xA3
-#define GSM0480_CTYPE_REJECT 0xA4
-
-/* Section 3.6.3 */
-#define GSM0480_COMPIDTAG_INVOKE_ID 0x02
-#define GSM0480_COMPIDTAG_LINKED_ID 0x80
-
-/* Section 3.6.4 */
-#define GSM0480_OPERATION_CODE 0x02
-
-/* Section 3.6.6 */
-#define GSM_0480_ERROR_CODE_TAG 0x02
-
-/* Section 3.6.7 */
-/* Table 3.13 */
-#define GSM_0480_PROBLEM_CODE_TAG_GENERAL 0x80
-#define GSM_0480_PROBLEM_CODE_TAG_INVOKE 0x81
-#define GSM_0480_PROBLEM_CODE_TAG_RETURN_RESULT 0x82
-#define GSM_0480_PROBLEM_CODE_TAG_RETURN_ERROR 0x83
-
-/* Table 3.14 */
-#define GSM_0480_GEN_PROB_CODE_UNRECOGNISED 0x00
-#define GSM_0480_GEN_PROB_CODE_MISTYPED 0x01
-#define GSM_0480_GEN_PROB_CODE_BAD_STRUCTURE 0x02
-
-/* Table 3.15 */
-#define GSM_0480_INVOKE_PROB_CODE_DUPLICATE_INVOKE_ID 0x00
-#define GSM_0480_INVOKE_PROB_CODE_UNRECOGNISED_OPERATION 0x01
-#define GSM_0480_INVOKE_PROB_CODE_MISTYPED_PARAMETER 0x02
-#define GSM_0480_INVOKE_PROB_CODE_RESOURCE_LIMITATION 0x03
-#define GSM_0480_INVOKE_PROB_CODE_INITIATING_RELEASE 0x04
-#define GSM_0480_INVOKE_PROB_CODE_UNRECOGNISED_LINKED_ID 0x05
-#define GSM_0480_INVOKE_PROB_CODE_UNEXPECTED_LINKED_RESPONSE 0x06
-#define GSM_0480_INVOKE_PROB_CODE_UNEXPECTED_LINKED_OPERATION 0x07
-
-/* Table 3.16 */
-#define GSM_0480_RESULT_PROB_CODE_UNRECOGNISED_INVOKE_ID 0x00
-#define GSM_0480_RESULT_PROB_CODE_RETURN_RESULT_UNEXPECTED 0x01
-#define GSM_0480_RESULT_PROB_CODE_MISTYPED_PARAMETER 0x02
-
-/* Table 3.17 */
-#define GSM_0480_ERROR_PROB_CODE_UNRECOGNISED_INVOKE_ID 0x00
-#define GSM_0480_ERROR_PROB_CODE_RETURN_ERROR_UNEXPECTED 0x01
-#define GSM_0480_ERROR_PROB_CODE_UNRECOGNISED_ERROR 0x02
-#define GSM_0480_ERROR_PROB_CODE_UNEXPECTED_ERROR 0x03
-#define GSM_0480_ERROR_PROB_CODE_MISTYPED_PARAMETER 0x04
-
-/* Section 4.5 */
-#define GSM0480_OP_CODE_REGISTER_SS 0x0A
-#define GSM0480_OP_CODE_ERASE_SS 0x0B
-#define GSM0480_OP_CODE_ACTIVATE_SS 0x0C
-#define GSM0480_OP_CODE_DEACTIVATE_SS 0x0D
-#define GSM0480_OP_CODE_INTERROGATE_SS 0x0E
-#define GSM0480_OP_CODE_NOTIFY_SS 0x10
-#define GSM0480_OP_CODE_REGISTER_PASSWORD 0x11
-#define GSM0480_OP_CODE_GET_PASSWORD 0x12
-#define GSM0480_OP_CODE_PROCESS_USS_DATA 0x13
-#define GSM0480_OP_CODE_FORWARD_CHECK_SS_IND 0x26
-#define GSM0480_OP_CODE_PROCESS_USS_REQ 0x3B
-#define GSM0480_OP_CODE_USS_REQUEST 0x3C
-#define GSM0480_OP_CODE_USS_NOTIFY 0x3D
-#define GSM0480_OP_CODE_FORWARD_CUG_INFO 0x78
-#define GSM0480_OP_CODE_SPLIT_MPTY 0x79
-#define GSM0480_OP_CODE_RETRIEVE_MPTY 0x7A
-#define GSM0480_OP_CODE_HOLD_MPTY 0x7B
-#define GSM0480_OP_CODE_BUILD_MPTY 0x7C
-#define GSM0480_OP_CODE_FORWARD_CHARGE_ADVICE 0x7D
-
-#define GSM0480_ERR_CODE_UNKNOWN_SUBSCRIBER 0x01
-#define GSM0480_ERR_CODE_ILLEGAL_SUBSCRIBER 0x09
-#define GSM0480_ERR_CODE_BEARER_SERVICE_NOT_PROVISIONED 0x0A
-#define GSM0480_ERR_CODE_TELESERVICE_NOT_PROVISIONED 0x0B
-#define GSM0480_ERR_CODE_ILLEGAL_EQUIPMENT 0x0C
-#define GSM0480_ERR_CODE_CALL_BARRED 0x0D
-#define GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION 0x10
-#define GSM0480_ERR_CODE_SS_ERROR_STATUS 0x11
-#define GSM0480_ERR_CODE_SS_NOT_AVAILABLE 0x12
-#define GSM0480_ERR_CODE_SS_SUBSCRIPTION_VIOLATION 0x13
-#define GSM0480_ERR_CODE_SS_INCOMPATIBILITY 0x14
-#define GSM0480_ERR_CODE_FACILITY_NOT_SUPPORTED 0x15
-#define GSM0480_ERR_CODE_ABSENT_SUBSCRIBER 0x1B
-#define GSM0480_ERR_CODE_SYSTEM_FAILURE 0x22
-#define GSM0480_ERR_CODE_DATA_MISSING 0x23
-#define GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE 0x24
-#define GSM0480_ERR_CODE_PW_REGISTRATION_FAILURE 0x25
-#define GSM0480_ERR_CODE_NEGATIVE_PW_CHECK 0x26
-#define GSM0480_ERR_CODE_NUM_PW_ATTEMPTS_VIOLATION 0x2B
-#define GSM0480_ERR_CODE_UNKNOWN_ALPHABET 0x47
-#define GSM0480_ERR_CODE_USSD_BUSY 0x48
-#define GSM0480_ERR_CODE_MAX_MPTY_PARTICIPANTS 0x7E
-#define GSM0480_ERR_CODE_RESOURCES_NOT_AVAILABLE 0x7F
-
static char ussd_string_buff[32];
static u_int8_t last_transaction_id;
static u_int8_t last_invoke_id;
@@ -153,23 +48,40 @@ static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t
length);
static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length);
static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length);
+static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag)
+{
+ msgb->data -= 2;
+ msgb->data[0] = tag;
+ msgb->data[1] = msgb->len;
+ msgb->len += 2;
+ return msgb->data;
+}
+
+static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag, u_int8_t
value)
+{
+ msgb->data -= 3;
+ msgb->len += 3;
+ msgb->data[0] = tag;
+ msgb->data[1] = 1;
+ msgb->data[2] = value;
+ return msgb->data;
+}
+
+
/* Receive a mobile-originated USSD message and return the decoded text */
char* gsm0480_rcv_ussd(struct msgb *msg)
{
int rc = 0;
u_int8_t* parse_ptr = msgb_l3(msg);
-// DEBUGP(DMM, "USSD %s\n", hexdump(msg->data, msg->len)); // temporary,
just see what we're receiving...
-
memset(ussd_string_buff, 0, sizeof(ussd_string_buff));
- if((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS)
- {
- last_transaction_id = *parse_ptr & 0xF0;
+ if ((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS) {
+ last_transaction_id = *parse_ptr & 0x70;
rc = parse_ussd(parse_ptr + 1);
}
- if(!rc)
+ if (!rc)
DEBUGP(DMM, "Error occurred while parsing received USSD!\n");
return ussd_string_buff;
@@ -228,8 +140,7 @@ static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length)
int rc = 1;
u_int8_t offset = 0;
- do
- {
+ do {
u_int8_t component_type = facility_ie[offset]; // Component Type tag - table 3.7
u_int8_t component_length = facility_ie[offset+1];
switch(component_type) {
@@ -248,10 +159,8 @@ static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length)
rc = 0;
break;
}
-
offset += (component_length+2);
- }
- while(offset < length);
+ } while(offset < length);
return rc;
}
@@ -261,19 +170,17 @@ static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length)
{
int rc = 1;
- if(invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) // mandatory part
- {
+ if (invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) { /* mandatory part */
fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x (expecting Invoke ID
tag)\n",
invoke_data[0]);
}
u_int8_t offset = invoke_data[1] + 2;
last_invoke_id = invoke_data[2];
- if(invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID) // optional part
+ if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID) /* optional part */
offset += invoke_data[offset+1] + 2; // skip over it
- if(invoke_data[offset] == GSM0480_OPERATION_CODE) // mandatory part
- {
+ if (invoke_data[offset] == GSM0480_OPERATION_CODE) { /* mandatory part */
u_int8_t operation_code = invoke_data[offset+2];
switch(operation_code) {
case GSM0480_OP_CODE_PROCESS_USS_REQ:
@@ -285,11 +192,9 @@ static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length)
rc = 0;
break;
}
- }
- else
- {
+ } else {
fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x (expecting Operation
Code tag)\n",
- invoke_data[0]);
+ invoke_data[0]);
rc = 0;
}
@@ -306,21 +211,16 @@ static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t
length)
// DEBUGP(DMM, "USSD request params %s\n", hexdump(uss_req_data, length));
/* FIXME: most phones send USSD text as a 7-bit encoded octet string; the following
code
also handles the case of plain ASCII text (IA5String), but other encodings might be used
*/
- if(uss_req_data[0] == GSM_0480_SEQUENCE_TAG)
- {
- if(uss_req_data[2] == ASN1_OCTET_STRING_TAG)
- {
+ if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
+ if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
dcs = uss_req_data[4];
// DEBUGP(DMM, "Data coding scheme = 0x%2.2X\n", dcs);
- if((dcs == 0x0F) && (uss_req_data[5] == ASN1_OCTET_STRING_TAG))
- {
+ if ((dcs == 0x0F) && (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
num_chars = (uss_req_data[6] * 8) / 7;
gsm_7bit_decode(ussd_string_buff, &(uss_req_data[7]), num_chars);
}
}
- }
- else if(uss_req_data[0] == ASN1_IA5_STRING_TAG)
- {
+ } else if (uss_req_data[0] == ASN1_IA5_STRING_TAG) {
num_chars = uss_req_data[1];
memcpy(ussd_string_buff, &(uss_req_data[2]), num_chars);
}
@@ -340,30 +240,32 @@ int gsm0480_send_ussd_response(struct msgb *in_msg, const char*
response_text)
msg->bts_link = in_msg->bts_link;
msg->lchan = in_msg->lchan;
- gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
- gh->proto_discr = GSM48_PDISC_NC_SS | last_transaction_id | 0x80; // TI direction =
1
- gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
-
- ptr8 = msgb_put(msg, 14);
- ptr8[0] = GSM0480_IE_FACILITY;
- ptr8[1] = response_len + 12;
- ptr8[2] = GSM0480_CTYPE_RETURN_RESULT;
- ptr8[3] = response_len + 10;
- ptr8[4] = GSM0480_COMPIDTAG_INVOKE_ID;
- ptr8[5] = 1;
- ptr8[6] = last_invoke_id;
- ptr8[7] = GSM_0480_SEQUENCE_TAG;
- ptr8[8] = response_len + 5;
- ptr8[9] = GSM0480_OPERATION_CODE;
- ptr8[10] = 1;
- ptr8[11] = GSM0480_OP_CODE_PROCESS_USS_DATA;
- ptr8[12] = ASN1_IA5_STRING_TAG;
- ptr8[13] = response_len;
-
+ /* First put the payload text into the message */
ptr8 = msgb_put(msg, response_len);
memcpy(ptr8, response_text, response_len);
-// DEBUGP(DMM, "USSD response %s\n", hexdump(msg->data, msg->len)); //
temporary, just to see what we're sending back
+ /* Then wrap it as an IA5 String */
+ msgb_wrap_with_TL(msg, ASN1_IA5_STRING_TAG);
+
+ /* Pre-pend the operation code */
+ msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, GSM0480_OP_CODE_PROCESS_USS_DATA);
+
+ /* Wrap the operation code and IA5 string as a sequence */
+ msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG);
+
+ /* Pre-pend the invoke ID */
+ msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, last_invoke_id);
+
+ /* Wrap this up as a Return Result component */
+ msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT);
+
+ /* Wrap the component in a Facility message */
+ msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
+
+ /* And finally pre-pend the L3 header */
+ gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
+ gh->proto_discr = GSM48_PDISC_NC_SS | last_transaction_id | (1<<7); /* TI
direction = 1 */
+ gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
return gsm48_sendmsg(msg, NULL);
}
@@ -372,28 +274,26 @@ int gsm0480_send_ussd_reject(struct msgb *in_msg)
{
struct msgb *msg = gsm48_msgb_alloc();
struct gsm48_hdr *gh;
- u_int8_t *ptr8;
msg->bts_link = in_msg->bts_link;
msg->lchan = in_msg->lchan;
- gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
- gh->proto_discr = GSM48_PDISC_NC_SS | last_transaction_id | 0x80; // TI direction =
1
- gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
+ /* First insert the problem code */
+ msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL,
GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
+
+ /* Before it insert the invoke ID */
+ msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, last_invoke_id);
- ptr8 = msgb_put(msg, 10);
- ptr8[0] = GSM0480_IE_FACILITY;
- ptr8[1] = 8;
- ptr8[2] = GSM0480_CTYPE_REJECT;
- ptr8[3] = 6;
- ptr8[4] = GSM0480_COMPIDTAG_INVOKE_ID;
- ptr8[5] = 1;
- ptr8[6] = last_invoke_id;
- ptr8[7] = GSM_0480_PROBLEM_CODE_TAG_GENERAL;
- ptr8[8] = 1;
- ptr8[9] = GSM_0480_GEN_PROB_CODE_UNRECOGNISED;
-
-// DEBUGP(DMM, "USSD reject %s\n", hexdump(msg->data, msg->len)); //
temporary, just to see what we're sending back
+ /* Wrap this up as a Reject component */
+ msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT);
+
+ /* Wrap the component in a Facility message */
+ msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
+
+ /* And finally pre-pend the L3 header */
+ gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
+ gh->proto_discr = GSM48_PDISC_NC_SS | last_transaction_id | (1<<7); /* TI
direction = 1 */
+ gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
return gsm48_sendmsg(msg, NULL);
}
diff --git a/openbsc/src/ussd.c b/openbsc/src/ussd.c
index 761a0e7..ba2f045 100755
--- a/openbsc/src/ussd.c
+++ b/openbsc/src/ussd.c
@@ -2,6 +2,7 @@
/* (C) 2008-2009 by Harald Welte <laforge(a)gnumonks.org>
* (C) 2008, 2009 by Holger Hans Peter Freyther <zecke(a)selfish.org>
+ * (C) 2009 by Mike Haben <michael.haben(a)btinternet.com>
*
* All Rights Reserved
*
@@ -21,6 +22,7 @@
*
*/
+/* This module defines the network-specific handling of mobile-originated USSD messages.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -31,10 +33,14 @@
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>
+/* Declarations of USSD strings to be recognised */
const char USSD_TEXT_OWN_NUMBER[] = "*#100#";
+/* Forward declarations of network-specific handler functions */
static int send_own_number(struct msgb *msg);
+
+/* Entrypoint - handler function common to all mobile-originated USSDs */
int handle_rcv_ussd(struct msgb *msg)
{
char* ussd_text_rcvd = gsm0480_rcv_ussd(msg);
@@ -42,20 +48,16 @@ int handle_rcv_ussd(struct msgb *msg)
if(ussd_text_rcvd[0] == 0xFF) // Release-Complete
return 0;
- DEBUGP(DMM, "Received USSD text %s\n", ussd_text_rcvd); // show text payload
entered on MS
-
- if(strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL)
- {
+ if(strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL) {
DEBUGP(DMM, "USSD: Own number requested\n");
return send_own_number(msg);
- }
- else
- {
+ } else {
DEBUGP(DMM, "Unhandled USSD %s\n", ussd_text_rcvd);
return gsm0480_send_ussd_reject(msg);
}
}
+/* A network-specific handler function */
static int send_own_number(struct msgb *msg)
{
char response_string[] = "Your extension is xxxxx";
--
1.6.0.4
--------------090900090905050500050904--