aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-10-08 17:10:03 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2017-10-22 19:23:04 +0200
commitf7476bce41c8efbfc8239c2c239e5a2cee8a7bcf (patch)
treeff0c7093d6a21fd469432252379e47624de79461
parent3218d1a8e0059157346aced9bdc4da47a1d66ff1 (diff)
NMT-900: Handle channels >= 1025 correctly
-rw-r--r--src/nmt/frame.c8
-rw-r--r--src/nmt/nmt.c10
2 files changed, 12 insertions, 6 deletions
diff --git a/src/nmt/frame.c b/src/nmt/frame.c
index e25698a..ace9d1f 100644
--- a/src/nmt/frame.c
+++ b/src/nmt/frame.c
@@ -47,8 +47,8 @@ uint64_t nmt_encode_channel(int nmt_system, int channel, int power)
value |= power << 9;
} else {
/* interleaved channels are indicated in traffic area */
- if (value > 1000)
- value -= 1000;
+ if (value >= 1024)
+ value -= 1024;
value |= channel;
/* if channel >= 512, set upper bit */
if (value & 0x200)
@@ -132,7 +132,7 @@ uint64_t nmt_encode_traffic_area(int nmt_system, int channel, uint8_t traffic_ar
} else {
/* upper bit is used for indication of interleaved channel */
value = traffic_area & 0x7f;
- if (channel > 1000)
+ if (channel >= 1024)
value |= 0x80;
}
@@ -487,7 +487,7 @@ static const char *param_ta_900(uint64_t value, int __attribute__((unused)) ndig
static char result[32];
if ((value & 0x80))
- sprintf(result, "%" PRIu64 " (Channel No. + 1000)", value & 0x7f);
+ sprintf(result, "%" PRIu64 " (Channel No. + 1024)", value & 0x7f);
else
sprintf(result, "%" PRIu64, value);
diff --git a/src/nmt/nmt.c b/src/nmt/nmt.c
index b5aec38..40d8727 100644
--- a/src/nmt/nmt.c
+++ b/src/nmt/nmt.c
@@ -490,10 +490,16 @@ static void nmt_page(transaction_t *trans, int try)
static int match_channel(nmt_t *nmt, frame_t *frame)
{
int channel, power;
+ int rc;
/* check channel match */
- nmt_decode_channel(nmt->sysinfo.system, frame->channel_no, &channel, &power);
- if ((channel & 0x3ff) != (nmt->sender.kanal & 0x3ff)) {
+ rc = nmt_decode_channel(nmt->sysinfo.system, frame->channel_no, &channel, &power);
+ if (rc < 0) {
+ PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Frame with illegal encoded channel received, ignoring.\n");
+ return 0;
+ }
+ /* in case of interleaved channel, ignore the missing upper bit */
+ if ((channel % 1024) != (nmt->sender.kanal % 1024)) {
PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Frame for different channel %d received, ignoring.\n", channel);
return 0;
}