mirror of
				https://github.com/brmlab/osmo-tetra.git
				synced 2025-10-30 23:14:00 +01:00 
			
		
		
		
	create 'struct tetra_mac_state' in main and pass through all layers/SAPs
This commit is contained in:
		
							parent
							
								
									e676ea1300
								
							
						
					
					
						commit
						0ad20fd762
					
				
					 5 changed files with 41 additions and 18 deletions
				
			
		|  | @ -39,7 +39,6 @@ | ||||||
| #include "tetra_upper_mac.h" | #include "tetra_upper_mac.h" | ||||||
| #include <lower_mac/viterbi.h> | #include <lower_mac/viterbi.h> | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| struct tetra_blk_param { | struct tetra_blk_param { | ||||||
| 	const char *name; | 	const char *name; | ||||||
| 	uint16_t type345_bits; | 	uint16_t type345_bits; | ||||||
|  | @ -147,6 +146,7 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned | ||||||
| 	uint8_t type2[512]; | 	uint8_t type2[512]; | ||||||
| 
 | 
 | ||||||
| 	const struct tetra_blk_param *tbp = &tetra_blk_param[type]; | 	const struct tetra_blk_param *tbp = &tetra_blk_param[type]; | ||||||
|  | 	struct tetra_mac_state *tms = priv; | ||||||
| 	const char *time_str; | 	const char *time_str; | ||||||
| 
 | 
 | ||||||
| 	/* TMV-SAP.UNITDATA.ind primitive which we will send to the upper MAC */ | 	/* TMV-SAP.UNITDATA.ind primitive which we will send to the upper MAC */ | ||||||
|  | @ -258,7 +258,7 @@ void tp_sap_udata_ind(enum tp_sap_data_type type, const uint8_t *bits, unsigned | ||||||
| 	/* send Rx time along with the TMV-UNITDATA.ind primitive */ | 	/* send Rx time along with the TMV-UNITDATA.ind primitive */ | ||||||
| 	memcpy(&tup->tdma_time, &tcd->time, sizeof(tup->tdma_time)); | 	memcpy(&tup->tdma_time, &tcd->time, sizeof(tup->tdma_time)); | ||||||
| 
 | 
 | ||||||
| 	upper_mac_prim_recv(&ttp->oph, NULL); | 	upper_mac_prim_recv(&ttp->oph, tms); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,16 +27,20 @@ | ||||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||||
| 
 | 
 | ||||||
| #include <osmocom/core/utils.h> | #include <osmocom/core/utils.h> | ||||||
|  | #include <osmocom/core/talloc.h> | ||||||
| 
 | 
 | ||||||
| #include "tetra_common.h" | #include "tetra_common.h" | ||||||
| #include <phy/tetra_burst.h> | #include <phy/tetra_burst.h> | ||||||
| #include <phy/tetra_burst_sync.h> | #include <phy/tetra_burst_sync.h> | ||||||
| #include "tetra_gsmtap.h" | #include "tetra_gsmtap.h" | ||||||
| 
 | 
 | ||||||
|  | void *tetra_tall_ctx; | ||||||
|  | 
 | ||||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||||
| { | { | ||||||
| 	int fd; | 	int fd; | ||||||
| 	struct tetra_rx_state *trs; | 	struct tetra_rx_state *trs; | ||||||
|  | 	struct tetra_mac_state *tms; | ||||||
| 
 | 
 | ||||||
| 	if (argc < 2) { | 	if (argc < 2) { | ||||||
| 		fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]); | 		fprintf(stderr, "Usage: %s <file_with_1_byte_per_bit>\n", argv[0]); | ||||||
|  | @ -51,7 +55,11 @@ int main(int argc, char **argv) | ||||||
| 
 | 
 | ||||||
| 	tetra_gsmtap_init("localhost", 0); | 	tetra_gsmtap_init("localhost", 0); | ||||||
| 
 | 
 | ||||||
|  | 	tms = talloc_zero(tetra_tall_ctx, struct tetra_mac_state); | ||||||
|  | 	tetra_mac_state_init(tms); | ||||||
|  | 
 | ||||||
| 	trs = calloc(1, sizeof(*trs)); | 	trs = calloc(1, sizeof(*trs)); | ||||||
|  | 	trs->burst_cb_priv = tms; | ||||||
| 
 | 
 | ||||||
| 	while (1) { | 	while (1) { | ||||||
| 		uint8_t buf[64]; | 		uint8_t buf[64]; | ||||||
|  | @ -69,6 +77,7 @@ int main(int argc, char **argv) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	free(trs); | 	free(trs); | ||||||
|  | 	talloc_free(tms); | ||||||
| 
 | 
 | ||||||
| 	exit(0); | 	exit(0); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -124,3 +124,8 @@ const char *tetra_get_sap_name(uint8_t sap) | ||||||
| { | { | ||||||
| 	return get_value_string(tetra_sap_names, sap); | 	return get_value_string(tetra_sap_names, sap); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void tetra_mac_state_init(struct tetra_mac_state *tms) | ||||||
|  | { | ||||||
|  | 	INIT_LLIST_HEAD(&tms->voice_channels); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -3,6 +3,8 @@ | ||||||
| 
 | 
 | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| 
 | 
 | ||||||
|  | #include <osmocom/core/linuxlist.h> | ||||||
|  | 
 | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
| #define DEBUGP(x, args...)	printf(x, ## args) | #define DEBUGP(x, args...)	printf(x, ## args) | ||||||
| #else | #else | ||||||
|  | @ -40,6 +42,12 @@ struct tetra_phy_state { | ||||||
| }; | }; | ||||||
| extern struct tetra_phy_state t_phy_state; | extern struct tetra_phy_state t_phy_state; | ||||||
| 
 | 
 | ||||||
|  | struct tetra_mac_state { | ||||||
|  | 	struct llist_head voice_channels; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | void tetra_mac_state_init(struct tetra_mac_state *tms); | ||||||
|  | 
 | ||||||
| #define TETRA_CRC_OK	0x1d0f | #define TETRA_CRC_OK	0x1d0f | ||||||
| 
 | 
 | ||||||
| uint32_t tetra_dl_carrier_hz(uint8_t band, uint16_t carrier, uint8_t offset); | uint32_t tetra_dl_carrier_hz(uint8_t band, uint16_t carrier, uint8_t offset); | ||||||
|  |  | ||||||
|  | @ -41,7 +41,7 @@ | ||||||
| /* FIXME: this is ugly */ | /* FIXME: this is ugly */ | ||||||
| static struct tetra_si_decoded g_last_sid; | 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 tetra_mac_state *tms) | ||||||
| { | { | ||||||
| 	struct msgb *msg = tmvp->oph.msg; | 	struct msgb *msg = tmvp->oph.msg; | ||||||
| 	struct tetra_si_decoded sid; | 	struct tetra_si_decoded sid; | ||||||
|  | @ -97,7 +97,7 @@ const char *tetra_alloc_dump(const struct tetra_chan_alloc_decoded *cad) | ||||||
| 	return buf; | 	return buf; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int rx_tl_sdu(uint8_t *bits, unsigned int len) | static int rx_tl_sdu(struct tetra_mac_state *tms, uint8_t *bits, unsigned int len) | ||||||
| { | { | ||||||
| 	uint8_t mle_pdisc = bits_to_uint(bits, 3); | 	uint8_t mle_pdisc = bits_to_uint(bits, 3); | ||||||
| 
 | 
 | ||||||
|  | @ -122,7 +122,7 @@ static int rx_tl_sdu(uint8_t *bits, unsigned int len) | ||||||
| 	return len; | 	return len; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int rx_tm_sdu(uint8_t *bits, unsigned int len) | static int rx_tm_sdu(struct tetra_mac_state *tms, uint8_t *bits, unsigned int len) | ||||||
| { | { | ||||||
| 	struct tetra_llc_pdu lpp; | 	struct tetra_llc_pdu lpp; | ||||||
| 
 | 
 | ||||||
|  | @ -132,12 +132,12 @@ static int rx_tm_sdu(uint8_t *bits, unsigned int len) | ||||||
| 	printf("TM-SDU(%s,%u,%u): ", | 	printf("TM-SDU(%s,%u,%u): ", | ||||||
| 		tetra_get_llc_pdut_dec_name(lpp.pdu_type), lpp.ns, lpp.ss); | 		tetra_get_llc_pdut_dec_name(lpp.pdu_type), lpp.ns, lpp.ss); | ||||||
| 	if (lpp.tl_sdu && lpp.ss == 0) { | 	if (lpp.tl_sdu && lpp.ss == 0) { | ||||||
| 		rx_tl_sdu(lpp.tl_sdu, lpp.tl_sdu_len); | 		rx_tl_sdu(tms, lpp.tl_sdu, lpp.tl_sdu_len); | ||||||
| 	} | 	} | ||||||
| 	return len; | 	return len; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void rx_resrc(struct tetra_tmvsap_prim *tmvp) | static void rx_resrc(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms) | ||||||
| { | { | ||||||
| 	struct msgb *msg = tmvp->oph.msg; | 	struct msgb *msg = tmvp->oph.msg; | ||||||
| 	struct tetra_resrc_decoded rsd; | 	struct tetra_resrc_decoded rsd; | ||||||
|  | @ -165,14 +165,14 @@ static void rx_resrc(struct tetra_tmvsap_prim *tmvp) | ||||||
| 		int len_bits = rsd.macpdu_length*8; | 		int len_bits = rsd.macpdu_length*8; | ||||||
| 		if (msg->l2h + len_bits > msg->l1h + msgb_l1len(msg)) | 		if (msg->l2h + len_bits > msg->l1h + msgb_l1len(msg)) | ||||||
| 			len_bits = msgb_l1len(msg) - tmpdu_offset; | 			len_bits = msgb_l1len(msg) - tmpdu_offset; | ||||||
| 		rx_tm_sdu(msg->l2h, len_bits); | 		rx_tm_sdu(tms, msg->l2h, len_bits); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
| 	printf("\n"); | 	printf("\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void rx_suppl(struct tetra_tmvsap_prim *tmvp) | static void rx_suppl(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms) | ||||||
| { | { | ||||||
| 	//struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
 | 	//struct tmv_unitdata_param *tup = &tmvp->u.unitdata;
 | ||||||
| 	struct msgb *msg = tmvp->oph.msg; | 	struct msgb *msg = tmvp->oph.msg; | ||||||
|  | @ -195,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(msg->l1h + tmpdu_offset, 100); | 		rx_tm_sdu(tms, msg->l1h + tmpdu_offset, 100); | ||||||
| 
 | 
 | ||||||
| 	printf("\n"); | 	printf("\n"); | ||||||
| } | } | ||||||
|  | @ -205,7 +205,7 @@ static void dump_access(struct tetra_access_field *acc, unsigned int num) | ||||||
| 	printf("ACCESS%u: %c/%u ", num, 'A'+acc->access_code, acc->base_frame_len); | 	printf("ACCESS%u: %c/%u ", num, 'A'+acc->access_code, acc->base_frame_len); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void rx_aach(struct tetra_tmvsap_prim *tmvp) | static void rx_aach(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms) | ||||||
| { | { | ||||||
| 	struct tmv_unitdata_param *tup = &tmvp->u.unitdata; | 	struct tmv_unitdata_param *tup = &tmvp->u.unitdata; | ||||||
| 	struct tetra_acc_ass_decoded aad; | 	struct tetra_acc_ass_decoded aad; | ||||||
|  | @ -228,7 +228,7 @@ static void rx_aach(struct tetra_tmvsap_prim *tmvp) | ||||||
| 	printf("\n"); | 	printf("\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp) | static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp, struct tetra_mac_state *tms) | ||||||
| { | { | ||||||
| 	struct tmv_unitdata_param *tup = &tmvp->u.unitdata; | 	struct tmv_unitdata_param *tup = &tmvp->u.unitdata; | ||||||
| 	struct msgb *msg = tmvp->oph.msg; | 	struct msgb *msg = tmvp->oph.msg; | ||||||
|  | @ -262,25 +262,25 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp) | ||||||
| 
 | 
 | ||||||
| 	switch (tup->lchan) { | 	switch (tup->lchan) { | ||||||
| 	case TETRA_LC_AACH: | 	case TETRA_LC_AACH: | ||||||
| 		rx_aach(tmvp); | 		rx_aach(tmvp, tms); | ||||||
| 		break; | 		break; | ||||||
| 	case TETRA_LC_BNCH: | 	case TETRA_LC_BNCH: | ||||||
| 	case TETRA_LC_UNKNOWN: | 	case TETRA_LC_UNKNOWN: | ||||||
| 	case TETRA_LC_SCH_F: | 	case TETRA_LC_SCH_F: | ||||||
| 		switch (pdu_type) { | 		switch (pdu_type) { | ||||||
| 		case TETRA_PDU_T_BROADCAST: | 		case TETRA_PDU_T_BROADCAST: | ||||||
| 			rx_bcast(tmvp); | 			rx_bcast(tmvp, tms); | ||||||
| 			break; | 			break; | ||||||
| 		case TETRA_PDU_T_MAC_RESOURCE: | 		case TETRA_PDU_T_MAC_RESOURCE: | ||||||
| 			rx_resrc(tmvp); | 			rx_resrc(tmvp, tms); | ||||||
| 			break; | 			break; | ||||||
| 		case TETRA_PDU_T_MAC_SUPPL: | 		case TETRA_PDU_T_MAC_SUPPL: | ||||||
| 			rx_suppl(tmvp); | 			rx_suppl(tmvp, tms); | ||||||
| 			break; | 			break; | ||||||
| 		case TETRA_PDU_T_MAC_FRAG_END: | 		case TETRA_PDU_T_MAC_FRAG_END: | ||||||
| 			if (msg->l1h[3] == TETRA_MAC_FRAGE_FRAG) { | 			if (msg->l1h[3] == TETRA_MAC_FRAGE_FRAG) { | ||||||
| 				printf("FRAG/END FRAG: "); | 				printf("FRAG/END FRAG: "); | ||||||
| 				rx_tm_sdu(msg->l1h+4, 100 /*FIXME*/); | 				rx_tm_sdu(tms, msg->l1h+4, 100 /*FIXME*/); | ||||||
| 				printf("\n"); | 				printf("\n"); | ||||||
| 			} else | 			} else | ||||||
| 				printf("FRAG/END END\n"); | 				printf("FRAG/END END\n"); | ||||||
|  | @ -303,12 +303,13 @@ static int rx_tmv_unitdata_ind(struct tetra_tmvsap_prim *tmvp) | ||||||
| int upper_mac_prim_recv(struct osmo_prim_hdr *op, void *priv) | int upper_mac_prim_recv(struct osmo_prim_hdr *op, void *priv) | ||||||
| { | { | ||||||
| 	struct tetra_tmvsap_prim *tmvp; | 	struct tetra_tmvsap_prim *tmvp; | ||||||
|  | 	struct tetra_mac_state *tms = priv; | ||||||
| 	int rc; | 	int rc; | ||||||
| 
 | 
 | ||||||
| 	switch (op->sap) { | 	switch (op->sap) { | ||||||
| 	case TETRA_SAP_TMV: | 	case TETRA_SAP_TMV: | ||||||
| 		tmvp = (struct tetra_tmvsap_prim *) op; | 		tmvp = (struct tetra_tmvsap_prim *) op; | ||||||
| 		rc = rx_tmv_unitdata_ind(tmvp); | 		rc = rx_tmv_unitdata_ind(tmvp, tms); | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		printf("primitive on unknown sap\n"); | 		printf("primitive on unknown sap\n"); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Harald Welte
						Harald Welte