[PATCH] Corrected response to mobile-originated USSD ProcessUnstructuredSS Request - return same op code Signed-off-by: Mike Haben <michael.haben at btinternet.com>

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Mike Haben michael.haben at btinternet.com
Tue Oct 13 16:20:19 UTC 2009


---
 openbsc/src/gsm_04_80.c |   31 +++++++++++++++++++------------
 openbsc/src/ussd.c      |    4 ++--
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/openbsc/src/gsm_04_80.c b/openbsc/src/gsm_04_80.c
index d922ae5..d0dcbc2 100755
--- a/openbsc/src/gsm_04_80.c
+++ b/openbsc/src/gsm_04_80.c
@@ -90,11 +90,11 @@ char* gsm0480_rcv_ussd(struct msgb *msg)
 static int parse_ussd(u_int8_t *ussd)
 {
 	int rc = 1;
-	u_int8_t msg_type = ussd[0] & 0xBF;  // message-type - section 3.4
+	u_int8_t msg_type = ussd[0] & 0xBF;  /* message-type - section 3.4 */
 
 	switch(msg_type) {  
 	case GSM0480_MTYPE_RELEASE_COMPLETE:
-		DEBUGP(DMM, "USS Release Complete\n");  // could also parse out the optional Cause/Facility data
+		DEBUGP(DMM, "USS Release Complete\n");  /* could also parse out the optional Cause/Facility data */
 		ussd_string_buff[0] = 0xFF;
 		break;
 	case GSM0480_MTYPE_REGISTER:
@@ -115,7 +115,7 @@ static int parse_ussd_information_elements(u_int8_t *ussd_ie)
 {
 	int rc;
 
-	u_int8_t iei = ussd_ie[0];  // Information Element Identifier - table 3.2 & GSM 04.08 section 10.5		
+	u_int8_t iei = ussd_ie[0];  /* Information Element Identifier - table 3.2 & GSM 04.08 section 10.5 */		
 	u_int8_t iei_length = ussd_ie[1];  
 	switch(iei) {
 	case GSM48_IE_CAUSE:
@@ -141,7 +141,7 @@ static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length)
 	u_int8_t offset = 0;
 
 	do {
-		u_int8_t component_type = facility_ie[offset]; // Component Type tag - table 3.7 
+		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) {
 		case GSM0480_CTYPE_INVOKE:
@@ -178,7 +178,7 @@ static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length)
 	last_invoke_id = invoke_data[2];
 
 	if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID)  /* optional part */
-		offset += invoke_data[offset+1] + 2;  // skip over it
+		offset += invoke_data[offset+1] + 2;  /* skip over it */
 		
 	if (invoke_data[offset] == GSM0480_OPERATION_CODE) {  /* mandatory part */
 		u_int8_t operation_code = invoke_data[offset+2];
@@ -208,13 +208,11 @@ static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length)
 	int num_chars;
 	u_int8_t dcs;
 
-//	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) {
 			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)) {
 				num_chars = (uss_req_data[6] * 8) / 7;
 				gsm_7bit_decode(ussd_string_buff, &(uss_req_data[7]), num_chars);
@@ -228,6 +226,7 @@ static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length)
 	return rc;
 }
 
+/* Send response to a mobile-originated ProcessUnstructuredSS-Request */
 int gsm0480_send_ussd_response(struct msgb *in_msg, const char* response_text)
 {
 	struct msgb *msg = gsm48_msgb_alloc();
@@ -235,20 +234,28 @@ int gsm0480_send_ussd_response(struct msgb *in_msg, const char* response_text)
 	u_int8_t *ptr8;
 	int response_len;
 
-	response_len = strlen(response_text);
+	response_len = (strlen(response_text) * 7) / 8;
+	if (((strlen(response_text) * 7) % 8) != 0)
+		response_len += 1;
 
 	msg->bts_link = in_msg->bts_link;
 	msg->lchan = in_msg->lchan;
 
 	/* First put the payload text into the message */
 	ptr8 = msgb_put(msg, response_len);
-	memcpy(ptr8, response_text, response_len);
+	gsm_7bit_encode(ptr8, response_text);
 
-	/* Then wrap it as an IA5 String */
-	msgb_wrap_with_TL(msg, ASN1_IA5_STRING_TAG);
+	/* Then wrap it as an Octet String */
+	msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG);
+
+	/* Pre-pend the DCS octet string */
+	msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F);
+
+	/* Then wrap these as a Sequence */
+	msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG);
 
 	/* Pre-pend the operation code */
-	msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, GSM0480_OP_CODE_PROCESS_USS_DATA);
+	msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, GSM0480_OP_CODE_PROCESS_USS_REQ);
 
 	/* Wrap the operation code and IA5 string as a sequence */
 	msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG);
diff --git a/openbsc/src/ussd.c b/openbsc/src/ussd.c
index ba2f045..5f9a457 100755
--- a/openbsc/src/ussd.c
+++ b/openbsc/src/ussd.c
@@ -45,7 +45,7 @@ int handle_rcv_ussd(struct msgb *msg)
 {
 	char* ussd_text_rcvd = gsm0480_rcv_ussd(msg);
 
-	if(ussd_text_rcvd[0] == 0xFF)  // Release-Complete
+	if(ussd_text_rcvd[0] == 0xFF)  /* Release-Complete */
 	    return 0;
 
 	if(strstr(USSD_TEXT_OWN_NUMBER, ussd_text_rcvd) != NULL) {
@@ -60,7 +60,7 @@ int handle_rcv_ussd(struct msgb *msg)
 /* A network-specific handler function */
 static int send_own_number(struct msgb *msg)
 {
-	char response_string[] = "Your extension is xxxxx";
+	char response_string[] = "Your extension is xxxxx\r"; /* Need trailing CR as EOT character */
 
 	char* own_number = msg->lchan->subscr->extension;
 	memcpy(response_string + 18, own_number, 5);
-- 
1.6.0.4


--------------050801040303060009020404--




More information about the OpenBSC mailing list