mirror of https://gerrit.osmocom.org/libosmocore
GSM 04.08: Add support for parsing CSD related bearer capabilities
Also adds a test case for both encoder and decoder of this IE
This commit is contained in:
parent
7ccd3181c5
commit
c8a0b93939
|
@ -1,6 +1,8 @@
|
|||
#ifndef _OSMOCORE_MNCC_H
|
||||
#define _OSMOCORE_MNCC_H
|
||||
|
||||
#include <osmocom/gsm/protocol/gsm_04_08.h>
|
||||
|
||||
#define GSM_MAX_FACILITY 128
|
||||
#define GSM_MAX_SSVERSION 128
|
||||
#define GSM_MAX_USERUSER 128
|
||||
|
@ -13,6 +15,18 @@ struct gsm_mncc_bearer_cap {
|
|||
int radio; /* Radio Channel Requirement */
|
||||
int speech_ctm; /* CTM text telephony indication */
|
||||
int speech_ver[8]; /* Speech version indication */
|
||||
struct {
|
||||
enum gsm48_bcap_ra rate_adaption;
|
||||
enum gsm48_bcap_sig_access sig_access;
|
||||
int async;
|
||||
int nr_stop_bits;
|
||||
int nr_data_bits;
|
||||
enum gsm48_bcap_user_rate user_rate;
|
||||
enum gsm48_bcap_parity parity;
|
||||
enum gsm48_bcap_interm_rate interm_rate;
|
||||
enum gsm48_bcap_transp transp;
|
||||
enum gsm48_bcap_modem_type modem_type;
|
||||
} data;
|
||||
};
|
||||
|
||||
struct gsm_mncc_number {
|
||||
|
|
|
@ -1246,6 +1246,71 @@ enum gsm48_bcap_rrq {
|
|||
GSM48_BCAP_RRQ_DUAL_FR = 3,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Rate Adaption */
|
||||
enum gsm48_bcap_ra {
|
||||
GSM48_BCAP_RA_NONE = 0,
|
||||
GSM48_BCAP_RA_V110_X30 = 1,
|
||||
GSM48_BCAP_RA_X31 = 2,
|
||||
GSM48_BCAP_RA_OTHER = 3,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Signalling access protocol */
|
||||
enum gsm48_bcap_sig_access {
|
||||
GSM48_BCAP_SA_I440_I450 = 1,
|
||||
GSM48_BCAP_SA_X21 = 2,
|
||||
GSM48_BCAP_SA_X28_DP_IN = 3,
|
||||
GSM48_BCAP_SA_X28_DP_UN = 4,
|
||||
GSM48_BCAP_SA_X28_NDP = 5,
|
||||
GSM48_BCAP_SA_X32 = 6,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: User Rate */
|
||||
enum gsm48_bcap_user_rate {
|
||||
GSM48_BCAP_UR_300 = 1,
|
||||
GSM48_BCAP_UR_1200 = 2,
|
||||
GSM48_BCAP_UR_2400 = 3,
|
||||
GSM48_BCAP_UR_4800 = 4,
|
||||
GSM48_BCAP_UR_9600 = 5,
|
||||
GSM48_BCAP_UR_12000 = 6,
|
||||
GSM48_BCAP_UR_1200_75 = 7,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Parity */
|
||||
enum gsm48_bcap_parity {
|
||||
GSM48_BCAP_PAR_ODD = 0,
|
||||
GSM48_BCAP_PAR_EVEN = 2,
|
||||
GSM48_BCAP_PAR_NONE = 3,
|
||||
GSM48_BCAP_PAR_ZERO = 4,
|
||||
GSM48_BCAP_PAR_ONE = 5,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Intermediate Rate */
|
||||
enum gsm48_bcap_interm_rate {
|
||||
GSM48_BCAP_IR_8k = 2,
|
||||
GSM48_BCAP_IR_16k = 3,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Transparency */
|
||||
enum gsm48_bcap_transp {
|
||||
GSM48_BCAP_TR_TRANSP = 0,
|
||||
GSM48_BCAP_TR_RLP = 1,
|
||||
GSM48_BCAP_TR_TR_PREF = 2,
|
||||
GSM48_BCAP_TR_RLP_PREF = 3,
|
||||
};
|
||||
|
||||
/* GSM 04.08 Bearer Capability: Modem Type */
|
||||
enum gsm48_bcap_modem_type {
|
||||
GSM48_BCAP_MT_NONE = 0,
|
||||
GSM48_BCAP_MT_V21 = 1,
|
||||
GSM48_BCAP_MT_V22 = 2,
|
||||
GSM48_BCAP_MT_V22bis = 3,
|
||||
GSM48_BCAP_MT_V23 = 4,
|
||||
GSM48_BCAP_MT_V26ter = 5,
|
||||
GSM48_BCAP_MT_V32 = 6,
|
||||
GSM48_BCAP_MT_UNDEF = 7,
|
||||
GSM48_BCAP_MT_AUTO_1 = 8,
|
||||
};
|
||||
|
||||
#define GSM48_TMSI_LEN 5
|
||||
#define GSM48_MID_TMSI_LEN (GSM48_TMSI_LEN + 2)
|
||||
#define GSM48_MI_SIZE 32
|
||||
|
|
|
@ -128,7 +128,8 @@ int gsm48_decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap,
|
|||
bcap->coding = (lv[1] & 0x10) >> 4;
|
||||
bcap->radio = (lv[1] & 0x60) >> 5;
|
||||
|
||||
if (bcap->transfer == GSM_MNCC_BCAP_SPEECH) {
|
||||
switch (bcap->transfer) {
|
||||
case GSM_MNCC_BCAP_SPEECH:
|
||||
i = 1;
|
||||
s = 0;
|
||||
while(!(lv[i] & 0x80)) {
|
||||
|
@ -142,7 +143,68 @@ int gsm48_decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap,
|
|||
if (s == 7) /* maximum speech versions + end of list */
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case GSM_MNCC_BCAP_UNR_DIG:
|
||||
case GSM_MNCC_BCAP_FAX_G3:
|
||||
i = 1;
|
||||
while(!(lv[i] & 0x80)) {
|
||||
i++; /* octet 3a etc */
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
/* ignore them */
|
||||
}
|
||||
/* octet 4: skip */
|
||||
i++;
|
||||
/* octet 5 */
|
||||
i++;
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
bcap->data.rate_adaption = (lv[i] >> 3) & 3;
|
||||
bcap->data.sig_access = lv[i] & 7;
|
||||
while(!(lv[i] & 0x80)) {
|
||||
i++; /* octet 5a etc */
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
/* ignore them */
|
||||
}
|
||||
/* octet 6 */
|
||||
i++;
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
bcap->data.async = lv[i] & 1;
|
||||
if (!(lv[i] & 0x80)) {
|
||||
i++;
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
/* octet 6a */
|
||||
bcap->data.nr_stop_bits = ((lv[i] >> 7) & 1) + 1;
|
||||
if (lv[i] & 0x10)
|
||||
bcap->data.nr_data_bits = 8;
|
||||
else
|
||||
bcap->data.nr_data_bits = 7;
|
||||
bcap->data.user_rate = lv[i] & 0xf;
|
||||
|
||||
if (!(lv[i] & 0x80)) {
|
||||
i++;
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
/* octet 6b */
|
||||
bcap->data.parity = lv[i] & 7;
|
||||
bcap->data.interm_rate = (lv[i] >> 5) & 3;
|
||||
|
||||
/* octet 6c */
|
||||
if (!(lv[i] & 0x80)) {
|
||||
i++;
|
||||
if (in_len < i)
|
||||
return 0;
|
||||
bcap->data.transp = (lv[i] >> 5) & 3;
|
||||
bcap->data.modem_type = lv[i] & 0x1F;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
i = 1;
|
||||
while (!(lv[i] & 0x80)) {
|
||||
i++; /* octet 3a etc */
|
||||
|
@ -151,6 +213,7 @@ int gsm48_decode_bearer_cap(struct gsm_mncc_bearer_cap *bcap,
|
|||
/* ignore them */
|
||||
}
|
||||
/* FIXME: implement OCTET 4+ parsing */
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -168,7 +231,8 @@ int gsm48_encode_bearer_cap(struct msgb *msg, int lv_only,
|
|||
lv[1] |= bcap->coding << 4;
|
||||
lv[1] |= bcap->radio << 5;
|
||||
|
||||
if (bcap->transfer == GSM_MNCC_BCAP_SPEECH) {
|
||||
switch (bcap->transfer) {
|
||||
case GSM_MNCC_BCAP_SPEECH:
|
||||
for (s = 0; bcap->speech_ver[s] >= 0; s++) {
|
||||
i++; /* octet 3a etc */
|
||||
lv[i] = bcap->speech_ver[s];
|
||||
|
@ -176,8 +240,29 @@ int gsm48_encode_bearer_cap(struct msgb *msg, int lv_only,
|
|||
lv[i] |= bcap->speech_ctm << 5;
|
||||
}
|
||||
lv[i] |= 0x80; /* last IE of octet 3 etc */
|
||||
} else {
|
||||
/* FIXME: implement OCTET 4+ encoding */
|
||||
break;
|
||||
case GSM48_BCAP_ITCAP_UNR_DIG_INF:
|
||||
case GSM48_BCAP_ITCAP_FAX_G3:
|
||||
lv[i++] |= 0x80; /* last IE of octet 3 etc */
|
||||
/* octet 4 */
|
||||
lv[i++] = 0xb8;
|
||||
/* octet 5 */
|
||||
lv[i++] = 0x80 | ((bcap->data.rate_adaption & 3) << 3)
|
||||
| (bcap->data.sig_access & 7);
|
||||
/* octet 6 */
|
||||
lv[i++] = 0x20 | (bcap->data.async & 1);
|
||||
/* octet 6a */
|
||||
lv[i++] = (bcap->data.user_rate & 0xf) |
|
||||
(bcap->data.nr_data_bits == 8 ? 0x10 : 0x00) |
|
||||
(bcap->data.nr_stop_bits == 2 ? 0x40 : 0x00);
|
||||
/* octet 6b */
|
||||
lv[i++] = (bcap->data.parity & 7) |
|
||||
((bcap->data.interm_rate & 3) << 5);
|
||||
/* octet 6c */
|
||||
lv[i] = 0x80 | (bcap->data.modem_type & 0x1f);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
lv[0] = i;
|
||||
|
|
|
@ -3,7 +3,7 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
|
|||
check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
|
||||
smscb/smscb_test bits/bitrev_test a5/a5_test \
|
||||
conv/conv_test auth/milenage_test lapd/lapd_test \
|
||||
gsm0808/gsm0808_test
|
||||
gsm0808/gsm0808_test gsm0408/gsm0408_test
|
||||
if ENABLE_MSGFILE
|
||||
check_PROGRAMS += msgfile/msgfile_test
|
||||
endif
|
||||
|
@ -23,6 +23,9 @@ conv_conv_test_LDADD = $(top_builddir)/src/libosmocore.la
|
|||
gsm0808_gsm0808_test_SOURCES = gsm0808/gsm0808_test.c
|
||||
gsm0808_gsm0808_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
gsm0408_gsm0408_test_SOURCES = gsm0408/gsm0408_test.c
|
||||
gsm0408_gsm0408_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
lapd_lapd_test_SOURCES = lapd/lapd_test.c
|
||||
lapd_lapd_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
|
||||
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* (C) 2012 by Harald Welte <laforge@gnumonks.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <osmocom/gsm/protocol/gsm_04_08.h>
|
||||
#include <osmocom/gsm/gsm48_ie.h>
|
||||
#include <osmocom/gsm/mncc.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
|
||||
|
||||
static const uint8_t csd_9600_v110_lv[] = { 0x07, 0xa1, 0xb8, 0x89, 0x21, 0x15, 0x63, 0x80 };
|
||||
|
||||
static const struct gsm_mncc_bearer_cap bcap_csd_9600_v110 = {
|
||||
.transfer = GSM48_BCAP_ITCAP_UNR_DIG_INF,
|
||||
.mode = GSM48_BCAP_TMOD_CIRCUIT,
|
||||
.coding = GSM48_BCAP_CODING_GSM_STD,
|
||||
.radio = GSM48_BCAP_RRQ_FR_ONLY,
|
||||
.speech_ver[0]= -1,
|
||||
.data = {
|
||||
.rate_adaption = GSM48_BCAP_RA_V110_X30,
|
||||
.sig_access = GSM48_BCAP_SA_I440_I450,
|
||||
.async = 1,
|
||||
.nr_stop_bits = 1,
|
||||
.nr_data_bits = 8,
|
||||
.user_rate = GSM48_BCAP_UR_9600,
|
||||
.parity = GSM48_BCAP_PAR_NONE,
|
||||
.interm_rate = GSM48_BCAP_IR_16k,
|
||||
.transp = GSM48_BCAP_TR_TRANSP,
|
||||
.modem_type = GSM48_BCAP_MT_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
static const uint8_t speech_all_lv[] = { 0x06, 0x60, 0x04, 0x02, 0x00, 0x05, 0x81 };
|
||||
|
||||
static const struct gsm_mncc_bearer_cap bcap_speech_all = {
|
||||
.transfer = GSM48_BCAP_ITCAP_SPEECH,
|
||||
.mode = GSM48_BCAP_TMOD_CIRCUIT,
|
||||
.coding = GSM48_BCAP_CODING_GSM_STD,
|
||||
.radio = GSM48_BCAP_RRQ_DUAL_FR,
|
||||
.speech_ver = {
|
||||
4, 2, 0, 5, 1, -1,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
struct bcap_test {
|
||||
const uint8_t *lv;
|
||||
const struct gsm_mncc_bearer_cap *bc;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
static const struct bcap_test bcap_tests[] = {
|
||||
{ csd_9600_v110_lv, &bcap_csd_9600_v110, "CSD 9600/V.110/transparent" },
|
||||
{ speech_all_lv, &bcap_speech_all, "Speech, all codecs" },
|
||||
};
|
||||
|
||||
static int test_bearer_cap()
|
||||
{
|
||||
struct gsm_mncc_bearer_cap bc;
|
||||
int i, rc;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bcap_tests); i++) {
|
||||
struct msgb *msg = msgb_alloc(100, "test");
|
||||
int lv_len;
|
||||
|
||||
memset(&bc, 0, sizeof(bc));
|
||||
|
||||
/* test decoding */
|
||||
rc = gsm48_decode_bearer_cap(&bc, bcap_tests[i].lv);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error decoding %s\n",
|
||||
bcap_tests[i].name);
|
||||
return rc;
|
||||
}
|
||||
if (memcmp(&bc, bcap_tests[i].bc, sizeof(bc))) {
|
||||
fprintf(stderr, "Incorrect decoded result of %s:\n",
|
||||
bcap_tests[i].name);
|
||||
fprintf(stderr, " should: %s\n",
|
||||
osmo_hexdump((uint8_t *) bcap_tests[i].bc, sizeof(bc)));
|
||||
fprintf(stderr, " is: %s\n",
|
||||
osmo_hexdump((uint8_t *) &bc, sizeof(bc)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* also test re-encode? */
|
||||
rc = gsm48_encode_bearer_cap(msg, 1, &bc);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error encoding %s\n",
|
||||
bcap_tests[i].name);
|
||||
return rc;
|
||||
}
|
||||
lv_len = bcap_tests[i].lv[0]+1;
|
||||
if (memcmp(msg->data, bcap_tests[i].lv, lv_len)) {
|
||||
fprintf(stderr, "Incorrect encoded result of %s:\n",
|
||||
bcap_tests[i].name);
|
||||
fprintf(stderr, " should: %s\n",
|
||||
osmo_hexdump(bcap_tests[i].lv, lv_len));
|
||||
fprintf(stderr, " is: %s\n",
|
||||
osmo_hexdump(msg->data, msg->len));
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Test `%s' passed\n", bcap_tests[i].name);
|
||||
msgb_free(msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
test_bearer_cap();
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Test `CSD 9600/V.110/transparent' passed
|
||||
Test `Speech, all codecs' passed
|
|
@ -71,3 +71,9 @@ AT_KEYWORDS([gsm0808])
|
|||
cat $abs_srcdir/gsm0808/gsm0808_test.ok > expout
|
||||
AT_CHECK([$abs_top_builddir/tests/gsm0808/gsm0808_test], [], [expout], [ignore])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([gsm0408])
|
||||
AT_KEYWORDS([gsm0408])
|
||||
cat $abs_srcdir/gsm0408/gsm0408_test.ok > expout
|
||||
AT_CHECK([$abs_top_builddir/tests/gsm0408/gsm0408_test], [], [expout], [ignore])
|
||||
AT_CLEANUP
|
||||
|
|
Loading…
Reference in New Issue