New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widen the range of allowed cell broadcast channels #35
Conversation
|
Couple of comments.
|
|
And sorry for the delay |
|
@monich No worries, I updated as you suggested... |
|
And this is how it looks from valgrind's point of view: |
|
BTW, the test itself needs to be updated e.g. --- a/ofono/unit/test-sms.c
+++ b/ofono/unit/test-sms.c
@@ -1589,7 +1589,7 @@ static void test_cbs_padding_character(void)
static const char *ranges[] = { "1-5, 2, 3, 600, 569-900, 999",
"0-20, 33, 44, 50-60, 20-50, 1-5, 5, 3, 5",
NULL };
-static const char *inv_ranges[] = { "1-5, 3333", "1-5, afbcd", "1-5, 3-5,,",
+static const char *inv_ranges[] = { "1-5, 33333", "1-5, afbcd", "1-5, 3-5,,",
"1-5, 3-5, c", NULL };
static void test_range_minimizer(void)
|
| @@ -4593,12 +4593,13 @@ static gboolean next_range(const char *str, int *offset, gint *min, gint *max) | |||
| GSList *cbs_optimize_ranges(GSList *ranges) | |||
| { | |||
| struct cbs_topic_range *range; | |||
| unsigned char bitmap[125]; | |||
| int bitmap_len = CBS_MAX_TOPIC / 8 + 1; | |||
| unsigned char (*bitmap)[bitmap_len]; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with just one line:
unsigned char *bitmap = g_malloc0(CBS_MAX_TOPIC / 8 + 1);| GSList *l; | ||
| unsigned short i; | ||
| GSList *ret = NULL; | ||
|
|
||
| memset(bitmap, 0, sizeof(bitmap)); | ||
| bitmap = g_malloc0(bitmap_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then this memset can just be deleted
| @@ -4607,17 +4608,17 @@ GSList *cbs_optimize_ranges(GSList *ranges) | |||
| int byte_offset = i / 8; | |||
| int bit = i % 8; | |||
|
|
|||
| bitmap[byte_offset] |= 1 << bit; | |||
| *bitmap[byte_offset] |= 1 << bit; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this isn't necessary (besides this extra indirection seems to be wrong)
| int byte_offset = i / 8; | ||
| int bit = i % 8; | ||
|
|
||
| if (is_bit_set(bitmap[byte_offset], bit) == FALSE) { | ||
| if (is_bit_set(*bitmap[byte_offset], bit) == FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this too is unnecessary
|
All the necessary necessary changes can be reduced to something like this: diff --git a/ofono/src/cbs.c b/ofono/src/cbs.c
index 8e3296b1..800aee8b 100644
--- a/ofono/src/cbs.c
+++ b/ofono/src/cbs.c
@@ -771,7 +771,7 @@ static void sim_cbmi_read_cb(int ok, int length, int record,
mi = (data[i] << 8) + data[i+1];
- if (mi > 999)
+ if (mi > CBS_MAX_TOPIC)
continue;
range = g_new0(struct cbs_topic_range, 1);
@@ -818,7 +818,7 @@ static void sim_cbmir_read_cb(int ok, int length, int record,
min = (data[i] << 8) + data[i+1];
max = (data[i+2] << 8) + data[i+3];
- if (min > 999 || max > 999 || min > max)
+ if (min > CBS_MAX_TOPIC || max > CBS_MAX_TOPIC || min > max)
continue;
range = g_new0(struct cbs_topic_range, 1);
diff --git a/ofono/src/smsutil.c b/ofono/src/smsutil.c
index d3d22243..29a6462f 100644
--- a/ofono/src/smsutil.c
+++ b/ofono/src/smsutil.c
@@ -4593,13 +4593,11 @@ out:
GSList *cbs_optimize_ranges(GSList *ranges)
{
struct cbs_topic_range *range;
- unsigned char bitmap[125];
+ unsigned char *bitmap = g_malloc0(CBS_MAX_TOPIC / 8 + 1);
GSList *l;
unsigned short i;
GSList *ret = NULL;
- memset(bitmap, 0, sizeof(bitmap));
-
for (l = ranges; l; l = l->next) {
range = l->data;
@@ -4613,7 +4611,7 @@ GSList *cbs_optimize_ranges(GSList *ranges)
range = NULL;
- for (i = 0; i <= 999; i++) {
+ for (i = 0; i <= CBS_MAX_TOPIC; i++) {
int byte_offset = i / 8;
int bit = i % 8;
@@ -4641,6 +4639,7 @@ GSList *cbs_optimize_ranges(GSList *ranges)
ret = g_slist_reverse(ret);
+ g_free(bitmap);
return ret;
}
@@ -4653,10 +4652,10 @@ GSList *cbs_extract_topic_ranges(const char *ranges)
GSList *tmp;
while (next_range(ranges, &offset, &min, &max) == TRUE) {
- if (min < 0 || min > 999)
+ if (min < 0 || min > CBS_MAX_TOPIC)
return NULL;
- if (max < 0 || max > 999)
+ if (max < 0 || max > CBS_MAX_TOPIC)
return NULL;
if (max < min)
diff --git a/ofono/src/smsutil.h b/ofono/src/smsutil.h
index 6197470a..ddd92143 100644
--- a/ofono/src/smsutil.h
+++ b/ofono/src/smsutil.h
@@ -23,6 +23,7 @@
#include <ofono/types.h>
#define CBS_MAX_GSM_CHARS 93
+#define CBS_MAX_TOPIC 9999
#define SMS_MSGID_LEN 20
enum sms_type {
diff --git a/ofono/unit/test-sms.c b/ofono/unit/test-sms.c
index 5ce262cf..95a60896 100644
--- a/ofono/unit/test-sms.c
+++ b/ofono/unit/test-sms.c
@@ -1589,7 +1589,7 @@ static void test_cbs_padding_character(void)
static const char *ranges[] = { "1-5, 2, 3, 600, 569-900, 999",
"0-20, 33, 44, 50-60, 20-50, 1-5, 5, 3, 5",
NULL };
-static const char *inv_ranges[] = { "1-5, 3333", "1-5, afbcd", "1-5, 3-5,,",
+static const char *inv_ranges[] = { "1-5, 33333", "1-5, afbcd", "1-5, 3-5,,",
"1-5, 3-5, c", NULL };
static void test_range_minimizer(void) |
|
I just pushed an alternative minimal PR #37 |
|
Very cool, then this can be closed :) |
|
Merged #37, closing this one. |
In fact cell broadcast can subscribe to topics up to 9999 so lets remove that restriction