NMT: Change 'index' of message to 'mt' (message type)

This commit is contained in:
Andreas Eversberg 2016-07-20 12:51:25 +02:00
parent 5807a49f49
commit 8741833948
3 changed files with 71 additions and 69 deletions

View File

@ -133,7 +133,7 @@ int nmt_encode_a_number(frame_t *frame, int index, enum number_type type, const
number_offset = index * 7 - 2;
/* encode */
frame->index = NMT_MESSAGE_8;
frame->mt = NMT_MESSAGE_8;
frame->seq_number = index;
if (index == 0) {
/* number type */
@ -251,11 +251,11 @@ static struct nmt_frame {
/* store actual number of frames for run-time range check */
static int num_frames;
const char *nmt_frame_name(int index)
const char *nmt_frame_name(enum nmt_mt mt)
{
if (index < 0 || index >= num_frames)
if (mt < 0 || mt >= num_frames)
return "invalid";
return nmt_frame[index].nr;
return nmt_frame[mt].nr;
}
static const char *param_integer(uint64_t value, int ndigits, enum nmt_direction direction)
@ -483,7 +483,7 @@ static struct nmt_parameter {
/* Depending on P-value, direction and additional info, frame index (used for
* nmt_frame[]) is decoded.
*/
static int decode_frame_index(const uint8_t *digits, enum nmt_direction direction, int callack)
enum nmt_mt decode_frame_mt(const uint8_t *digits, enum nmt_direction direction, int callack)
{
if (direction == MS_TO_MTX || direction == BS_TO_MTX || direction == XX_TO_MTX) {
/* MS/BS TO MTX */
@ -672,30 +672,30 @@ int init_frame(void)
/* decode 16 digits frame */
static void disassemble_frame(frame_t *frame, const uint8_t *digits, enum nmt_direction direction, int callack)
{
int index;
enum nmt_mt mt;
int i, j, ndigits;
char digit;
uint64_t value;
memset(frame, 0, sizeof(*frame));
/* index of frame */
index = decode_frame_index(digits, direction, callack);
frame->index = index;
/* message type of frame */
mt = decode_frame_mt(digits, direction, callack);
frame->mt = mt;
/* update direction */
direction = nmt_frame[index].direction;
direction = nmt_frame[mt].direction;
PDEBUG(DFRAME, DEBUG_DEBUG, "Decoding %s %s %s\n", nmt_dir_name(direction), nmt_frame[index].nr, nmt_frame[index].description);
PDEBUG(DFRAME, DEBUG_DEBUG, "Decoding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description);
for (i = 0; i < 16; i++) {
digit = nmt_frame[index].digits[i];
digit = nmt_frame[mt].digits[i];
if (digit == '-')
continue;
value = digits[i];
ndigits = 1;
for (j = i + 1; j < 16; j++) {
if (nmt_frame[index].digits[j] != digit)
if (nmt_frame[mt].digits[j] != digit)
break;
value = (value << 4) | digits[j];
ndigits++;
@ -790,7 +790,7 @@ static void disassemble_frame(frame_t *frame, const uint8_t *digits, enum nmt_di
for (i = 0; i < 16; i++)
debug_digits[i] = "0123456789abcdef"[digits[i]];
debug_digits[i] = '\0';
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[index].digits);
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[mt].digits);
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug_digits);
}
}
@ -798,30 +798,30 @@ static void disassemble_frame(frame_t *frame, const uint8_t *digits, enum nmt_di
/* encode 16 digits frame */
static void assemble_frame(frame_t *frame, uint8_t *digits, int debug)
{
int index;
enum nmt_mt mt;
int i, j;
char digit;
uint64_t value;
enum nmt_direction direction;
index = frame->index;
mt = frame->mt;
if (index >= num_frames) {
PDEBUG(DFRAME, DEBUG_ERROR, "Frame index %d out of range (0..%d), please fix!\n", index, num_frames - 1);
if (mt >= num_frames) {
PDEBUG(DFRAME, DEBUG_ERROR, "Frame mt %d out of range (0..%d), please fix!\n", mt, num_frames - 1);
abort();
}
/* set prefix of frame */
frame->prefix = nmt_frame[index].prefix;
frame->prefix = nmt_frame[mt].prefix;
/* retrieve direction */
direction = nmt_frame[index].direction;
direction = nmt_frame[mt].direction;
if (debug)
PDEBUG(DFRAME, DEBUG_DEBUG, "Coding %s %s %s\n", nmt_dir_name(direction), nmt_frame[index].nr, nmt_frame[index].description);
PDEBUG(DFRAME, DEBUG_DEBUG, "Coding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description);
for (i = 15; i >= 0; i--) {
digit = nmt_frame[index].digits[i];
digit = nmt_frame[mt].digits[i];
if (digit == '-') {
digits[i] = 0;
continue;
@ -904,7 +904,7 @@ static void assemble_frame(frame_t *frame, uint8_t *digits, int debug)
digits[i] = (value & 0xf);
value >>= 4;
for (j = i - 1; j >= 0; j--) {
if (nmt_frame[index].digits[j] != digit)
if (nmt_frame[mt].digits[j] != digit)
break;
digits[j] = (value & 0xf);
value >>= 4;
@ -916,13 +916,13 @@ static void assemble_frame(frame_t *frame, uint8_t *digits, int debug)
int ndigits;
for (i = 0; i < 16; i++) {
digit = nmt_frame[index].digits[i];
digit = nmt_frame[mt].digits[i];
if (digit == '-')
continue;
value = digits[i];
ndigits = 1;
for (j = i + 1; j < 16; j++) {
if (nmt_frame[index].digits[j] != digit)
if (nmt_frame[mt].digits[j] != digit)
break;
value = (value << 4) | digits[j];
ndigits++;
@ -938,7 +938,7 @@ static void assemble_frame(frame_t *frame, uint8_t *digits, int debug)
for (i = 0; i < 16; i++)
debug_digits[i] = "0123456789abcdef"[digits[i]];
debug_digits[i] = '\0';
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[index].digits);
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[mt].digits);
PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug_digits);
}
}

View File

@ -49,7 +49,7 @@ enum nmt_mt {
};
typedef struct frame {
uint8_t index;
enum nmt_mt mt;
uint16_t channel_no;
uint16_t tc_no;
uint8_t traffic_area;
@ -84,7 +84,7 @@ uint64_t nmt_digits2value(const char *digits, int num);
char nmt_value2digit(uint64_t value);
uint16_t nmt_encode_area_no(uint8_t area_no);
const char *nmt_frame_name(int index);
const char *nmt_frame_name(enum nmt_mt mt);
const char *encode_frame(frame_t *frame, int debug);
int decode_frame(frame_t *frame, const char *bits, enum nmt_direction direction, int callack);

View File

@ -524,7 +524,7 @@ static int match_subscriber(nmt_t *nmt, frame_t *frame)
static void tx_ident(nmt_t *nmt, frame_t *frame)
{
frame->index = NMT_MESSAGE_3b;
frame->mt = NMT_MESSAGE_3b;
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
frame->traffic_area = nmt->sysinfo.traffic_area;
frame->ms_country = nmt_digits2value(&nmt->subscriber.country, 1);
@ -534,7 +534,7 @@ static void tx_ident(nmt_t *nmt, frame_t *frame)
static void set_line_signal(nmt_t *nmt, frame_t *frame, uint8_t signal)
{
frame->index = NMT_MESSAGE_5a;
frame->mt = NMT_MESSAGE_5a;
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
frame->traffic_area = nmt->sysinfo.traffic_area;
frame->ms_country = nmt_digits2value(&nmt->subscriber.country, 1);
@ -564,7 +564,7 @@ static int encode_a_number(nmt_t *nmt, frame_t *frame, int index, enum number_ty
number_offset = index * 7 - 2;
/* encode */
frame->index = NMT_MESSAGE_8;
frame->mt = NMT_MESSAGE_8;
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
frame->traffic_area = nmt->sysinfo.traffic_area;
frame->seq_number = index;
@ -630,16 +630,16 @@ static void tx_idle(nmt_t *nmt, frame_t *frame)
{
switch (nmt->sysinfo.chan_type) {
case CHAN_TYPE_CC:
frame->index = NMT_MESSAGE_1a;
frame->mt = NMT_MESSAGE_1a;
break;
case CHAN_TYPE_TC:
frame->index = NMT_MESSAGE_4;
frame->mt = NMT_MESSAGE_4;
break;
case CHAN_TYPE_CC_TC:
frame->index = NMT_MESSAGE_1b;
frame->mt = NMT_MESSAGE_1b;
break;
case CHAN_TYPE_TEST:
frame->index = NMT_MESSAGE_30;
frame->mt = NMT_MESSAGE_30;
break;
}
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
@ -649,7 +649,7 @@ static void tx_idle(nmt_t *nmt, frame_t *frame)
static void rx_idle(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_11a: /* roaming update and seizure */
if (!match_channel(nmt, frame))
break;
@ -675,7 +675,7 @@ static void rx_idle(nmt_t *nmt, frame_t *frame)
/* set subscriber */
nmt_value2digits(frame->ms_country, &nmt->subscriber.country, 1);
nmt_value2digits(frame->ms_number, nmt->subscriber.number, 6);
if (frame->index == NMT_MESSAGE_12)
if (frame->mt == NMT_MESSAGE_12)
nmt->subscriber.coinbox = 1;
nmt->subscriber.number[6] = '\0';
@ -689,7 +689,7 @@ static void rx_idle(nmt_t *nmt, frame_t *frame)
case NMT_MESSAGE_13a: /* line signal */
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -709,7 +709,7 @@ static void tx_roaming_ident(nmt_t *nmt, frame_t *frame)
static void rx_roaming_ident(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_11a: /* roaming update */
if (!match_channel(nmt, frame))
break;
@ -727,7 +727,7 @@ static void rx_roaming_ident(nmt_t *nmt, frame_t *frame)
nmt->tx_frame_count = 0;
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -742,9 +742,9 @@ static void tx_roaming_confirm(nmt_t *nmt, frame_t *frame)
static void rx_roaming_confirm(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -764,7 +764,7 @@ static void tx_mo_ident(nmt_t *nmt, frame_t *frame)
static void rx_mo_ident(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_10b: /* seizure */
case NMT_MESSAGE_12: /* seizure */
if (!match_channel(nmt, frame))
@ -781,7 +781,7 @@ static void rx_mo_ident(nmt_t *nmt, frame_t *frame)
nmt->tx_frame_count = 0;
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -805,7 +805,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame)
{
int len = strlen(nmt->dialing);
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_14a: /* digits */
if (!match_channel(nmt, frame))
break;
@ -881,7 +881,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame)
nmt->tx_frame_count = 0;
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
return;
@ -903,7 +903,7 @@ static void tx_mo_complete(nmt_t *nmt, frame_t *frame)
if (nmt->tx_frame_count == 5)
PDEBUG(DNMT, DEBUG_INFO, "Send 'compandor in'.\n");
} else
frame->index = NMT_MESSAGE_6;
frame->mt = NMT_MESSAGE_6;
if (nmt->tx_frame_count == 9) {
PDEBUG(DNMT, DEBUG_INFO, "Connect audio.\n");
nmt_new_state(nmt, STATE_ACTIVE);
@ -931,7 +931,7 @@ static void timeout_mo_dialing(nmt_t *nmt)
*/
static void tx_mt_paging(nmt_t *nmt, frame_t *frame)
{
frame->index = NMT_MESSAGE_2a;
frame->mt = NMT_MESSAGE_2a;
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
frame->traffic_area = nmt->sysinfo.traffic_area;
frame->ms_country = nmt_digits2value(&nmt->subscriber.country, 1);
@ -962,7 +962,7 @@ static void tx_mt_paging(nmt_t *nmt, frame_t *frame)
static void rx_mt_paging(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_10a: /* call acknowledgement */
if (!match_channel(nmt, frame))
break;
@ -980,13 +980,13 @@ static void rx_mt_paging(nmt_t *nmt, frame_t *frame)
}
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
static void tx_mt_channel(nmt_t *nmt, frame_t *frame)
{
frame->index = NMT_MESSAGE_2b;
frame->mt = NMT_MESSAGE_2b;
frame->channel_no = nmt_encode_channel(nmt->sender.kanal, nmt->sysinfo.ms_power);
frame->traffic_area = nmt->sysinfo.traffic_area;
frame->ms_country = nmt_digits2value(&nmt->subscriber.country, 1);
@ -1016,7 +1016,7 @@ static void tx_mt_ident(nmt_t *nmt, frame_t *frame)
static void rx_mt_ident(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_10b: /* seizure */
if (!match_subscriber(nmt, frame))
break;
@ -1041,7 +1041,7 @@ static void rx_mt_ident(nmt_t *nmt, frame_t *frame)
}
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -1049,7 +1049,7 @@ static void tx_mt_autoanswer(nmt_t *nmt, frame_t *frame)
{
/* first we need to wait for autoanswer */
if (nmt->wait_autoanswer) {
frame->index = NMT_MESSAGE_6;
frame->mt = NMT_MESSAGE_6;
return;
}
if (++nmt->tx_frame_count == 1)
@ -1067,7 +1067,7 @@ static void tx_mt_autoanswer(nmt_t *nmt, frame_t *frame)
static void rx_mt_autoanswer(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_15: /* idle */
nmt->wait_autoanswer = 0;
break;
@ -1084,7 +1084,7 @@ static void rx_mt_autoanswer(nmt_t *nmt, frame_t *frame)
call_in_answer(nmt->sender.callref, &nmt->subscriber.country);
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -1099,7 +1099,7 @@ static void tx_mt_ringing(nmt_t *nmt, frame_t *frame)
PDEBUG(DNMT, DEBUG_INFO, "Send 'A-number'.\n");
encode_a_number(nmt, frame, nmt->tx_frame_count - 4, nmt->caller_type, nmt->caller_id);
} else
frame->index = NMT_MESSAGE_6;
frame->mt = NMT_MESSAGE_6;
}
if (nmt->tx_callerid_count == 1) {
/* start ringing after first caller ID of 6 frames */
@ -1117,7 +1117,7 @@ static void tx_mt_ringing(nmt_t *nmt, frame_t *frame)
static void rx_mt_ringing(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_13a: /* line signal */
if (!match_channel(nmt, frame))
break;
@ -1131,7 +1131,7 @@ static void rx_mt_ringing(nmt_t *nmt, frame_t *frame)
call_in_answer(nmt->sender.callref, &nmt->subscriber.country);
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -1143,7 +1143,7 @@ static void tx_mt_complete(nmt_t *nmt, frame_t *frame)
PDEBUG(DNMT, DEBUG_INFO, "Send 'compandor in'.\n");
set_line_signal(nmt, frame, 5);
} else
frame->index = NMT_MESSAGE_6;
frame->mt = NMT_MESSAGE_6;
if (nmt->tx_frame_count == 5) {
PDEBUG(DNMT, DEBUG_INFO, "Connect audio.\n");
nmt_new_state(nmt, STATE_ACTIVE);
@ -1195,7 +1195,7 @@ static void tx_mt_release(nmt_t *nmt, frame_t *frame)
static void rx_mt_release(nmt_t *nmt, frame_t *frame)
{
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_13a: /* line signal */
if (!match_channel(nmt, frame))
break;
@ -1207,7 +1207,7 @@ static void rx_mt_release(nmt_t *nmt, frame_t *frame)
nmt_go_idle(nmt);
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -1261,7 +1261,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
if (nmt->supervisory)
timer_start(&nmt->timer, SUPERVISORY_TO2);
switch (frame->index) {
switch (frame->mt) {
case NMT_MESSAGE_13a: /* line signal */
if (!match_channel(nmt, frame))
break;
@ -1319,7 +1319,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
nmt->mft_num++;
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state));
}
}
@ -1371,13 +1371,13 @@ void nmt_receive_frame(nmt_t *nmt, const char *bits, double quality, double leve
/* frame counter */
nmt->rx_frame_count += (int)(frames_elapsed + 0.5);
PDEBUG(DNMT, (nmt->sender.loopback) ? DEBUG_NOTICE : DEBUG_DEBUG, "Received frame %s\n", nmt_frame_name(frame.index));
PDEBUG(DNMT, (nmt->sender.loopback) ? DEBUG_NOTICE : DEBUG_DEBUG, "Received frame %s\n", nmt_frame_name(frame.mt));
if (nmt->sender.loopback)
return;
/* MS releases, but this is not the acknowledge of MTX release */
if (frame.index == NMT_MESSAGE_13a
if (frame.mt == NMT_MESSAGE_13a
&& (frame.line_signal & 0xf) == 1
&& nmt->state != STATE_MO_RELEASE
&& nmt->state != STATE_MT_RELEASE) {
@ -1436,7 +1436,7 @@ void nmt_receive_frame(nmt_t *nmt, const char *bits, double quality, double leve
rx_active(nmt, &frame);
break;
default:
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame.index), nmt_state_name(nmt->state));
PDEBUG(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame.mt), nmt_state_name(nmt->state));
}
}
@ -1524,13 +1524,15 @@ const char *nmt_get_frame(nmt_t *nmt)
}
/* no encoding debug for certain (idle) frames */
switch(frame.index) {
switch(frame.mt) {
case NMT_MESSAGE_1a:
case NMT_MESSAGE_4:
case NMT_MESSAGE_1b:
case NMT_MESSAGE_30:
debug = 0;
break;
default:
break;
}
/* frame sending aborted (e.g. due to audio) */
@ -1539,7 +1541,7 @@ const char *nmt_get_frame(nmt_t *nmt)
bits = encode_frame(&frame, debug);
PDEBUG(DNMT, DEBUG_DEBUG, "Sending frame %s.\n", nmt_frame_name(frame.index));
PDEBUG(DNMT, DEBUG_DEBUG, "Sending frame %s.\n", nmt_frame_name(frame.mt));
return bits;
}