mirror of
https://github.com/brmlab/osmo-tetra.git
synced 2025-06-08 09:54:09 +02:00
TETRA: start to use msgb as part of osmo_prim / tmvsap_prim
This will allow us to pass the same msgb (with different l1h/l2h) up the stack.
This commit is contained in:
parent
8d36966e82
commit
4911ba91ef
4 changed files with 45 additions and 29 deletions
|
@ -24,6 +24,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <osmocom/core/utils.h>
|
#include <osmocom/core/utils.h>
|
||||||
|
#include <osmocom/core/msgb.h>
|
||||||
|
#include <osmocom/core/talloc.h>
|
||||||
|
|
||||||
#include <tetra_common.h>
|
#include <tetra_common.h>
|
||||||
#include <tetra_tdma.h>
|
#include <tetra_tdma.h>
|
||||||
|
@ -126,8 +128,8 @@ struct tetra_tmvsap_prim *tmvsap_prim_alloc(uint16_t prim, uint8_t op)
|
||||||
{
|
{
|
||||||
struct tetra_tmvsap_prim *ttp;
|
struct tetra_tmvsap_prim *ttp;
|
||||||
|
|
||||||
//ttp = talloc_zero(NULL, struct tetra_tmvsap_prim);
|
ttp = talloc_zero(NULL, struct tetra_tmvsap_prim);
|
||||||
ttp = calloc(1, sizeof(struct tetra_tmvsap_prim));
|
ttp->oph.msg = msgb_alloc(412, "tmvsap_prim");
|
||||||
ttp->oph.sap = TETRA_SAP_TMV;
|
ttp->oph.sap = TETRA_SAP_TMV;
|
||||||
ttp->oph.primitive = prim;
|
ttp->oph.primitive = prim;
|
||||||
ttp->oph.operation = op;
|
ttp->oph.operation = op;
|
||||||
|
@ -151,8 +153,11 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned
|
||||||
struct tetra_tmvsap_prim *ttp;
|
struct tetra_tmvsap_prim *ttp;
|
||||||
struct tmv_unitdata_param *tup;
|
struct tmv_unitdata_param *tup;
|
||||||
|
|
||||||
|
struct msgb *msg;
|
||||||
|
|
||||||
ttp = tmvsap_prim_alloc(PRIM_TMV_UNITDATA, PRIM_OP_INDICATION);
|
ttp = tmvsap_prim_alloc(PRIM_TMV_UNITDATA, PRIM_OP_INDICATION);
|
||||||
tup = &ttp->u.unitdata;
|
tup = &ttp->u.unitdata;
|
||||||
|
msg = ttp->oph.msg;
|
||||||
|
|
||||||
/* update the cell time */
|
/* update the cell time */
|
||||||
memcpy(&tcd->time, &t_phy_state.time, sizeof(tcd->time));
|
memcpy(&tcd->time, &t_phy_state.time, sizeof(tcd->time));
|
||||||
|
@ -204,10 +209,16 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned
|
||||||
ubit_dump(type2, tbp->type1_bits));
|
ubit_dump(type2, tbp->type1_bits));
|
||||||
} else
|
} else
|
||||||
printf("WRONG\n");
|
printf("WRONG\n");
|
||||||
|
} else if (type == TPSAP_T_BBK) {
|
||||||
|
/* FIXME: RM3014-decode */
|
||||||
|
tup->crc_ok = 1;
|
||||||
|
memcpy(type2, type4, tbp->type2_bits);
|
||||||
|
DEBUGP("%s %s type1: %s\n", tbp->name, time_str,
|
||||||
|
ubit_dump(type2, tbp->type1_bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(tup->mac_block, type2, tbp->type1_bits);
|
msg->l1h = msgb_put(msg, tbp->type1_bits);
|
||||||
tup->mac_block_len = tbp->type1_bits;
|
memcpy(msg->l1h, type2, tbp->type1_bits);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TPSAP_T_SB1:
|
case TPSAP_T_SB1:
|
||||||
|
@ -235,10 +246,6 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned
|
||||||
/* FIXME: do something */
|
/* FIXME: do something */
|
||||||
break;
|
break;
|
||||||
case TPSAP_T_BBK:
|
case TPSAP_T_BBK:
|
||||||
/* FIXME: RM3014-decode */
|
|
||||||
tup->crc_ok = 1;
|
|
||||||
memcpy(tup->mac_block, type4, tbp->type1_bits);
|
|
||||||
DEBUGP("%s %s type1: %s\n", tbp->name, time_str, ubit_dump(tup->mac_block, tbp->type1_bits));
|
|
||||||
tup->lchan = TETRA_LC_AACH;
|
tup->lchan = TETRA_LC_AACH;
|
||||||
break;
|
break;
|
||||||
case TPSAP_T_SCH_F:
|
case TPSAP_T_SCH_F:
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct osmo_prim_hdr {
|
||||||
uint16_t sap;
|
uint16_t sap;
|
||||||
uint16_t primitive;
|
uint16_t primitive;
|
||||||
enum osmo_prim_operation operation;
|
enum osmo_prim_operation operation;
|
||||||
|
struct msgb *msg; /* message containing associated data */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,7 +28,8 @@ struct tmv_unitdata_param {
|
||||||
int crc_ok; /* was the CRC verified OK? */
|
int crc_ok; /* was the CRC verified OK? */
|
||||||
uint32_t scrambling_code; /* which scrambling code was used */
|
uint32_t scrambling_code; /* which scrambling code was used */
|
||||||
struct tetra_tdma_time tdma_time;/* TDMA timestamp */
|
struct tetra_tdma_time tdma_time;/* TDMA timestamp */
|
||||||
uint8_t mac_block[412]; /* maximum num of bits in a non-QAM chan */ };
|
//uint8_t mac_block[412]; /* maximum num of bits in a non-QAM chan */
|
||||||
|
};
|
||||||
|
|
||||||
/* Table 23.3 */
|
/* Table 23.3 */
|
||||||
struct tmv_configure_param {
|
struct tmv_configure_param {
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <osmocom/core/utils.h>
|
#include <osmocom/core/utils.h>
|
||||||
|
#include <osmocom/core/msgb.h>
|
||||||
|
#include <osmocom/core/talloc.h>
|
||||||
|
|
||||||
#include "tetra_common.h"
|
#include "tetra_common.h"
|
||||||
#include "tetra_prim.h"
|
#include "tetra_prim.h"
|
||||||
|
@ -41,13 +43,13 @@ static struct tetra_si_decoded g_last_sid;
|
||||||
|
|
||||||
static void rx_bcast(struct tetra_tmvsap_prim *tmvp)
|
static void rx_bcast(struct tetra_tmvsap_prim *tmvp)
|
||||||
{
|
{
|
||||||
struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
struct msgb *msg = tmvp->oph.msg;
|
||||||
struct tetra_si_decoded sid;
|
struct tetra_si_decoded sid;
|
||||||
uint32_t dl_freq, ul_freq;
|
uint32_t dl_freq, ul_freq;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(&sid, 0, sizeof(sid));
|
memset(&sid, 0, sizeof(sid));
|
||||||
macpdu_decode_sysinfo(&sid, tup->mac_block);
|
macpdu_decode_sysinfo(&sid, msg->l1h);
|
||||||
|
|
||||||
dl_freq = tetra_dl_carrier_hz(sid.freq_band,
|
dl_freq = tetra_dl_carrier_hz(sid.freq_band,
|
||||||
sid.main_carrier,
|
sid.main_carrier,
|
||||||
|
@ -137,12 +139,13 @@ static int rx_tm_sdu(uint8_t *bits, unsigned int len)
|
||||||
|
|
||||||
static void rx_resrc(struct tetra_tmvsap_prim *tmvp)
|
static void rx_resrc(struct tetra_tmvsap_prim *tmvp)
|
||||||
{
|
{
|
||||||
struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
struct msgb *msg = tmvp->oph.msg;
|
||||||
struct tetra_resrc_decoded rsd;
|
struct tetra_resrc_decoded rsd;
|
||||||
int tmpdu_offset;
|
int tmpdu_offset;
|
||||||
|
|
||||||
memset(&rsd, 0, sizeof(rsd));
|
memset(&rsd, 0, sizeof(rsd));
|
||||||
tmpdu_offset = macpdu_decode_resource(&rsd, tup->mac_block);
|
tmpdu_offset = macpdu_decode_resource(&rsd, msg->l1h);
|
||||||
|
msg->l2h = msg->l1h + tmpdu_offset;
|
||||||
|
|
||||||
printf("RESOURCE Encr=%u, Length=%d Addr=%s ",
|
printf("RESOURCE Encr=%u, Length=%d Addr=%s ",
|
||||||
rsd.encryption_mode, rsd.macpdu_length,
|
rsd.encryption_mode, rsd.macpdu_length,
|
||||||
|
@ -160,10 +163,9 @@ static void rx_resrc(struct tetra_tmvsap_prim *tmvp)
|
||||||
|
|
||||||
if (rsd.macpdu_length > 0 && rsd.encryption_mode == 0) {
|
if (rsd.macpdu_length > 0 && rsd.encryption_mode == 0) {
|
||||||
int len_bits = rsd.macpdu_length*8;
|
int len_bits = rsd.macpdu_length*8;
|
||||||
if (tup->mac_block + tmpdu_offset + len_bits >
|
if (msg->l2h + len_bits > msg->l1h + msgb_l1len(msg))
|
||||||
tup->mac_block + tup->mac_block_len)
|
len_bits = msgb_l1len(msg) - tmpdu_offset;
|
||||||
len_bits = tup->mac_block_len - tmpdu_offset;
|
rx_tm_sdu(msg->l2h, len_bits);
|
||||||
rx_tm_sdu(tup->mac_block + tmpdu_offset, len_bits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -172,16 +174,17 @@ out:
|
||||||
|
|
||||||
static void rx_suppl(struct tetra_tmvsap_prim *tmvp)
|
static void rx_suppl(struct tetra_tmvsap_prim *tmvp)
|
||||||
{
|
{
|
||||||
struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
//struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
||||||
|
struct msgb *msg = tmvp->oph.msg;
|
||||||
//struct tetra_suppl_decoded sud;
|
//struct tetra_suppl_decoded sud;
|
||||||
int tmpdu_offset;
|
int tmpdu_offset;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
memset(&sud, 0, sizeof(sud));
|
memset(&sud, 0, sizeof(sud));
|
||||||
tmpdu_offset = macpdu_decode_suppl(&sud, tup->mac_block, tup->lchan);
|
tmpdu_offset = macpdu_decode_suppl(&sud, msg->l1h, tup->lchan);
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
uint8_t slot_granting = *(tup->mac_block + 17);
|
uint8_t slot_granting = *(msg->l1h + 17);
|
||||||
if (slot_granting)
|
if (slot_granting)
|
||||||
tmpdu_offset = 17+1+8;
|
tmpdu_offset = 17+1+8;
|
||||||
else
|
else
|
||||||
|
@ -192,7 +195,7 @@ static void rx_suppl(struct tetra_tmvsap_prim *tmvp)
|
||||||
printf("SUPPLEMENTARY MAC-D-BLOCK ");
|
printf("SUPPLEMENTARY MAC-D-BLOCK ");
|
||||||
|
|
||||||
//if (sud.encryption_mode == 0)
|
//if (sud.encryption_mode == 0)
|
||||||
rx_tm_sdu(tup->mac_block + tmpdu_offset, 100);
|
rx_tm_sdu(msg->l1h + tmpdu_offset, 100);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
@ -210,7 +213,7 @@ static void rx_aach(struct tetra_tmvsap_prim *tmvp)
|
||||||
printf("ACCESS-ASSIGN PDU: ");
|
printf("ACCESS-ASSIGN PDU: ");
|
||||||
|
|
||||||
memset(&aad, 0, sizeof(aad));
|
memset(&aad, 0, sizeof(aad));
|
||||||
macpdu_decode_access_assign(&aad, tup->mac_block,
|
macpdu_decode_access_assign(&aad, tmvp->oph.msg->l1h,
|
||||||
tup->tdma_time.fn == 18 ? 1 : 0);
|
tup->tdma_time.fn == 18 ? 1 : 0);
|
||||||
|
|
||||||
if (aad.pres & TETRA_ACC_ASS_PRES_ACCESS1)
|
if (aad.pres & TETRA_ACC_ASS_PRES_ACCESS1)
|
||||||
|
@ -228,7 +231,8 @@ static void rx_aach(struct tetra_tmvsap_prim *tmvp)
|
||||||
static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp)
|
static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp)
|
||||||
{
|
{
|
||||||
struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
|
||||||
uint8_t pdu_type = bits_to_uint(tup->mac_block, 2);
|
struct msgb *msg = tmvp->oph.msg;
|
||||||
|
uint8_t pdu_type = bits_to_uint(msg->l1h, 2);
|
||||||
const char *pdu_name;
|
const char *pdu_name;
|
||||||
struct msgb *gsmtap_msg;
|
struct msgb *gsmtap_msg;
|
||||||
|
|
||||||
|
@ -237,7 +241,7 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp)
|
||||||
else if (tup->lchan == TETRA_LC_AACH)
|
else if (tup->lchan == TETRA_LC_AACH)
|
||||||
pdu_name = "ACCESS-ASSIGN";
|
pdu_name = "ACCESS-ASSIGN";
|
||||||
else {
|
else {
|
||||||
pdu_type = bits_to_uint(tup->mac_block, 2);
|
pdu_type = bits_to_uint(msg->l1h, 2);
|
||||||
pdu_name = tetra_get_macpdu_name(pdu_type);
|
pdu_name = tetra_get_macpdu_name(pdu_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,8 +253,10 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp)
|
||||||
if (!tup->crc_ok)
|
if (!tup->crc_ok)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
gsmtap_msg = tetra_gsmtap_makemsg(&tup->tdma_time, tup->lchan, tup->tdma_time.tn,
|
gsmtap_msg = tetra_gsmtap_makemsg(&tup->tdma_time, tup->lchan,
|
||||||
/* FIXME: */ 0, 0, 0, tup->mac_block, tup->mac_block_len);
|
tup->tdma_time.tn,
|
||||||
|
/* FIXME: */ 0, 0, 0,
|
||||||
|
msg->l1h, msgb_l1len(msg));
|
||||||
if (gsmtap_msg)
|
if (gsmtap_msg)
|
||||||
tetra_gsmtap_sendmsg(gsmtap_msg);
|
tetra_gsmtap_sendmsg(gsmtap_msg);
|
||||||
|
|
||||||
|
@ -272,9 +278,9 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp)
|
||||||
rx_suppl(tmvp);
|
rx_suppl(tmvp);
|
||||||
break;
|
break;
|
||||||
case TETRA_PDU_T_MAC_FRAG_END:
|
case TETRA_PDU_T_MAC_FRAG_END:
|
||||||
if (tup->mac_block[3] == TETRA_MAC_FRAGE_FRAG) {
|
if (msg->l1h[3] == TETRA_MAC_FRAGE_FRAG) {
|
||||||
printf("FRAG/END FRAG: ");
|
printf("FRAG/END FRAG: ");
|
||||||
rx_tm_sdu(tup->mac_block+4, 100 /*FIXME*/);
|
rx_tm_sdu(msg->l1h+4, 100 /*FIXME*/);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
} else
|
} else
|
||||||
printf("FRAG/END END\n");
|
printf("FRAG/END END\n");
|
||||||
|
@ -309,7 +315,8 @@ int upper_mac_prim_recv(struct osmo_prim_hdr *op, void *priv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(op);
|
talloc_free(op->msg);
|
||||||
|
talloc_free(op);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue