1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
add_test(function test_ril_worker_GsmPDUHelper_readCbDataCodingScheme() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
function test_dcs(dcs, encoding, language, hasLanguageIndicator, messageClass) {
context.Buf.readUint8 = function() {
return dcs;
};
let msg = {};
context.GsmPDUHelper.readCbDataCodingScheme(msg);
equal(msg.dcs, dcs);
equal(msg.encoding, encoding);
equal(msg.language, language);
equal(msg.hasLanguageIndicator, hasLanguageIndicator);
equal(msg.messageClass, messageClass);
}
function test_dcs_throws(dcs) {
context.Buf.readUint8 = function() {
return dcs;
};
throws(function() {
context.GsmPDUHelper.readCbDataCodingScheme({});
}, "Unsupported CBS data coding scheme: " + dcs);
}
// Group 0000
for (let i = 0; i < 16; i++) {
test_dcs(i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, CB_DCS_LANG_GROUP_1[i],
false, GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
}
// Group 0001
// 0000 GSM 7 bit default alphabet; message preceded by language indication.
test_dcs(0x10, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true,
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
// 0001 UCS2; message preceded by language indication.
test_dcs(0x11, PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true,
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
// Group 0010
// 0000..0100
for (let i = 0; i < 5; i++) {
test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET,
CB_DCS_LANG_GROUP_2[i], false,
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
}
// 0101..1111 Reserved
for (let i = 5; i < 16; i++) {
test_dcs(0x20 + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
}
// Group 0100, 0101, 1001
for (let group of [0x40, 0x50, 0x90]) {
for (let i = 0; i < 16; i++) {
let encoding = i & 0x0C;
if (encoding == 0x0C) {
encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET;
}
let messageClass = GECKO_SMS_MESSAGE_CLASSES[i & PDU_DCS_MSG_CLASS_BITS];
test_dcs(group + i, encoding, null, false, messageClass);
}
}
// Group 1111
for (let i = 0; i < 16; i ++) {
let encoding = i & 0x04 ? PDU_DCS_MSG_CODING_8BITS_ALPHABET
: PDU_DCS_MSG_CODING_7BITS_ALPHABET;
let messageClass;
switch(i & PDU_DCS_MSG_CLASS_BITS) {
case 0x01: messageClass = PDU_DCS_MSG_CLASS_USER_1; break;
case 0x02: messageClass = PDU_DCS_MSG_CLASS_USER_2; break;
case 0x03: messageClass = PDU_DCS_MSG_CLASS_3; break;
default: messageClass = PDU_DCS_MSG_CLASS_NORMAL; break;
}
test_dcs(0xF0 + i, encoding, null, false,
GECKO_SMS_MESSAGE_CLASSES[messageClass]);
}
// Group 0011, 1000, 1010, 1011, 1100
// 0000..1111 Reserved
for (let group of [0x30, 0x80, 0xA0, 0xB0, 0xC0]) {
for (let i = 0; i < 16; i++) {
test_dcs(group + i, PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL]);
}
}
// Group 0110, 0111, 1101, 1110
// TODO: unsupported
for (let group of [0x60, 0x70, 0xD0, 0xE0]) {
for (let i = 0; i < 16; i++) {
test_dcs_throws(group + i);
}
}
run_next_test();
});
add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
function test_data(options, expected) {
let readIndex = 0;
context.Buf.readUint8 = function() {
return options[3][readIndex++];
};
context.Buf.readUint8Array = function(length) {
let array = new Uint8Array(length);
for (let i = 0; i < length; i++) {
array[i] = this.readUint8();
}
return array;
};
let msg = {
encoding: options[0],
language: options[1],
hasLanguageIndicator: options[2]
};
context.GsmPDUHelper.readGsmCbData(msg, options[3].length);
equal(msg.body, expected[0]);
equal(msg.data == null, expected[1] == null);
if (expected[1] != null) {
equal(msg.data.length, expected[1].length);
for (let i = 0; i < expected[1].length; i++) {
equal(msg.data[i], expected[1][i]);
}
}
equal(msg.language, expected[2]);
}
// We're testing Cell Broadcast message body with all zeros octet stream. As
// shown in 3GPP TS 23.038, septet 0x00 will be decoded as '@' when both
// langTableIndex and langShiftTableIndex equal to
// PDU_DCS_MSG_CODING_7BITS_ALPHABET.
// PDU_DCS_MSG_CODING_7BITS_ALPHABET
test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, false,
[0]],
["@", null, null]);
test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, null, true,
[0, 0, 0, 0]],
["@", null, "@@"]);
test_data([PDU_DCS_MSG_CODING_7BITS_ALPHABET, "@@", false,
[0]],
["@", null, "@@"]);
// PDU_DCS_MSG_CODING_8BITS_ALPHABET
test_data([PDU_DCS_MSG_CODING_8BITS_ALPHABET, null, false,
[0]],
[null, [0], null]);
// PDU_DCS_MSG_CODING_16BITS_ALPHABET
test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, false,
[0x00, 0x40]],
["@", null, null]);
test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, null, true,
[0x00, 0x00, 0x00, 0x40]],
["@", null, "@@"]);
test_data([PDU_DCS_MSG_CODING_16BITS_ALPHABET, "@@", false,
[0x00, 0x40]],
["@", null, "@@"]);
run_next_test();
});
add_test(function test_ril_worker_Sim_Download_Message() {
let worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
ok(message.rilMessageType !== "cellbroadcast-received",
"Data-Download message shall be ignored.");
}
});
function buildPdu(aMessageId) {
return "C002" + aMessageId + "011154741914AFA7C76B9058" +
"FEBEBB41E6371EA4AEB7E173D0DB5E96" +
"83E8E832881DD6E741E4F7B9D168341A" +
"8D46A3D168341A8D46A3D168341A8D46" +
"A3D168341A8D46A3D168341A8D46A3D1" +
"68341A8D46A3D100";
}
["1000", "107F", "1080", "10FF"].forEach(aMessageId => {
worker.onRILMessage(
0,
newIncomingParcel(
-1,
RESPONSE_TYPE_UNSOLICITED,
UNSOLICITED_RESPONSE_NEW_BROADCAST_SMS,
hexStringToParcelByteArrayData(buildPdu(aMessageId))));
});
ok(true, "All Data-Download Messages are ingored.");
run_next_test();
});
|