aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-10-18 09:53:04 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-10-18 09:54:33 +0200
commit4cc21eaa42bd90928d0b5c1d3f52713a17abdff3 (patch)
tree11da1f5ac1e5845b54460cbce6e81270915737a3 /openbsc
parente9f8a258a862adfa17aa9882e46c54b1738f4ad9 (diff)
ussd: Move the code libosmocore, increase the version number.
Move the code to libosmocore, update the header file and the version required in the configure.in. Conflicts: openbsc/configure.in openbsc/include/openbsc/gsm_04_80.h openbsc/src/gsm_04_80.c
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/configure.in2
-rw-r--r--openbsc/include/openbsc/gsm_04_80.h11
-rw-r--r--openbsc/src/gsm_04_80.c186
3 files changed, 2 insertions, 197 deletions
diff --git a/openbsc/configure.in b/openbsc/configure.in
index 633a021d8..e32c4080f 100644
--- a/openbsc/configure.in
+++ b/openbsc/configure.in
@@ -15,7 +15,7 @@ dnl checks for libraries
AC_SEARCH_LIBS(crypt, crypt,
[LIBCRYPT="-lcrypt"; AC_DEFINE([VTY_CRYPT_PW], [], [Use crypt functionality of vty.])])
-PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.22)
+PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.23)
PKG_CHECK_MODULES(LIBOSMOSCCP, libosmo-sccp >= 0.0.3)
dnl checks for header files
diff --git a/openbsc/include/openbsc/gsm_04_80.h b/openbsc/include/openbsc/gsm_04_80.h
index 83f327526..071a6abf0 100644
--- a/openbsc/include/openbsc/gsm_04_80.h
+++ b/openbsc/include/openbsc/gsm_04_80.h
@@ -3,17 +3,8 @@
#include <osmocore/msgb.h>
#include <osmocore/protocol/gsm_04_80.h>
+#include <osmocore/gsm0480.h>
-#define MAX_LEN_USSD_STRING 31
-
-struct ussd_request {
- char text[MAX_LEN_USSD_STRING + 1];
- u_int8_t transaction_id;
- u_int8_t invoke_id;
-};
-
-int gsm0480_decode_ussd_request(const struct msgb *msg,
- struct ussd_request *request);
int gsm0480_send_ussd_response(const struct msgb *in_msg, const char* response_text,
const struct ussd_request *req);
int gsm0480_send_ussd_reject(const struct msgb *msg,
diff --git a/openbsc/src/gsm_04_80.c b/openbsc/src/gsm_04_80.c
index 39c1f95f3..6a75c0930 100644
--- a/openbsc/src/gsm_04_80.c
+++ b/openbsc/src/gsm_04_80.c
@@ -38,17 +38,6 @@
#include <openbsc/gsm_04_80.h>
#include <osmocore/gsm0480.h>
-/* Forward declarations */
-static int parse_ussd(u_int8_t *ussd, struct ussd_request *req);
-static int parse_ussd_info_elements(u_int8_t *ussd_ie,
- struct ussd_request *req);
-static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length,
- struct ussd_request *req);
-static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length,
- struct ussd_request *req);
-static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length,
- struct ussd_request *req);
-
static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag)
{
uint8_t *data = msgb_push(msgb, 2);
@@ -70,181 +59,6 @@ static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag,
}
-/* Decode a mobile-originated USSD-request message */
-int gsm0480_decode_ussd_request(const struct msgb *msg, struct ussd_request *req)
-{
- int rc = 0;
- u_int8_t *parse_ptr = msgb_l3(msg);
-
- if ((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS) {
- req->transaction_id = *parse_ptr & 0x70;
- rc = parse_ussd(parse_ptr+1, req);
- }
-
- if (!rc)
- DEBUGP(DMM, "Error occurred while parsing received USSD!\n");
-
- return rc;
-}
-
-static int parse_ussd(u_int8_t *ussd, struct ussd_request *req)
-{
- int rc = 1;
- 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 */
- req->text[0] = 0xFF;
- break;
- case GSM0480_MTYPE_REGISTER:
- case GSM0480_MTYPE_FACILITY:
- rc &= parse_ussd_info_elements(ussd+1, req);
- break;
- default:
- fprintf(stderr, "Unknown GSM 04.80 message-type field 0x%02x\n",
- ussd[0]);
- rc = 0;
- break;
- }
-
- return rc;
-}
-
-static int parse_ussd_info_elements(u_int8_t *ussd_ie, struct ussd_request *req)
-{
- int rc;
- /* Information Element Identifier - table 3.2 & GSM 04.08 section 10.5 */
- u_int8_t iei = ussd_ie[0];
- u_int8_t iei_length = ussd_ie[1];
-
- switch (iei) {
- case GSM48_IE_CAUSE:
- break;
- case GSM0480_IE_FACILITY:
- rc = parse_facility_ie(ussd_ie+2, iei_length, req);
- break;
- case GSM0480_IE_SS_VERSION:
- break;
- default:
- fprintf(stderr, "Unhandled GSM 04.08 or 04.80 IEI 0x%02x\n",
- iei);
- rc = 0;
- break;
- }
-
- return rc;
-}
-
-static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length,
- struct ussd_request *req)
-{
- int rc = 1;
- u_int8_t offset = 0;
-
- do {
- /* Component Type tag - table 3.7 */
- u_int8_t component_type = facility_ie[offset];
- u_int8_t component_length = facility_ie[offset+1];
-
- switch (component_type) {
- case GSM0480_CTYPE_INVOKE:
- rc &= parse_ss_invoke(facility_ie+2,
- component_length,
- req);
- break;
- case GSM0480_CTYPE_RETURN_RESULT:
- break;
- case GSM0480_CTYPE_RETURN_ERROR:
- break;
- case GSM0480_CTYPE_REJECT:
- break;
- default:
- fprintf(stderr, "Unknown GSM 04.80 Facility "
- "Component Type 0x%02x\n", component_type);
- rc = 0;
- break;
- }
- offset += (component_length+2);
- } while (offset < length);
-
- return rc;
-}
-
-/* Parse an Invoke component - see table 3.3 */
-static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length,
- struct ussd_request *req)
-{
- int rc = 1;
- u_int8_t offset;
-
- /* mandatory part */
- if (invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) {
- fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag "
- "0x%02x (expecting Invoke ID tag)\n", invoke_data[0]);
- }
-
- offset = invoke_data[1] + 2;
- req->invoke_id = invoke_data[2];
-
- /* optional part */
- if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID)
- offset += invoke_data[offset+1] + 2; /* skip over it */
-
- /* mandatory part */
- if (invoke_data[offset] == GSM0480_OPERATION_CODE) {
- u_int8_t operation_code = invoke_data[offset+2];
- switch (operation_code) {
- case GSM0480_OP_CODE_PROCESS_USS_REQ:
- rc = parse_process_uss_req(invoke_data + offset + 3,
- length - offset - 3,
- req);
- break;
- default:
- fprintf(stderr, "GSM 04.80 operation code 0x%02x "
- "is not yet handled\n", operation_code);
- rc = 0;
- break;
- }
- } else {
- fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x "
- "(expecting Operation Code tag)\n",
- invoke_data[0]);
- rc = 0;
- }
-
- return rc;
-}
-
-/* Parse the parameters of a Process UnstructuredSS Request */
-static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length,
- struct ussd_request *req)
-{
- int rc = 0;
- int num_chars;
- u_int8_t dcs;
-
- if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
- if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
- dcs = uss_req_data[4];
- if ((dcs == 0x0F) &&
- (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
- num_chars = (uss_req_data[6] * 8) / 7;
- /* Prevent a mobile-originated buffer-overrun! */
- if (num_chars > MAX_LEN_USSD_STRING)
- num_chars = MAX_LEN_USSD_STRING;
- gsm_7bit_decode(req->text,
- &(uss_req_data[7]), num_chars);
- /* append null-terminator */
- req->text[num_chars+1] = 0;
- rc = 1;
- }
- }
- }
- return rc;
-}
-
/* Send response to a mobile-originated ProcessUnstructuredSS-Request */
int gsm0480_send_ussd_response(const struct msgb *in_msg, const char *response_text,
const struct ussd_request *req)