Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ofono/src/cbs.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 9 additions & 7 deletions ofono/src/smsutil.c
Expand Up @@ -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];
Copy link
Member

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);
Copy link
Member

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


for (l = ranges; l; l = l->next) {
range = l->data;
Expand All @@ -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;
Copy link
Member

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)

}
}

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;

if (is_bit_set(bitmap[byte_offset], bit) == FALSE) {
if (is_bit_set(*bitmap[byte_offset], bit) == FALSE) {
Copy link
Member

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

if (range) {
ret = g_slist_prepend(ret, range);
range = NULL;
Expand All @@ -4641,6 +4642,7 @@ GSList *cbs_optimize_ranges(GSList *ranges)

ret = g_slist_reverse(ret);

g_free(bitmap);
return ret;
}

Expand All @@ -4653,10 +4655,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)
Expand Down
1 change: 1 addition & 0 deletions ofono/src/smsutil.h
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions ofono/test/test-cbs
Expand Up @@ -6,6 +6,8 @@ import sys
from gi.repository import GLib
import os

MAX_TOPIC = 9999

def print_menu():
print("Select test case")
print("----------------------------------------------------------------")
Expand Down Expand Up @@ -92,9 +94,9 @@ def set_topics(cbs):
break

if topicTemp:
if int(topicTemp) > 999:
if int(topicTemp) > MAX_TOPIC:
invalidData = True
print("Invalid Topic ID %s (range 0-999). \
print("Invalid Topic ID %s (range 0-{MAX_TOPIC}). \
\nCould not register." % topicTemp)

index = index + 1
Expand Down