2011-12-04 23:58:27 -08:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is RIL JS Worker.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Kyle Machulis <kyle@nonpolynomial.com>
|
|
|
|
* Philipp von Weitershausen <philipp@weitershausen.de>
|
2011-12-23 21:02:51 -08:00
|
|
|
* Fernando Jimenez <ferjmoreno@gmail.com>
|
2011-12-04 23:58:27 -08:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file implements the RIL worker thread. It communicates with
|
|
|
|
* the main thread to provide a high-level API to the phone's RIL
|
|
|
|
* stack, and with the RIL IPC thread to communicate with the RIL
|
|
|
|
* device itself. These communication channels use message events as
|
|
|
|
* known from Web Workers:
|
|
|
|
*
|
|
|
|
* - postMessage()/"message" events for main thread communication
|
|
|
|
*
|
|
|
|
* - postRILMessage()/"RILMessageEvent" events for RIL IPC thread
|
|
|
|
* communication.
|
|
|
|
*
|
2012-03-15 18:01:24 -07:00
|
|
|
* The two main objects in this file represent individual parts of this
|
2011-12-04 23:58:27 -08:00
|
|
|
* communication chain:
|
2011-12-16 13:47:32 -08:00
|
|
|
*
|
2012-03-15 18:01:24 -07:00
|
|
|
* - RILMessageEvent -> Buf -> RIL -> postMessage() -> nsIRadioInterfaceLayer
|
|
|
|
* - nsIRadioInterfaceLayer -> postMessage() -> RIL -> Buf -> postRILMessage()
|
2011-12-04 23:58:27 -08:00
|
|
|
*
|
|
|
|
* Note: The code below is purposely lean on abstractions to be as lean in
|
|
|
|
* terms of object allocations. As a result, it may look more like C than
|
|
|
|
* JavaScript, and that's intended.
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-02 10:41:07 -08:00
|
|
|
importScripts("ril_consts.js", "systemlibs.js");
|
2011-12-04 23:58:27 -08:00
|
|
|
|
2012-02-20 10:30:05 -08:00
|
|
|
// We leave this as 'undefined' instead of setting it to 'false'. That
|
|
|
|
// way an outer scope can define it to 'true' (e.g. for testing purposes)
|
|
|
|
// without us overriding that here.
|
|
|
|
let DEBUG;
|
2011-12-04 23:58:27 -08:00
|
|
|
|
|
|
|
const INT32_MAX = 2147483647;
|
|
|
|
const UINT8_SIZE = 1;
|
|
|
|
const UINT16_SIZE = 2;
|
|
|
|
const UINT32_SIZE = 4;
|
|
|
|
const PARCEL_SIZE_SIZE = UINT32_SIZE;
|
|
|
|
|
2012-02-02 10:41:07 -08:00
|
|
|
let RILQUIRKS_CALLSTATE_EXTRA_UINT32 = false;
|
2012-03-12 16:45:57 -07:00
|
|
|
let RILQUIRKS_DATACALLSTATE_DOWN_IS_UP = false;
|
2012-03-20 12:28:15 -07:00
|
|
|
// This flag defaults to true since on RIL v6 and later, we get the
|
|
|
|
// version number via the UNSOLICITED_RIL_CONNECTED parcel.
|
|
|
|
let RILQUIRKS_V5_LEGACY = true;
|
2012-02-02 10:41:07 -08:00
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* This object contains helpers buffering incoming data & deconstructing it
|
|
|
|
* into parcels as well as buffering outgoing data & constructing parcels.
|
|
|
|
* For that it maintains two buffers and corresponding uint8 views, indexes.
|
|
|
|
*
|
|
|
|
* The incoming buffer is a circular buffer where we store incoming data.
|
|
|
|
* As soon as a complete parcel is received, it is processed right away, so
|
|
|
|
* the buffer only needs to be large enough to hold one parcel.
|
|
|
|
*
|
|
|
|
* The outgoing buffer is to prepare outgoing parcels. The index is reset
|
|
|
|
* every time a parcel is sent.
|
|
|
|
*/
|
|
|
|
let Buf = {
|
|
|
|
|
|
|
|
INCOMING_BUFFER_LENGTH: 1024,
|
|
|
|
OUTGOING_BUFFER_LENGTH: 1024,
|
|
|
|
|
|
|
|
init: function init() {
|
|
|
|
this.incomingBuffer = new ArrayBuffer(this.INCOMING_BUFFER_LENGTH);
|
|
|
|
this.outgoingBuffer = new ArrayBuffer(this.OUTGOING_BUFFER_LENGTH);
|
|
|
|
|
|
|
|
this.incomingBytes = new Uint8Array(this.incomingBuffer);
|
|
|
|
this.outgoingBytes = new Uint8Array(this.outgoingBuffer);
|
|
|
|
|
|
|
|
// Track where incoming data is read from and written to.
|
|
|
|
this.incomingWriteIndex = 0;
|
|
|
|
this.incomingReadIndex = 0;
|
|
|
|
|
|
|
|
// Leave room for the parcel size for outgoing parcels.
|
|
|
|
this.outgoingIndex = PARCEL_SIZE_SIZE;
|
|
|
|
|
|
|
|
// How many bytes we've read for this parcel so far.
|
|
|
|
this.readIncoming = 0;
|
|
|
|
|
2012-02-20 10:30:04 -08:00
|
|
|
// How many bytes available as parcel data.
|
|
|
|
this.readAvailable = 0;
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
// Size of the incoming parcel. If this is zero, we're expecting a new
|
|
|
|
// parcel.
|
|
|
|
this.currentParcelSize = 0;
|
|
|
|
|
|
|
|
// This gets incremented each time we send out a parcel.
|
|
|
|
this.token = 1;
|
|
|
|
|
|
|
|
// Maps tokens we send out with requests to the request type, so that
|
|
|
|
// when we get a response parcel back, we know what request it was for.
|
|
|
|
this.tokenRequestMap = {};
|
2012-01-17 17:34:09 -08:00
|
|
|
|
|
|
|
// This is the token of last solicited response.
|
|
|
|
this.lastSolicitedToken = 0;
|
2011-12-04 23:58:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grow the incoming buffer.
|
|
|
|
*
|
|
|
|
* @param min_size
|
|
|
|
* Minimum new size. The actual new size will be the the smallest
|
|
|
|
* power of 2 that's larger than this number.
|
|
|
|
*/
|
|
|
|
growIncomingBuffer: function growIncomingBuffer(min_size) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Current buffer of " + this.INCOMING_BUFFER_LENGTH +
|
|
|
|
" can't handle incoming " + min_size + " bytes.");
|
|
|
|
}
|
|
|
|
let oldBytes = this.incomingBytes;
|
|
|
|
this.INCOMING_BUFFER_LENGTH =
|
|
|
|
2 << Math.floor(Math.log(min_size)/Math.log(2));
|
|
|
|
if (DEBUG) debug("New incoming buffer size: " + this.INCOMING_BUFFER_LENGTH);
|
|
|
|
this.incomingBuffer = new ArrayBuffer(this.INCOMING_BUFFER_LENGTH);
|
|
|
|
this.incomingBytes = new Uint8Array(this.incomingBuffer);
|
|
|
|
if (this.incomingReadIndex <= this.incomingWriteIndex) {
|
|
|
|
// Read and write index are in natural order, so we can just copy
|
|
|
|
// the old buffer over to the bigger one without having to worry
|
|
|
|
// about the indexes.
|
|
|
|
this.incomingBytes.set(oldBytes, 0);
|
|
|
|
} else {
|
|
|
|
// The write index has wrapped around but the read index hasn't yet.
|
|
|
|
// Write whatever the read index has left to read until it would
|
|
|
|
// circle around to the beginning of the new buffer, and the rest
|
|
|
|
// behind that.
|
|
|
|
let head = oldBytes.subarray(this.incomingReadIndex);
|
|
|
|
let tail = oldBytes.subarray(0, this.incomingReadIndex);
|
|
|
|
this.incomingBytes.set(head, 0);
|
|
|
|
this.incomingBytes.set(tail, head.length);
|
|
|
|
this.incomingReadIndex = 0;
|
|
|
|
this.incomingWriteIndex += head.length;
|
|
|
|
}
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("New incoming buffer size is " + this.INCOMING_BUFFER_LENGTH);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grow the outgoing buffer.
|
|
|
|
*
|
|
|
|
* @param min_size
|
|
|
|
* Minimum new size. The actual new size will be the the smallest
|
|
|
|
* power of 2 that's larger than this number.
|
|
|
|
*/
|
|
|
|
growOutgoingBuffer: function growOutgoingBuffer(min_size) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Current buffer of " + this.OUTGOING_BUFFER_LENGTH +
|
|
|
|
" is too small.");
|
|
|
|
}
|
|
|
|
let oldBytes = this.outgoingBytes;
|
|
|
|
this.OUTGOING_BUFFER_LENGTH =
|
|
|
|
2 << Math.floor(Math.log(min_size)/Math.log(2));
|
|
|
|
this.outgoingBuffer = new ArrayBuffer(this.OUTGOING_BUFFER_LENGTH);
|
|
|
|
this.outgoingBytes = new Uint8Array(this.outgoingBuffer);
|
|
|
|
this.outgoingBytes.set(oldBytes, 0);
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("New outgoing buffer size is " + this.OUTGOING_BUFFER_LENGTH);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for reading data from the incoming buffer.
|
|
|
|
*
|
|
|
|
* These are all little endian, apart from readParcelSize();
|
|
|
|
*/
|
|
|
|
|
2012-02-20 10:30:04 -08:00
|
|
|
readUint8Unchecked: function readUint8Unchecked() {
|
2011-12-04 23:58:27 -08:00
|
|
|
let value = this.incomingBytes[this.incomingReadIndex];
|
|
|
|
this.incomingReadIndex = (this.incomingReadIndex + 1) %
|
|
|
|
this.INCOMING_BUFFER_LENGTH;
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2012-02-20 10:30:04 -08:00
|
|
|
readUint8: function readUint8() {
|
|
|
|
if (!this.readAvailable) {
|
|
|
|
throw new Error("Trying to read data beyond the parcel end!");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.readAvailable--;
|
|
|
|
return this.readUint8Unchecked();
|
|
|
|
},
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
readUint16: function readUint16() {
|
|
|
|
return this.readUint8() | this.readUint8() << 8;
|
|
|
|
},
|
|
|
|
|
|
|
|
readUint32: function readUint32() {
|
|
|
|
return this.readUint8() | this.readUint8() << 8 |
|
|
|
|
this.readUint8() << 16 | this.readUint8() << 24;
|
|
|
|
},
|
|
|
|
|
|
|
|
readUint32List: function readUint32List() {
|
|
|
|
let length = this.readUint32();
|
|
|
|
let ints = [];
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
ints.push(this.readUint32());
|
|
|
|
}
|
|
|
|
return ints;
|
|
|
|
},
|
|
|
|
|
|
|
|
readString: function readString() {
|
|
|
|
let string_len = this.readUint32();
|
|
|
|
if (string_len < 0 || string_len >= INT32_MAX) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let s = "";
|
|
|
|
for (let i = 0; i < string_len; i++) {
|
|
|
|
s += String.fromCharCode(this.readUint16());
|
|
|
|
}
|
|
|
|
// Strings are \0\0 delimited, but that isn't part of the length. And
|
|
|
|
// if the string length is even, the delimiter is two characters wide.
|
|
|
|
// It's insane, I know.
|
|
|
|
let delimiter = this.readUint16();
|
|
|
|
if (!(string_len & 1)) {
|
|
|
|
delimiter |= this.readUint16();
|
|
|
|
}
|
|
|
|
if (DEBUG) {
|
|
|
|
if (delimiter != 0) {
|
|
|
|
debug("Something's wrong, found string delimiter: " + delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
|
|
|
|
readStringList: function readStringList() {
|
|
|
|
let num_strings = this.readUint32();
|
|
|
|
let strings = [];
|
|
|
|
for (let i = 0; i < num_strings; i++) {
|
|
|
|
strings.push(this.readString());
|
|
|
|
}
|
|
|
|
return strings;
|
|
|
|
},
|
|
|
|
|
|
|
|
readParcelSize: function readParcelSize() {
|
2012-02-20 10:30:04 -08:00
|
|
|
return this.readUint8Unchecked() << 24 |
|
|
|
|
this.readUint8Unchecked() << 16 |
|
|
|
|
this.readUint8Unchecked() << 8 |
|
|
|
|
this.readUint8Unchecked();
|
2011-12-04 23:58:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for writing data to the outgoing buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
writeUint8: function writeUint8(value) {
|
|
|
|
if (this.outgoingIndex >= this.OUTGOING_BUFFER_LENGTH) {
|
|
|
|
this.growOutgoingBuffer(this.outgoingIndex + 1);
|
|
|
|
}
|
|
|
|
this.outgoingBytes[this.outgoingIndex] = value;
|
|
|
|
this.outgoingIndex++;
|
|
|
|
},
|
|
|
|
|
|
|
|
writeUint16: function writeUint16(value) {
|
|
|
|
this.writeUint8(value & 0xff);
|
|
|
|
this.writeUint8((value >> 8) & 0xff);
|
|
|
|
},
|
|
|
|
|
|
|
|
writeUint32: function writeUint32(value) {
|
|
|
|
this.writeUint8(value & 0xff);
|
|
|
|
this.writeUint8((value >> 8) & 0xff);
|
|
|
|
this.writeUint8((value >> 16) & 0xff);
|
|
|
|
this.writeUint8((value >> 24) & 0xff);
|
|
|
|
},
|
|
|
|
|
|
|
|
writeString: function writeString(value) {
|
|
|
|
if (value == null) {
|
|
|
|
this.writeUint32(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.writeUint32(value.length);
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
|
|
this.writeUint16(value.charCodeAt(i));
|
|
|
|
}
|
|
|
|
// Strings are \0\0 delimited, but that isn't part of the length. And
|
|
|
|
// if the string length is even, the delimiter is two characters wide.
|
|
|
|
// It's insane, I know.
|
|
|
|
this.writeUint16(0);
|
|
|
|
if (!(value.length & 1)) {
|
|
|
|
this.writeUint16(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
writeStringList: function writeStringList(strings) {
|
|
|
|
this.writeUint32(strings.length);
|
|
|
|
for (let i = 0; i < strings.length; i++) {
|
|
|
|
this.writeString(strings[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
writeParcelSize: function writeParcelSize(value) {
|
|
|
|
/**
|
|
|
|
* Parcel size will always be the first thing in the parcel byte
|
|
|
|
* array, but the last thing written. Store the current index off
|
|
|
|
* to a temporary to be reset after we write the size.
|
|
|
|
*/
|
|
|
|
let currentIndex = this.outgoingIndex;
|
|
|
|
this.outgoingIndex = 0;
|
|
|
|
this.writeUint8((value >> 24) & 0xff);
|
|
|
|
this.writeUint8((value >> 16) & 0xff);
|
|
|
|
this.writeUint8((value >> 8) & 0xff);
|
|
|
|
this.writeUint8(value & 0xff);
|
|
|
|
this.outgoingIndex = currentIndex;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parcel management
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write incoming data to the circular buffer.
|
|
|
|
*
|
|
|
|
* @param incoming
|
|
|
|
* Uint8Array containing the incoming data.
|
|
|
|
*/
|
|
|
|
writeToIncoming: function writeToIncoming(incoming) {
|
|
|
|
// We don't have to worry about the head catching the tail since
|
|
|
|
// we process any backlog in parcels immediately, before writing
|
|
|
|
// new data to the buffer. So the only edge case we need to handle
|
|
|
|
// is when the incoming data is larger than the buffer size.
|
|
|
|
if (incoming.length > this.INCOMING_BUFFER_LENGTH) {
|
|
|
|
this.growIncomingBuffer(incoming.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can let the typed arrays do the copying if the incoming data won't
|
|
|
|
// wrap around the edges of the circular buffer.
|
|
|
|
let remaining = this.INCOMING_BUFFER_LENGTH - this.incomingWriteIndex;
|
|
|
|
if (remaining >= incoming.length) {
|
|
|
|
this.incomingBytes.set(incoming, this.incomingWriteIndex);
|
|
|
|
} else {
|
|
|
|
// The incoming data would wrap around it.
|
|
|
|
let head = incoming.subarray(0, remaining);
|
|
|
|
let tail = incoming.subarray(remaining);
|
|
|
|
this.incomingBytes.set(head, this.incomingWriteIndex);
|
|
|
|
this.incomingBytes.set(tail, 0);
|
|
|
|
}
|
|
|
|
this.incomingWriteIndex = (this.incomingWriteIndex + incoming.length) %
|
|
|
|
this.INCOMING_BUFFER_LENGTH;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process incoming data.
|
|
|
|
*
|
|
|
|
* @param incoming
|
|
|
|
* Uint8Array containing the incoming data.
|
|
|
|
*/
|
|
|
|
processIncoming: function processIncoming(incoming) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Received " + incoming.length + " bytes.");
|
|
|
|
debug("Already read " + this.readIncoming);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.writeToIncoming(incoming);
|
|
|
|
this.readIncoming += incoming.length;
|
|
|
|
while (true) {
|
|
|
|
if (!this.currentParcelSize) {
|
|
|
|
// We're expecting a new parcel.
|
|
|
|
if (this.readIncoming < PARCEL_SIZE_SIZE) {
|
|
|
|
// We don't know how big the next parcel is going to be, need more
|
|
|
|
// data.
|
|
|
|
if (DEBUG) debug("Next parcel size unknown, going to sleep.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.currentParcelSize = this.readParcelSize();
|
|
|
|
if (DEBUG) debug("New incoming parcel of size " +
|
|
|
|
this.currentParcelSize);
|
|
|
|
// The size itself is not included in the size.
|
|
|
|
this.readIncoming -= PARCEL_SIZE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.readIncoming < this.currentParcelSize) {
|
|
|
|
// We haven't read enough yet in order to be able to process a parcel.
|
|
|
|
if (DEBUG) debug("Read " + this.readIncoming + ", but parcel size is "
|
|
|
|
+ this.currentParcelSize + ". Going to sleep.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alright, we have enough data to process at least one whole parcel.
|
|
|
|
// Let's do that.
|
|
|
|
let expectedAfterIndex = (this.incomingReadIndex + this.currentParcelSize)
|
|
|
|
% this.INCOMING_BUFFER_LENGTH;
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
let parcel;
|
|
|
|
if (expectedAfterIndex < this.incomingReadIndex) {
|
|
|
|
let head = this.incomingBytes.subarray(this.incomingReadIndex);
|
|
|
|
let tail = this.incomingBytes.subarray(0, expectedAfterIndex);
|
|
|
|
parcel = Array.slice(head).concat(Array.slice(tail));
|
|
|
|
} else {
|
|
|
|
parcel = Array.slice(this.incomingBytes.subarray(
|
|
|
|
this.incomingReadIndex, expectedAfterIndex));
|
|
|
|
}
|
|
|
|
debug("Parcel (size " + this.currentParcelSize + "): " + parcel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) debug("We have at least one complete parcel.");
|
|
|
|
try {
|
2012-02-20 10:30:04 -08:00
|
|
|
this.readAvailable = this.currentParcelSize;
|
2011-12-04 23:58:27 -08:00
|
|
|
this.processParcel();
|
|
|
|
} catch (ex) {
|
2011-12-23 21:02:51 -08:00
|
|
|
if (DEBUG) debug("Parcel handling threw " + ex + "\n" + ex.stack);
|
2011-12-04 23:58:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the whole parcel was consumed.
|
|
|
|
if (this.incomingReadIndex != expectedAfterIndex) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Parcel handler didn't consume whole parcel, " +
|
|
|
|
Math.abs(expectedAfterIndex - this.incomingReadIndex) +
|
|
|
|
" bytes left over");
|
|
|
|
}
|
|
|
|
this.incomingReadIndex = expectedAfterIndex;
|
|
|
|
}
|
|
|
|
this.readIncoming -= this.currentParcelSize;
|
2012-02-20 10:30:04 -08:00
|
|
|
this.readAvailable = 0;
|
2011-12-04 23:58:27 -08:00
|
|
|
this.currentParcelSize = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process one parcel.
|
|
|
|
*/
|
|
|
|
processParcel: function processParcel() {
|
|
|
|
let response_type = this.readUint32();
|
|
|
|
|
2012-02-19 15:44:29 -08:00
|
|
|
let request_type, options;
|
2011-12-04 23:58:27 -08:00
|
|
|
if (response_type == RESPONSE_TYPE_SOLICITED) {
|
|
|
|
let token = this.readUint32();
|
|
|
|
let error = this.readUint32();
|
2012-02-19 15:44:29 -08:00
|
|
|
|
|
|
|
options = this.tokenRequestMap[token];
|
2012-03-15 17:47:00 -07:00
|
|
|
delete this.tokenRequestMap[token];
|
2012-02-19 15:44:29 -08:00
|
|
|
request_type = options.rilRequestType;
|
2012-03-07 14:14:37 -08:00
|
|
|
|
|
|
|
options.rilRequestError = error;
|
2012-02-02 10:41:07 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
debug("Solicited response for request type " + request_type +
|
2012-04-05 14:16:56 -07:00
|
|
|
", token " + token + ", error " + error);
|
2012-02-02 10:41:07 -08:00
|
|
|
}
|
2011-12-04 23:58:27 -08:00
|
|
|
} else if (response_type == RESPONSE_TYPE_UNSOLICITED) {
|
|
|
|
request_type = this.readUint32();
|
2012-02-02 10:41:07 -08:00
|
|
|
if (DEBUG) debug("Unsolicited response for request type " + request_type);
|
2011-12-04 23:58:27 -08:00
|
|
|
} else {
|
2012-02-02 10:41:07 -08:00
|
|
|
if (DEBUG) debug("Unknown response type: " + response_type);
|
2011-12-04 23:58:27 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-20 10:30:04 -08:00
|
|
|
RIL.handleParcel(request_type, this.readAvailable, options);
|
2011-12-04 23:58:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start a new outgoing parcel.
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* Integer specifying the request type.
|
2012-02-19 15:44:29 -08:00
|
|
|
* @param options [optional]
|
|
|
|
* Object containing information about the request, e.g. the
|
2012-02-23 07:29:38 -08:00
|
|
|
* original main thread message object that led to the RIL request.
|
2011-12-04 23:58:27 -08:00
|
|
|
*/
|
2012-02-19 15:44:29 -08:00
|
|
|
newParcel: function newParcel(type, options) {
|
2012-02-10 11:27:38 -08:00
|
|
|
if (DEBUG) debug("New outgoing parcel of type " + type);
|
2011-12-04 23:58:27 -08:00
|
|
|
// We're going to leave room for the parcel size at the beginning.
|
|
|
|
this.outgoingIndex = PARCEL_SIZE_SIZE;
|
|
|
|
this.writeUint32(type);
|
|
|
|
let token = this.token;
|
|
|
|
this.writeUint32(token);
|
2012-02-19 15:44:29 -08:00
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
options.rilRequestType = type;
|
2012-03-07 14:14:37 -08:00
|
|
|
options.rilRequestError = null;
|
2012-02-19 15:44:29 -08:00
|
|
|
this.tokenRequestMap[token] = options;
|
2011-12-04 23:58:27 -08:00
|
|
|
this.token++;
|
|
|
|
return token;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-02-02 10:41:07 -08:00
|
|
|
* Communicate with the RIL IPC thread.
|
2011-12-04 23:58:27 -08:00
|
|
|
*/
|
|
|
|
sendParcel: function sendParcel() {
|
|
|
|
// Compute the size of the parcel and write it to the front of the parcel
|
|
|
|
// where we left room for it. Note that he parcel size does not include
|
|
|
|
// the size itself.
|
|
|
|
let parcelSize = this.outgoingIndex - PARCEL_SIZE_SIZE;
|
|
|
|
this.writeParcelSize(parcelSize);
|
|
|
|
|
|
|
|
// This assumes that postRILMessage will make a copy of the ArrayBufferView
|
|
|
|
// right away!
|
|
|
|
let parcel = this.outgoingBytes.subarray(0, this.outgoingIndex);
|
2012-02-02 10:41:07 -08:00
|
|
|
if (DEBUG) debug("Outgoing parcel: " + Array.slice(parcel));
|
2011-12-04 23:58:27 -08:00
|
|
|
postRILMessage(parcel);
|
|
|
|
this.outgoingIndex = PARCEL_SIZE_SIZE;
|
|
|
|
},
|
|
|
|
|
2012-02-23 07:29:38 -08:00
|
|
|
simpleRequest: function simpleRequest(type, options) {
|
|
|
|
this.newParcel(type, options);
|
2011-12-04 23:58:27 -08:00
|
|
|
this.sendParcel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-15 18:01:24 -07:00
|
|
|
* The RIL state machine.
|
|
|
|
*
|
|
|
|
* This object communicates with rild via parcels and with the main thread
|
|
|
|
* via post messages. It maintains state about the radio, ICC, calls, etc.
|
|
|
|
* and acts upon state changes accordingly.
|
2011-12-04 23:58:27 -08:00
|
|
|
*/
|
|
|
|
let RIL = {
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* One of the RADIO_STATE_* constants.
|
|
|
|
*/
|
2012-03-20 12:28:15 -07:00
|
|
|
radioState: GECKO_RADIOSTATE_UNAVAILABLE,
|
2012-03-15 17:47:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ICC status. Keeps a reference of the data response to the
|
|
|
|
* getICCStatus request.
|
|
|
|
*/
|
|
|
|
iccStatus: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Card state
|
|
|
|
*/
|
|
|
|
cardState: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strings
|
|
|
|
*/
|
|
|
|
IMEI: null,
|
|
|
|
IMEISV: null,
|
|
|
|
IMSI: null,
|
2012-03-15 17:47:00 -07:00
|
|
|
SMSC: null,
|
|
|
|
MSISDN: null,
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2012-03-19 15:49:27 -07:00
|
|
|
voiceRegistrationState: {},
|
|
|
|
dataRegistrationState: {},
|
2012-03-15 17:47:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of strings identifying the network operator.
|
|
|
|
*/
|
|
|
|
operator: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String containing the baseband version.
|
|
|
|
*/
|
|
|
|
basebandVersion: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Network selection mode. 0 for automatic, 1 for manual selection.
|
|
|
|
*/
|
|
|
|
networkSelectionMode: null,
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Active calls
|
|
|
|
*/
|
|
|
|
currentCalls: {},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Existing data calls.
|
|
|
|
*/
|
|
|
|
currentDataCalls: {},
|
|
|
|
|
2012-03-16 17:02:06 -07:00
|
|
|
/**
|
|
|
|
* Hash map for received multipart sms fragments. Messages are hashed with
|
|
|
|
* its sender address and concatenation reference number. Three additional
|
|
|
|
* attributes `segmentMaxSeq`, `receivedSegments`, `segments` are inserted.
|
|
|
|
*/
|
|
|
|
_receivedSmsSegmentsMap: {},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Outgoing messages waiting for SMS-STATUS-REPORT.
|
|
|
|
*/
|
|
|
|
_pendingSentSmsMap: {},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Mute or unmute the radio.
|
|
|
|
*/
|
|
|
|
_muted: true,
|
|
|
|
get muted() {
|
|
|
|
return this._muted;
|
|
|
|
},
|
|
|
|
set muted(val) {
|
|
|
|
val = Boolean(val);
|
|
|
|
if (this._muted != val) {
|
|
|
|
this.setMute(val);
|
|
|
|
this._muted = val;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2012-02-02 10:41:07 -08:00
|
|
|
/**
|
|
|
|
* Set quirk flags based on the RIL model detected. Note that this
|
|
|
|
* requires the RIL being "warmed up" first, which happens when on
|
2012-03-12 16:45:57 -07:00
|
|
|
* an incoming or outgoing voice call or data call.
|
2012-02-02 10:41:07 -08:00
|
|
|
*/
|
|
|
|
rilQuirksInitialized: false,
|
|
|
|
initRILQuirks: function initRILQuirks() {
|
2012-03-12 16:45:57 -07:00
|
|
|
if (this.rilQuirksInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 10:41:07 -08:00
|
|
|
// The Samsung Galaxy S2 I-9100 radio sends an extra Uint32 in the
|
|
|
|
// call state.
|
|
|
|
let model_id = libcutils.property_get("ril.model_id");
|
|
|
|
if (DEBUG) debug("Detected RIL model " + model_id);
|
|
|
|
if (model_id == "I9100") {
|
2012-03-12 16:45:57 -07:00
|
|
|
if (DEBUG) {
|
|
|
|
debug("Detected I9100, enabling " +
|
|
|
|
"RILQUIRKS_CALLSTATE_EXTRA_UINT32, " +
|
|
|
|
"RILQUIRKS_DATACALLSTATE_DOWN_IS_UP.");
|
|
|
|
}
|
2012-02-02 10:41:07 -08:00
|
|
|
RILQUIRKS_CALLSTATE_EXTRA_UINT32 = true;
|
2012-03-12 16:45:57 -07:00
|
|
|
RILQUIRKS_DATACALLSTATE_DOWN_IS_UP = true;
|
2012-02-02 10:41:07 -08:00
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
if (model_id == "I9023" || model_id == "I9020") {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Detected I9020/I9023, enabling " +
|
|
|
|
"RILQUIRKS_DATACALLSTATE_DOWN_IS_UP");
|
|
|
|
}
|
|
|
|
RILQUIRKS_DATACALLSTATE_DOWN_IS_UP = true;
|
|
|
|
}
|
2012-02-02 10:41:07 -08:00
|
|
|
|
|
|
|
this.rilQuirksInitialized = true;
|
|
|
|
},
|
|
|
|
|
2012-02-10 11:27:23 -08:00
|
|
|
/**
|
|
|
|
* Parse an integer from a string, falling back to a default value
|
|
|
|
* if the the provided value is not a string or does not contain a valid
|
|
|
|
* number.
|
2012-02-23 07:29:38 -08:00
|
|
|
*
|
2012-02-10 11:27:23 -08:00
|
|
|
* @param string
|
|
|
|
* String to be parsed.
|
|
|
|
* @param defaultValue
|
|
|
|
* Default value to be used.
|
|
|
|
*/
|
|
|
|
parseInt: function RIL_parseInt(string, defaultValue) {
|
|
|
|
let number = parseInt(string, 10);
|
|
|
|
if (!isNaN(number)) {
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
if (defaultValue === undefined) {
|
|
|
|
defaultValue = null;
|
|
|
|
}
|
|
|
|
return defaultValue;
|
|
|
|
},
|
|
|
|
|
2012-03-15 18:01:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Outgoing requests to the RIL. These can be triggered from the
|
|
|
|
* main thread via messages that look like this:
|
|
|
|
*
|
|
|
|
* {type: "methodName",
|
|
|
|
* extra: "parameters",
|
|
|
|
* go: "here"}
|
|
|
|
*
|
|
|
|
* So if one of the following methods takes arguments, it takes only one,
|
|
|
|
* an object, which then contains all of the parameters as attributes.
|
|
|
|
* The "@param" documentation is to be interpreted accordingly.
|
|
|
|
*/
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
2012-01-10 14:53:08 -08:00
|
|
|
* Retrieve the ICC's status.
|
2011-12-04 23:58:27 -08:00
|
|
|
*/
|
|
|
|
getICCStatus: function getICCStatus() {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_SIM_STATUS);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter a PIN to unlock the ICC.
|
2011-12-16 13:47:32 -08:00
|
|
|
*
|
2011-12-04 23:58:27 -08:00
|
|
|
* @param pin
|
|
|
|
* String containing the PIN.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
enterICCPIN: function enterICCPIN(options) {
|
2011-12-04 23:58:27 -08:00
|
|
|
Buf.newParcel(REQUEST_ENTER_SIM_PIN);
|
|
|
|
Buf.writeUint32(1);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.pin);
|
2011-12-04 23:58:27 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2012-01-10 14:53:08 -08:00
|
|
|
/**
|
|
|
|
* Change the current ICC PIN number
|
|
|
|
*
|
|
|
|
* @param oldPin
|
|
|
|
* String containing the old PIN value
|
|
|
|
* @param newPin
|
|
|
|
* String containing the new PIN value
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
changeICCPIN: function changeICCPIN(options) {
|
2012-01-10 14:53:08 -08:00
|
|
|
Buf.newParcel(REQUEST_CHANGE_SIM_PIN);
|
|
|
|
Buf.writeUint32(2);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.oldPin);
|
|
|
|
Buf.writeString(options.newPin);
|
2012-01-10 14:53:08 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supplies SIM PUK and a new PIN to unlock the ICC
|
|
|
|
*
|
|
|
|
* @param puk
|
|
|
|
* String containing the PUK value.
|
|
|
|
* @param newPin
|
|
|
|
* String containing the new PIN value.
|
|
|
|
*
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
enterICCPUK: function enterICCPUK(options) {
|
2012-01-10 14:53:08 -08:00
|
|
|
Buf.newParcel(REQUEST_ENTER_SIM_PUK);
|
|
|
|
Buf.writeUint32(2);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.puk);
|
|
|
|
Buf.writeString(options.newPin);
|
2012-01-10 14:53:08 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Request an ICC I/O operation.
|
|
|
|
*
|
|
|
|
* See TS 27.007 "restricted SIM" operation, "AT Command +CRSM".
|
|
|
|
* The sequence is in the same order as how libril reads this parcel,
|
|
|
|
* see the struct RIL_SIM_IO_v5 or RIL_SIM_IO_v6 defined in ril.h
|
|
|
|
*
|
|
|
|
* @param command
|
|
|
|
* The I/O command, one of the ICC_COMMAND_* constants.
|
|
|
|
* @param fileid
|
|
|
|
* The file to operate on, one of the ICC_EF_* constants.
|
|
|
|
* @param pathid
|
|
|
|
* String type, check pathid from TS 27.007 +CRSM
|
|
|
|
* @param p1, p2, p3
|
|
|
|
* Arbitrary integer parameters for the command.
|
|
|
|
* @param data
|
|
|
|
* String parameter for the command.
|
|
|
|
* @param pin2 [optional]
|
|
|
|
* String containing the PIN2.
|
|
|
|
*/
|
|
|
|
iccIO: function iccIO(options) {
|
|
|
|
let token = Buf.newParcel(REQUEST_SIM_IO, options);
|
|
|
|
Buf.writeUint32(options.command);
|
|
|
|
Buf.writeUint32(options.fileid);
|
2012-03-20 01:49:59 -07:00
|
|
|
Buf.writeString(options.pathid);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeUint32(options.p1);
|
|
|
|
Buf.writeUint32(options.p2);
|
|
|
|
Buf.writeUint32(options.p3);
|
|
|
|
Buf.writeString(options.data);
|
|
|
|
if (options.pin2 != null) {
|
|
|
|
Buf.writeString(options.pin2);
|
|
|
|
}
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
2012-03-15 18:01:24 -07:00
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Read the MSISDN from the ICC.
|
|
|
|
*/
|
|
|
|
getMSISDN: function getMSISDN() {
|
|
|
|
this.iccIO({
|
|
|
|
command: ICC_COMMAND_GET_RESPONSE,
|
|
|
|
fileid: ICC_EF_MSISDN,
|
|
|
|
pathid: EF_PATH_MF_SIM + EF_PATH_DF_TELECOM,
|
|
|
|
p1: 0, // For GET_RESPONSE, p1 = 0
|
|
|
|
p2: 0, // For GET_RESPONSE, p2 = 0
|
|
|
|
p3: GET_RESPONSE_EF_SIZE_BYTES,
|
|
|
|
data: null,
|
|
|
|
pin2: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Request the phone's radio power to be switched on or off.
|
|
|
|
*
|
|
|
|
* @param on
|
|
|
|
* Boolean indicating the desired power state.
|
|
|
|
*/
|
|
|
|
setRadioPower: function setRadioPower(on) {
|
|
|
|
Buf.newParcel(REQUEST_RADIO_POWER);
|
|
|
|
Buf.writeUint32(1);
|
|
|
|
Buf.writeUint32(on ? 1 : 0);
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set screen state.
|
|
|
|
*
|
|
|
|
* @param on
|
|
|
|
* Boolean indicating whether the screen should be on or off.
|
|
|
|
*/
|
|
|
|
setScreenState: function setScreenState(on) {
|
|
|
|
Buf.newParcel(REQUEST_SCREEN_STATE);
|
|
|
|
Buf.writeUint32(1);
|
|
|
|
Buf.writeUint32(on ? 1 : 0);
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2012-03-19 15:49:27 -07:00
|
|
|
getVoiceRegistrationState: function getVoiceRegistrationState() {
|
|
|
|
Buf.simpleRequest(REQUEST_VOICE_REGISTRATION_STATE);
|
2011-12-04 23:58:27 -08:00
|
|
|
},
|
|
|
|
|
2012-03-19 15:49:27 -07:00
|
|
|
getDataRegistrationState: function getDataRegistrationState() {
|
|
|
|
Buf.simpleRequest(REQUEST_DATA_REGISTRATION_STATE);
|
2011-12-04 23:58:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
getOperator: function getOperator() {
|
|
|
|
Buf.simpleRequest(REQUEST_OPERATOR);
|
|
|
|
},
|
|
|
|
|
|
|
|
getNetworkSelectionMode: function getNetworkSelectionMode() {
|
|
|
|
Buf.simpleRequest(REQUEST_QUERY_NETWORK_SELECTION_MODE);
|
|
|
|
},
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
setNetworkSelectionAutomatic: function setNetworkSelectionAutomatic() {
|
|
|
|
Buf.simpleRequest(REQUEST_SET_NETWORK_SELECTION_AUTOMATIC);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the preferred network type.
|
|
|
|
*
|
|
|
|
* @param network_type
|
|
|
|
* The network type. One of the PREFERRED_NETWORK_TYPE_* constants.
|
|
|
|
*/
|
|
|
|
setPreferredNetworkType: function setPreferredNetworkType(network_type) {
|
|
|
|
Buf.newParcel(REQUEST_SET_PREFERRED_NETWORK_TYPE);
|
|
|
|
Buf.writeUint32(network_type);
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Request various states about the network.
|
|
|
|
*/
|
|
|
|
requestNetworkInfo: function requestNetworkInfo() {
|
|
|
|
if (DEBUG) debug("Requesting phone state");
|
2012-03-19 15:49:27 -07:00
|
|
|
this.getVoiceRegistrationState();
|
|
|
|
this.getDataRegistrationState(); //TODO only GSM
|
2012-03-15 17:47:00 -07:00
|
|
|
this.getOperator();
|
|
|
|
this.getNetworkSelectionMode();
|
|
|
|
},
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Get current calls.
|
|
|
|
*/
|
|
|
|
getCurrentCalls: function getCurrentCalls() {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_CURRENT_CALLS);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the signal strength.
|
|
|
|
*/
|
|
|
|
getSignalStrength: function getSignalStrength() {
|
|
|
|
Buf.simpleRequest(REQUEST_SIGNAL_STRENGTH);
|
|
|
|
},
|
|
|
|
|
|
|
|
getIMEI: function getIMEI() {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_IMEI);
|
|
|
|
},
|
|
|
|
|
|
|
|
getIMEISV: function getIMEISV() {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_IMEISV);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDeviceIdentity: function getDeviceIdentity() {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_DEVICE_IDENTITY);
|
|
|
|
},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
getBasebandVersion: function getBasebandVersion() {
|
|
|
|
Buf.simpleRequest(REQUEST_BASEBAND_VERSION);
|
|
|
|
},
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Dial the phone.
|
|
|
|
*
|
2012-03-15 17:47:00 -07:00
|
|
|
* @param number
|
|
|
|
* String containing the number to dial.
|
2011-12-04 23:58:27 -08:00
|
|
|
* @param clirMode
|
|
|
|
* Integer doing something XXX TODO
|
|
|
|
* @param uusInfo
|
|
|
|
* Integer doing something XXX TODO
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
dial: function dial(options) {
|
2011-12-04 23:58:27 -08:00
|
|
|
let token = Buf.newParcel(REQUEST_DIAL);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.number);
|
|
|
|
Buf.writeUint32(options.clirMode || 0);
|
|
|
|
Buf.writeUint32(options.uusInfo || 0);
|
2012-01-05 08:17:20 -08:00
|
|
|
// TODO Why do we need this extra 0? It was put it in to make this
|
|
|
|
// match the format of the binary message.
|
|
|
|
Buf.writeUint32(0);
|
2011-12-04 23:58:27 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-06 22:57:05 -08:00
|
|
|
/**
|
|
|
|
* Hang up the phone.
|
|
|
|
*
|
2012-01-09 14:28:47 -08:00
|
|
|
* @param callIndex
|
2011-12-06 22:57:05 -08:00
|
|
|
* Call index (1-based) as reported by REQUEST_GET_CURRENT_CALLS.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
hangUp: function hangUp(options) {
|
2012-03-15 17:47:00 -07:00
|
|
|
//TODO need to check whether call is holding/waiting/background
|
|
|
|
// and then use REQUEST_HANGUP_WAITING_OR_BACKGROUND
|
2011-12-06 22:57:05 -08:00
|
|
|
Buf.newParcel(REQUEST_HANGUP);
|
|
|
|
Buf.writeUint32(1);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeUint32(options.callIndex);
|
2011-12-06 22:57:05 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-12 10:22:26 -08:00
|
|
|
/**
|
|
|
|
* Mute or unmute the radio.
|
|
|
|
*
|
|
|
|
* @param mute
|
|
|
|
* Boolean to indicate whether to mute or unmute the radio.
|
|
|
|
*/
|
|
|
|
setMute: function setMute(mute) {
|
|
|
|
Buf.newParcel(REQUEST_SET_MUTE);
|
|
|
|
Buf.writeUint32(1);
|
|
|
|
Buf.writeUint32(mute ? 1 : 0);
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-06 22:57:05 -08:00
|
|
|
/**
|
|
|
|
* Answer an incoming call.
|
2012-03-15 17:47:00 -07:00
|
|
|
*
|
|
|
|
* @param callIndex
|
|
|
|
* Call index of the call to answer.
|
2011-12-06 22:57:05 -08:00
|
|
|
*/
|
2012-03-15 18:01:24 -07:00
|
|
|
answerCall: function answerCall(options) {
|
2012-03-15 17:47:00 -07:00
|
|
|
// Check for races. Since we dispatched the incoming call notification the
|
|
|
|
// incoming call may have changed. The main thread thinks that it is
|
|
|
|
// answering the call with the given index, so only answer if that is still
|
|
|
|
// incoming.
|
|
|
|
let call = this.currentCalls[options.callIndex];
|
|
|
|
if (call && call.state == CALL_STATE_INCOMING) {
|
|
|
|
Buf.simpleRequest(REQUEST_ANSWER);
|
|
|
|
}
|
2011-12-06 22:57:05 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reject an incoming call.
|
2012-03-15 17:47:00 -07:00
|
|
|
*
|
|
|
|
* @param callIndex
|
|
|
|
* Call index of the call to reject.
|
2011-12-06 22:57:05 -08:00
|
|
|
*/
|
|
|
|
rejectCall: function rejectCall() {
|
2012-03-15 17:47:00 -07:00
|
|
|
// Check for races. Since we dispatched the incoming call notification the
|
|
|
|
// incoming call may have changed. The main thread thinks that it is
|
|
|
|
// rejecting the call with the given index, so only reject if that is still
|
|
|
|
// incoming.
|
|
|
|
let call = this.currentCalls[options.callIndex];
|
|
|
|
if (call && call.state == CALL_STATE_INCOMING) {
|
|
|
|
Buf.simpleRequest(REQUEST_UDUB);
|
|
|
|
}
|
2011-12-06 22:57:05 -08:00
|
|
|
},
|
2012-04-05 01:12:42 -07:00
|
|
|
|
|
|
|
holdCall: function holdCall(options) {
|
|
|
|
let call = this.currentCalls[options.callIndex];
|
|
|
|
if (call && call.state == CALL_STATE_ACTIVE) {
|
|
|
|
Buf.simpleRequest(REQUEST_SWITCH_HOLDING_AND_ACTIVE);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resumeCall: function resumeCall(options) {
|
|
|
|
let call = this.currentCalls[options.callIndex];
|
|
|
|
if (call && call.state == CALL_STATE_HOLDING) {
|
|
|
|
Buf.simpleRequest(REQUEST_SWITCH_HOLDING_AND_ACTIVE);
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 22:57:05 -08:00
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Send an SMS.
|
|
|
|
*
|
2012-02-19 15:44:29 -08:00
|
|
|
* The `options` parameter object should contain the following attributes:
|
|
|
|
*
|
|
|
|
* @param number
|
2012-03-15 17:47:00 -07:00
|
|
|
* String containing the recipient number.
|
2011-12-23 21:02:51 -08:00
|
|
|
* @param body
|
2012-03-15 17:47:00 -07:00
|
|
|
* String containing the message text.
|
|
|
|
* @param requestId
|
|
|
|
* String identifying the sms request used by the SmsRequestManager.
|
|
|
|
* @param processId
|
|
|
|
* String containing the processId for the SmsRequestManager.
|
2011-12-04 23:58:27 -08:00
|
|
|
*/
|
2012-02-19 15:44:29 -08:00
|
|
|
sendSMS: function sendSMS(options) {
|
2012-03-15 17:47:00 -07:00
|
|
|
// Get the SMS Center address
|
|
|
|
if (!this.SMSC) {
|
|
|
|
// We request the SMS center address again, passing it the SMS options
|
|
|
|
// in order to try to send it again after retrieving the SMSC number.
|
|
|
|
this.getSMSCAddress(options);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We explicitly save this information on the options object so that we
|
|
|
|
// can refer to it later, in particular on the main thread (where this
|
|
|
|
// object may get sent eventually.)
|
|
|
|
options.SMSC = this.SMSC;
|
|
|
|
|
|
|
|
//TODO: verify values on 'options'
|
|
|
|
|
2012-03-16 16:59:35 -07:00
|
|
|
if (options.segmentMaxSeq > 1) {
|
|
|
|
if (!options.segmentSeq) {
|
|
|
|
// Fist segment to send
|
|
|
|
options.segmentSeq = 1;
|
|
|
|
options.body = options.segments[0].body;
|
|
|
|
options.encodedBodyLength = options.segments[0].encodedBodyLength;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
options.body = options.fullBody;
|
|
|
|
options.encodedBodyLength = options.encodedFullBodyLength;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.newParcel(REQUEST_SEND_SMS, options);
|
2011-12-04 23:58:27 -08:00
|
|
|
Buf.writeUint32(2);
|
2012-02-19 15:44:29 -08:00
|
|
|
Buf.writeString(options.SMSC);
|
2012-03-02 04:41:37 -08:00
|
|
|
GsmPDUHelper.writeMessage(options);
|
2011-12-04 23:58:27 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Acknowledge the receipt and handling of an SMS.
|
|
|
|
*
|
|
|
|
* @param success
|
|
|
|
* Boolean indicating whether the message was successfuly handled.
|
|
|
|
* @param cause
|
|
|
|
* SMS_* constant indicating the reason for unsuccessful handling.
|
|
|
|
*/
|
|
|
|
acknowledgeSMS: function acknowledgeSMS(success, cause) {
|
|
|
|
let token = Buf.newParcel(REQUEST_SMS_ACKNOWLEDGE);
|
|
|
|
Buf.writeUint32(2);
|
|
|
|
Buf.writeUint32(success ? 1 : 0);
|
|
|
|
Buf.writeUint32(cause);
|
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-16 13:47:32 -08:00
|
|
|
/**
|
|
|
|
* Start a DTMF Tone.
|
|
|
|
*
|
|
|
|
* @param dtmfChar
|
|
|
|
* DTMF signal to send, 0-9, *, +
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
startTone: function startTone(options) {
|
2011-12-16 13:47:32 -08:00
|
|
|
Buf.newParcel(REQUEST_DTMF_START);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.dtmfChar);
|
2011-12-16 13:47:32 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
|
|
|
stopTone: function stopTone() {
|
|
|
|
Buf.simpleRequest(REQUEST_DTMF_STOP);
|
|
|
|
},
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
/**
|
|
|
|
* Send a DTMF tone.
|
|
|
|
*
|
|
|
|
* @param dtmfChar
|
|
|
|
* DTMF signal to send, 0-9, *, +
|
|
|
|
*/
|
|
|
|
sendTone: function sendTone(options) {
|
2011-12-16 13:47:32 -08:00
|
|
|
Buf.newParcel(REQUEST_DTMF);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.dtmfChar);
|
2011-12-16 13:47:32 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Get the Short Message Service Center address.
|
2012-02-23 07:29:38 -08:00
|
|
|
*
|
|
|
|
* @param pendingSMS
|
|
|
|
* Object containing the parameters of an SMS waiting to be sent.
|
2011-12-23 21:02:51 -08:00
|
|
|
*/
|
2012-02-23 07:29:38 -08:00
|
|
|
getSMSCAddress: function getSMSCAddress(pendingSMS) {
|
|
|
|
Buf.simpleRequest(REQUEST_GET_SMSC_ADDRESS, pendingSMS);
|
2011-12-23 21:02:51 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Short Message Service Center address.
|
|
|
|
*
|
2012-03-15 17:47:00 -07:00
|
|
|
* @param SMSC
|
2011-12-23 21:02:51 -08:00
|
|
|
* Short Message Service Center address in PDU format.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
setSMSCAddress: function setSMSCAddress(options) {
|
2012-01-17 17:34:09 -08:00
|
|
|
Buf.newParcel(REQUEST_SET_SMSC_ADDRESS);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.SMSC);
|
2012-01-17 17:34:09 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a data call.
|
|
|
|
*
|
|
|
|
* @param radioTech
|
|
|
|
* Integer to indicate radio technology.
|
2012-02-10 11:27:38 -08:00
|
|
|
* DATACALL_RADIOTECHNOLOGY_CDMA => CDMA.
|
|
|
|
* DATACALL_RADIOTECHNOLOGY_GSM => GSM.
|
2012-01-17 17:34:09 -08:00
|
|
|
* @param apn
|
|
|
|
* String containing the name of the APN to connect to.
|
|
|
|
* @param user
|
|
|
|
* String containing the username for the APN.
|
|
|
|
* @param passwd
|
|
|
|
* String containing the password for the APN.
|
|
|
|
* @param chappap
|
|
|
|
* Integer containing CHAP/PAP auth type.
|
|
|
|
* DATACALL_AUTH_NONE => PAP and CHAP is never performed.
|
|
|
|
* DATACALL_AUTH_PAP => PAP may be performed.
|
|
|
|
* DATACALL_AUTH_CHAP => CHAP may be performed.
|
|
|
|
* DATACALL_AUTH_PAP_OR_CHAP => PAP / CHAP may be performed.
|
|
|
|
* @param pdptype
|
|
|
|
* String containing PDP type to request. ("IP", "IPV6", ...)
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
setupDataCall: function setupDataCall(options) {
|
2012-01-17 17:34:09 -08:00
|
|
|
let token = Buf.newParcel(REQUEST_SETUP_DATA_CALL);
|
|
|
|
Buf.writeUint32(7);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.radioTech.toString());
|
2012-01-17 17:34:09 -08:00
|
|
|
Buf.writeString(DATACALL_PROFILE_DEFAULT.toString());
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.apn);
|
|
|
|
Buf.writeString(options.user);
|
|
|
|
Buf.writeString(options.passwd);
|
|
|
|
Buf.writeString(options.chappap.toString());
|
|
|
|
Buf.writeString(options.pdptype);
|
2012-01-17 17:34:09 -08:00
|
|
|
Buf.sendParcel();
|
|
|
|
return token;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deactivate a data call.
|
|
|
|
*
|
|
|
|
* @param cid
|
|
|
|
* String containing CID.
|
|
|
|
* @param reason
|
|
|
|
* One of DATACALL_DEACTIVATE_* constants.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
deactivateDataCall: function deactivateDataCall(options) {
|
2012-03-15 17:47:00 -07:00
|
|
|
let datacall = this.currentDataCalls[options.cid];
|
|
|
|
if (!datacall) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-17 17:34:09 -08:00
|
|
|
let token = Buf.newParcel(REQUEST_DEACTIVATE_DATA_CALL);
|
|
|
|
Buf.writeUint32(2);
|
2012-03-15 17:47:00 -07:00
|
|
|
Buf.writeString(options.cid);
|
|
|
|
Buf.writeString(options.reason || DATACALL_DEACTIVATE_NO_REASON);
|
2012-01-17 17:34:09 -08:00
|
|
|
Buf.sendParcel();
|
2012-03-15 17:47:00 -07:00
|
|
|
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_DISCONNECTING;
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
|
|
|
datacall: datacall});
|
2012-01-17 17:34:09 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of data calls.
|
|
|
|
*/
|
|
|
|
getDataCallList: function getDataCallList() {
|
|
|
|
Buf.simpleRequest(REQUEST_DATA_CALL_LIST);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get failure casue code for the most recently failed PDP context.
|
|
|
|
*/
|
|
|
|
getFailCauseCode: function getFailCauseCode() {
|
|
|
|
Buf.simpleRequest(REQUEST_LAST_CALL_FAIL_CAUSE);
|
|
|
|
},
|
2012-03-15 17:47:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process ICC status.
|
|
|
|
*/
|
|
|
|
_processICCStatus: function _processICCStatus(iccStatus) {
|
|
|
|
this.iccStatus = iccStatus;
|
|
|
|
|
|
|
|
if ((!iccStatus) || (iccStatus.cardState == CARD_STATE_ABSENT)) {
|
|
|
|
if (DEBUG) debug("ICC absent");
|
|
|
|
if (this.cardState == GECKO_CARDSTATE_ABSENT) {
|
|
|
|
this.operator = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.cardState = GECKO_CARDSTATE_ABSENT;
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "cardstatechange",
|
|
|
|
cardState: this.cardState});
|
2012-03-15 17:47:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
let app = iccStatus.apps[iccStatus.gsmUmtsSubscriptionAppIndex];
|
|
|
|
if (!app) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Subscription application is not present in iccStatus.");
|
|
|
|
}
|
|
|
|
if (this.cardState == GECKO_CARDSTATE_ABSENT) {
|
2012-03-15 17:47:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
this.cardState = GECKO_CARDSTATE_ABSENT;
|
|
|
|
this.operator = null;
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "cardstatechange",
|
|
|
|
cardState: this.cardState});
|
2012-03-15 17:47:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
let newCardState;
|
|
|
|
switch (app.app_state) {
|
|
|
|
case CARD_APPSTATE_PIN:
|
|
|
|
newCardState = GECKO_CARDSTATE_PIN_REQUIRED;
|
|
|
|
break;
|
|
|
|
case CARD_APPSTATE_PUK:
|
|
|
|
newCardState = GECKO_CARDSTATE_PUK_REQUIRED;
|
|
|
|
break;
|
|
|
|
case CARD_APPSTATE_SUBSCRIPTION_PERSO:
|
|
|
|
newCardState = GECKO_CARDSTATE_NETWORK_LOCKED;
|
|
|
|
break;
|
|
|
|
case CARD_APPSTATE_READY:
|
|
|
|
this.requestNetworkInfo();
|
|
|
|
this.getSignalStrength();
|
|
|
|
this.getMSISDN();
|
|
|
|
newCardState = GECKO_CARDSTATE_READY;
|
|
|
|
break;
|
|
|
|
case CARD_APPSTATE_UNKNOWN:
|
|
|
|
case CARD_APPSTATE_DETECTED:
|
|
|
|
default:
|
|
|
|
newCardState = GECKO_CARDSTATE_NOT_READY;
|
|
|
|
}
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
if (this.cardState == newCardState) {
|
|
|
|
return;
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
this.cardState = newCardState;
|
|
|
|
this.sendDOMMessage({type: "cardstatechange",
|
|
|
|
cardState: this.cardState});
|
2012-03-15 17:47:00 -07:00
|
|
|
},
|
|
|
|
|
2012-03-15 18:01:24 -07:00
|
|
|
/**
|
|
|
|
* Process the MSISDN ICC I/O response.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
_processMSISDNResponse: function _processMSISDNResponse(options) {
|
|
|
|
switch (options.command) {
|
|
|
|
case ICC_COMMAND_GET_RESPONSE:
|
|
|
|
let response = Buf.readString();
|
|
|
|
let recordSize = parseInt(
|
|
|
|
response.substr(RESPONSE_DATA_RECORD_LENGTH * 2, 2), 16) & 0xff;
|
|
|
|
let options = {
|
|
|
|
command: ICC_COMMAND_READ_RECORD,
|
|
|
|
fileid: ICC_EF_MSISDN,
|
|
|
|
pathid: EF_PATH_MF_SIM + EF_PATH_DF_TELECOM,
|
|
|
|
p1: 1, // Record number, MSISDN is always in the 1st record
|
|
|
|
p2: READ_RECORD_ABSOLUTE_MODE,
|
|
|
|
p3: recordSize,
|
|
|
|
data: null,
|
|
|
|
pin2: null,
|
|
|
|
};
|
2012-03-15 18:01:24 -07:00
|
|
|
this.iccIO(options);
|
2012-03-15 17:47:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ICC_COMMAND_READ_RECORD:
|
|
|
|
// Ignore 2 bytes prefix, which is 4 chars
|
|
|
|
let number = GsmPDUHelper.readStringAsBCD().toString().substr(4);
|
|
|
|
if (DEBUG) debug("MSISDN: " + number);
|
2012-03-17 07:23:17 -07:00
|
|
|
this.MSISDN = number || null;
|
|
|
|
this.sendDOMMessage({type: "siminfo", msisdn: this.MSISDN});
|
2012-03-15 17:47:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-19 15:49:27 -07:00
|
|
|
_processVoiceRegistrationState: function _processVoiceRegistrationState(state) {
|
|
|
|
let rs = this.voiceRegistrationState;
|
2012-03-15 17:47:00 -07:00
|
|
|
let stateChanged = false;
|
|
|
|
|
|
|
|
let regState = RIL.parseInt(state[0], NETWORK_CREG_STATE_UNKNOWN);
|
|
|
|
if (rs.regState != regState) {
|
|
|
|
rs.regState = regState;
|
|
|
|
stateChanged = true;
|
2012-03-20 12:28:15 -07:00
|
|
|
if (regState == NETWORK_CREG_STATE_REGISTERED_HOME ||
|
|
|
|
regState == NETWORK_CREG_STATE_REGISTERED_ROAMING) {
|
|
|
|
RIL.getSMSCAddress();
|
|
|
|
}
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let radioTech = RIL.parseInt(state[3], NETWORK_CREG_TECH_UNKNOWN);
|
|
|
|
if (rs.radioTech != radioTech) {
|
|
|
|
rs.radioTech = radioTech;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This zombie code branch that will be raised from the dead once
|
|
|
|
// we add explicit CDMA support everywhere (bug 726098).
|
|
|
|
let cdma = false;
|
|
|
|
if (cdma) {
|
|
|
|
let baseStationId = RIL.parseInt(state[4]);
|
|
|
|
let baseStationLatitude = RIL.parseInt(state[5]);
|
|
|
|
let baseStationLongitude = RIL.parseInt(state[6]);
|
|
|
|
if (!baseStationLatitude && !baseStationLongitude) {
|
|
|
|
baseStationLatitude = baseStationLongitude = null;
|
|
|
|
}
|
|
|
|
let cssIndicator = RIL.parseInt(state[7]);
|
|
|
|
let systemId = RIL.parseInt(state[8]);
|
|
|
|
let networkId = RIL.parseInt(state[9]);
|
|
|
|
let roamingIndicator = RIL.parseInt(state[10]);
|
|
|
|
let systemIsInPRL = RIL.parseInt(state[11]);
|
|
|
|
let defaultRoamingIndicator = RIL.parseInt(state[12]);
|
|
|
|
let reasonForDenial = RIL.parseInt(state[13]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stateChanged) {
|
2012-03-19 15:49:27 -07:00
|
|
|
this.sendDOMMessage({type: "voiceregistrationstatechange",
|
|
|
|
voiceRegistrationState: rs});
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-19 15:49:27 -07:00
|
|
|
_processDataRegistrationState: function _processDataRegistrationState(state) {
|
|
|
|
let rs = this.dataRegistrationState;
|
2012-03-15 17:47:00 -07:00
|
|
|
let stateChanged = false;
|
|
|
|
|
|
|
|
let regState = RIL.parseInt(state[0], NETWORK_CREG_STATE_UNKNOWN);
|
|
|
|
if (rs.regState != regState) {
|
|
|
|
rs.regState = regState;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let radioTech = RIL.parseInt(state[3], NETWORK_CREG_TECH_UNKNOWN);
|
|
|
|
if (rs.radioTech != radioTech) {
|
|
|
|
rs.radioTech = radioTech;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stateChanged) {
|
2012-03-19 15:49:27 -07:00
|
|
|
this.sendDOMMessage({type: "dataregistrationstatechange",
|
|
|
|
dataRegistrationState: rs});
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-15 18:01:24 -07:00
|
|
|
/**
|
|
|
|
* Helpers for processing call state.
|
|
|
|
*/
|
2012-03-15 17:47:00 -07:00
|
|
|
_processCalls: function _processCalls(newCalls) {
|
|
|
|
// Go through the calls we currently have on file and see if any of them
|
|
|
|
// changed state. Remove them from the newCalls map as we deal with them
|
|
|
|
// so that only new calls remain in the map after we're done.
|
|
|
|
for each (let currentCall in this.currentCalls) {
|
|
|
|
let newCall;
|
|
|
|
if (newCalls) {
|
|
|
|
newCall = newCalls[currentCall.callIndex];
|
|
|
|
delete newCalls[currentCall.callIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newCall) {
|
|
|
|
// Call is still valid.
|
|
|
|
if (newCall.state != currentCall.state) {
|
|
|
|
// State has changed.
|
|
|
|
currentCall.state = newCall.state;
|
|
|
|
this._handleChangedCallState(currentCall);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Call is no longer reported by the radio. Remove from our map and
|
|
|
|
// send disconnected state change.
|
|
|
|
delete this.currentCalls[currentCall.callIndex];
|
|
|
|
this._handleDisconnectedCall(currentCall);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go through any remaining calls that are new to us.
|
|
|
|
for each (let newCall in newCalls) {
|
|
|
|
if (newCall.isVoice) {
|
|
|
|
// Format international numbers appropriately.
|
|
|
|
if (newCall.number &&
|
|
|
|
newCall.toa == TOA_INTERNATIONAL &&
|
|
|
|
newCall.number[0] != "+") {
|
|
|
|
newCall.number = "+" + newCall.number;
|
|
|
|
}
|
|
|
|
// Add to our map.
|
|
|
|
this.currentCalls[newCall.callIndex] = newCall;
|
|
|
|
this._handleChangedCallState(newCall);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update our mute status. If there is anything in our currentCalls map then
|
|
|
|
// we know it's a voice call and we should leave audio on.
|
|
|
|
this.muted = Object.getOwnPropertyNames(this.currentCalls).length == 0;
|
|
|
|
},
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
_handleChangedCallState: function _handleChangedCallState(changedCall) {
|
|
|
|
let message = {type: "callStateChange",
|
|
|
|
call: {callIndex: changedCall.callIndex,
|
|
|
|
state: changedCall.state,
|
|
|
|
number: changedCall.number,
|
|
|
|
name: changedCall.name}};
|
|
|
|
this.sendDOMMessage(message);
|
|
|
|
},
|
|
|
|
|
|
|
|
_handleDisconnectedCall: function _handleDisconnectedCall(disconnectedCall) {
|
|
|
|
let message = {type: "callDisconnected",
|
|
|
|
call: {callIndex: disconnectedCall.callIndex}};
|
|
|
|
this.sendDOMMessage(message);
|
|
|
|
},
|
|
|
|
|
|
|
|
_processDataCallList: function _processDataCallList(datacalls) {
|
|
|
|
for each (let currentDataCall in this.currentDataCalls) {
|
|
|
|
let updatedDataCall;
|
|
|
|
if (datacalls) {
|
|
|
|
updatedDataCall = datacalls[currentDataCall.cid];
|
|
|
|
delete datacalls[currentDataCall.cid];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!updatedDataCall) {
|
|
|
|
delete this.currentDataCalls[currentDataCall.callIndex];
|
|
|
|
currentDataCall.state = GECKO_NETWORK_STATE_DISCONNECTED;
|
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
|
|
|
datacall: currentDataCall});
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setDataCallGeckoState(updatedDataCall);
|
|
|
|
if (updatedDataCall.state != currentDataCall.state) {
|
|
|
|
currentDataCall.status = updatedDataCall.status;
|
|
|
|
currentDataCall.active = updatedDataCall.active;
|
|
|
|
currentDataCall.state = updatedDataCall.state;
|
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
|
|
|
datacall: currentDataCall});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for each (let newDataCall in datacalls) {
|
|
|
|
this.currentDataCalls[newDataCall.cid] = newDataCall;
|
|
|
|
this._setDataCallGeckoState(newDataCall);
|
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
|
|
|
datacall: newDataCall});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_setDataCallGeckoState: function _setDataCallGeckoState(datacall) {
|
|
|
|
switch (datacall.active) {
|
|
|
|
case DATACALL_INACTIVE:
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_DISCONNECTED;
|
|
|
|
break;
|
|
|
|
case DATACALL_ACTIVE_DOWN:
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_SUSPENDED;
|
|
|
|
if (RILQUIRKS_DATACALLSTATE_DOWN_IS_UP) {
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_CONNECTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATACALL_ACTIVE_UP:
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_CONNECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Helper for processing received SMS parcel data.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* Length of SMS string in the incoming parcel.
|
|
|
|
*
|
|
|
|
* @return Message parsed or null for invalid message.
|
|
|
|
*/
|
|
|
|
_processReceivedSms: function _processReceivedSms(length) {
|
|
|
|
if (!length) {
|
|
|
|
if (DEBUG) debug("Received empty SMS!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// An SMS is a string, but we won't read it as such, so let's read the
|
|
|
|
// string length and then defer to PDU parsing helper.
|
|
|
|
let messageStringLength = Buf.readUint32();
|
|
|
|
if (DEBUG) debug("Got new SMS, length " + messageStringLength);
|
|
|
|
let message = GsmPDUHelper.readMessage();
|
|
|
|
if (DEBUG) debug(message);
|
|
|
|
|
|
|
|
// Read string delimiters. See Buf.readString().
|
|
|
|
let delimiter = Buf.readUint16();
|
|
|
|
if (!(messageStringLength & 1)) {
|
|
|
|
delimiter |= Buf.readUint16();
|
|
|
|
}
|
|
|
|
if (DEBUG) {
|
|
|
|
if (delimiter != 0) {
|
|
|
|
debug("Something's wrong, found string delimiter: " + delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for processing SMS-DELIVER PDUs.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* Length of SMS string in the incoming parcel.
|
|
|
|
*
|
|
|
|
* @return A failure cause defined in 3GPP 23.040 clause 9.2.3.22.
|
|
|
|
*/
|
|
|
|
_processSmsDeliver: function _processSmsDeliver(length) {
|
|
|
|
let message = this._processReceivedSms(length);
|
|
|
|
if (!message) {
|
|
|
|
return PDU_FCS_UNSPECIFIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.header && (message.header.segmentMaxSeq > 1)) {
|
|
|
|
message = this._processReceivedSmsSegment(message);
|
|
|
|
} else {
|
|
|
|
message.fullBody = message.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
message.type = "sms-received";
|
|
|
|
this.sendDOMMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PDU_FCS_OK;
|
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Helper for processing SMS-STATUS-REPORT PDUs.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* Length of SMS string in the incoming parcel.
|
|
|
|
*
|
|
|
|
* @return A failure cause defined in 3GPP 23.040 clause 9.2.3.22.
|
|
|
|
*/
|
|
|
|
_processSmsStatusReport: function _processSmsStatusReport(length) {
|
|
|
|
let message = this._processReceivedSms(length);
|
|
|
|
if (!message) {
|
|
|
|
return PDU_FCS_UNSPECIFIED;
|
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
let options = this._pendingSentSmsMap[message.messageRef];
|
|
|
|
if (!options) {
|
|
|
|
return PDU_FCS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
let status = message.status;
|
|
|
|
|
|
|
|
// 3GPP TS 23.040 9.2.3.15 `The MS shall interpret any reserved values as
|
|
|
|
// "Service Rejected"(01100011) but shall store them exactly as received.`
|
|
|
|
if ((status >= 0x80)
|
|
|
|
|| ((status >= PDU_ST_0_RESERVED_BEGIN)
|
|
|
|
&& (status < PDU_ST_0_SC_SPECIFIC_BEGIN))
|
|
|
|
|| ((status >= PDU_ST_1_RESERVED_BEGIN)
|
|
|
|
&& (status < PDU_ST_1_SC_SPECIFIC_BEGIN))
|
|
|
|
|| ((status >= PDU_ST_2_RESERVED_BEGIN)
|
|
|
|
&& (status < PDU_ST_2_SC_SPECIFIC_BEGIN))
|
|
|
|
|| ((status >= PDU_ST_3_RESERVED_BEGIN)
|
|
|
|
&& (status < PDU_ST_3_SC_SPECIFIC_BEGIN))
|
|
|
|
) {
|
|
|
|
status = PDU_ST_3_SERVICE_REJECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pending. Waiting for next status report.
|
|
|
|
if ((status >>> 5) == 0x01) {
|
|
|
|
return PDU_FCS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
delete this._pendingSentSmsMap[message.messageRef];
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
if ((status >>> 5) != 0x00) {
|
|
|
|
// TODO: bug 727319 - Notify SMS send failures
|
|
|
|
return PDU_FCS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
if ((options.segmentMaxSeq > 1)
|
|
|
|
&& (options.segmentSeq < options.segmentMaxSeq)) {
|
|
|
|
// Not last segment. Send next segment here.
|
|
|
|
this._processSentSmsSegment(options);
|
|
|
|
} else {
|
|
|
|
// Last segment delivered with success. Report it.
|
|
|
|
this.sendDOMMessage({
|
|
|
|
type: "sms-delivered",
|
|
|
|
envelopeId: options.envelopeId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
return PDU_FCS_OK;
|
|
|
|
},
|
|
|
|
|
2012-03-16 17:02:06 -07:00
|
|
|
/**
|
|
|
|
* Helper for processing received multipart SMS.
|
|
|
|
*
|
|
|
|
* @return null for handled segments, and an object containing full message
|
|
|
|
* body once all segments are received.
|
|
|
|
*/
|
|
|
|
_processReceivedSmsSegment: function _processReceivedSmsSegment(original) {
|
|
|
|
let hash = original.sender + ":" + original.header.segmentRef;
|
|
|
|
let seq = original.header.segmentSeq;
|
|
|
|
|
|
|
|
let options = this._receivedSmsSegmentsMap[hash];
|
|
|
|
if (!options) {
|
|
|
|
options = original;
|
|
|
|
this._receivedSmsSegmentsMap[hash] = options;
|
|
|
|
|
|
|
|
options.segmentMaxSeq = original.header.segmentMaxSeq;
|
|
|
|
options.receivedSegments = 0;
|
|
|
|
options.segments = [];
|
|
|
|
} else if (options.segments[seq]) {
|
|
|
|
// Duplicated segment?
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Got duplicated segment no." + seq + " of a multipart SMS: "
|
|
|
|
+ JSON.stringify(original));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.segments[seq] = original.body;
|
|
|
|
options.receivedSegments++;
|
|
|
|
if (options.receivedSegments < options.segmentMaxSeq) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Got segment no." + seq + " of a multipart SMS: "
|
|
|
|
+ JSON.stringify(options));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from map
|
|
|
|
delete this._receivedSmsSegmentsMap[hash];
|
|
|
|
|
|
|
|
// Rebuild full body
|
|
|
|
options.fullBody = "";
|
|
|
|
for (let i = 1; i <= options.segmentMaxSeq; i++) {
|
|
|
|
options.fullBody += options.segments[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Got full multipart SMS: " + JSON.stringify(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Helper for processing sent multipart SMS.
|
|
|
|
*/
|
|
|
|
_processSentSmsSegment: function _processSentSmsSegment(options) {
|
|
|
|
// Setup attributes for sending next segment
|
|
|
|
let next = options.segmentSeq;
|
|
|
|
options.body = options.segments[next].body;
|
|
|
|
options.encodedBodyLength = options.segments[next].encodedBodyLength;
|
|
|
|
options.segmentSeq = next + 1;
|
|
|
|
|
|
|
|
this.sendSMS(options);
|
|
|
|
},
|
|
|
|
|
2012-03-15 18:01:24 -07:00
|
|
|
/**
|
|
|
|
* Handle incoming messages from the main UI thread.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* Object containing the message. Messages are supposed
|
|
|
|
*/
|
|
|
|
handleDOMMessage: function handleMessage(message) {
|
|
|
|
if (DEBUG) debug("Received DOM message " + JSON.stringify(message));
|
|
|
|
let method = this[message.type];
|
|
|
|
if (typeof method != "function") {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Don't know what to do with message " + JSON.stringify(message));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
method.call(this, message);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of current voice calls.
|
|
|
|
*/
|
|
|
|
enumerateCalls: function enumerateCalls() {
|
|
|
|
if (DEBUG) debug("Sending all current calls");
|
|
|
|
let calls = [];
|
|
|
|
for each (let call in this.currentCalls) {
|
|
|
|
calls.push(call);
|
|
|
|
}
|
|
|
|
this.sendDOMMessage({type: "enumerateCalls", calls: calls});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of current data calls.
|
|
|
|
*/
|
|
|
|
enumerateDataCalls: function enumerateDataCalls() {
|
|
|
|
let datacall_list = [];
|
|
|
|
for each (let datacall in this.currentDataCalls) {
|
|
|
|
datacall_list.push(datacall);
|
|
|
|
}
|
|
|
|
this.sendDOMMessage({type: "datacalllist",
|
|
|
|
datacalls: datacall_list});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send messages to the main thread.
|
|
|
|
*/
|
|
|
|
sendDOMMessage: function sendDOMMessage(message) {
|
|
|
|
postMessage(message, "*");
|
|
|
|
},
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Handle incoming requests from the RIL. We find the method that
|
|
|
|
* corresponds to the request type. Incidentally, the request type
|
|
|
|
* _is_ the method name, so that's easy.
|
|
|
|
*/
|
|
|
|
|
2012-02-19 15:44:29 -08:00
|
|
|
handleParcel: function handleParcel(request_type, length, options) {
|
2011-12-04 23:58:27 -08:00
|
|
|
let method = this[request_type];
|
|
|
|
if (typeof method == "function") {
|
2012-02-02 10:41:07 -08:00
|
|
|
if (DEBUG) debug("Handling parcel as " + method.name);
|
2012-02-19 15:44:29 -08:00
|
|
|
method.call(this, length, options);
|
2011-12-04 23:58:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_GET_SIM_STATUS] = function REQUEST_GET_SIM_STATUS(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
let iccStatus = {};
|
|
|
|
iccStatus.cardState = Buf.readUint32(); // CARD_STATE_*
|
|
|
|
iccStatus.universalPINState = Buf.readUint32(); // CARD_PINSTATE_*
|
|
|
|
iccStatus.gsmUmtsSubscriptionAppIndex = Buf.readUint32();
|
|
|
|
iccStatus.cdmaSubscriptionAppIndex = Buf.readUint32();
|
|
|
|
if (!RILQUIRKS_V5_LEGACY) {
|
|
|
|
iccStatus.imsSubscriptionAppIndex = Buf.readUint32();
|
|
|
|
}
|
2011-12-04 23:58:27 -08:00
|
|
|
|
|
|
|
let apps_length = Buf.readUint32();
|
|
|
|
if (apps_length > CARD_MAX_APPS) {
|
|
|
|
apps_length = CARD_MAX_APPS;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
iccStatus.apps = [];
|
2011-12-04 23:58:27 -08:00
|
|
|
for (let i = 0 ; i < apps_length ; i++) {
|
|
|
|
iccStatus.apps.push({
|
2012-03-19 15:49:27 -07:00
|
|
|
app_type: Buf.readUint32(), // CARD_APPTYPE_*
|
|
|
|
app_state: Buf.readUint32(), // CARD_APPSTATE_*
|
|
|
|
perso_substate: Buf.readUint32(), // CARD_PERSOSUBSTATE_*
|
2011-12-04 23:58:27 -08:00
|
|
|
aid: Buf.readString(),
|
|
|
|
app_label: Buf.readString(),
|
|
|
|
pin1_replaced: Buf.readUint32(),
|
|
|
|
pin1: Buf.readUint32(),
|
|
|
|
pin2: Buf.readUint32()
|
|
|
|
});
|
|
|
|
}
|
2012-03-15 18:01:24 -07:00
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) debug("iccStatus: " + JSON.stringify(iccStatus));
|
|
|
|
this._processICCStatus(iccStatus);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_ENTER_SIM_PIN] = function REQUEST_ENTER_SIM_PIN(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
let response = Buf.readUint32List();
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) debug("REQUEST_ENTER_SIM_PIN returned " + response);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_ENTER_SIM_PUK] = function REQUEST_ENTER_SIM_PUK(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-10 14:53:08 -08:00
|
|
|
let response = Buf.readUint32List();
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) debug("REQUEST_ENTER_SIM_PUK returned " + response);
|
2012-01-10 14:53:08 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_ENTER_SIM_PIN2] = null;
|
|
|
|
RIL[REQUEST_ENTER_SIM_PUK2] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_CHANGE_SIM_PIN] = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_CHANGE_SIM_PIN2] = null;
|
|
|
|
RIL[REQUEST_ENTER_NETWORK_DEPERSONALIZATION] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_GET_CURRENT_CALLS] = function REQUEST_GET_CURRENT_CALLS(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-12 16:45:57 -07:00
|
|
|
this.initRILQuirks();
|
2012-02-02 10:41:07 -08:00
|
|
|
|
2011-12-06 22:57:05 -08:00
|
|
|
let calls_length = 0;
|
|
|
|
// The RIL won't even send us the length integer if there are no active calls.
|
|
|
|
// So only read this integer if the parcel actually has it.
|
|
|
|
if (length) {
|
|
|
|
calls_length = Buf.readUint32();
|
|
|
|
}
|
|
|
|
if (!calls_length) {
|
2012-03-15 17:47:00 -07:00
|
|
|
this._processCalls(null);
|
2011-12-06 22:57:05 -08:00
|
|
|
return;
|
|
|
|
}
|
2011-12-04 23:58:27 -08:00
|
|
|
|
2011-12-06 22:57:05 -08:00
|
|
|
let calls = {};
|
2011-12-04 23:58:27 -08:00
|
|
|
for (let i = 0; i < calls_length; i++) {
|
2012-02-02 10:41:07 -08:00
|
|
|
let call = {};
|
|
|
|
call.state = Buf.readUint32(); // CALL_STATE_*
|
|
|
|
call.callIndex = Buf.readUint32(); // GSM index (1-based)
|
|
|
|
call.toa = Buf.readUint32();
|
|
|
|
call.isMpty = Boolean(Buf.readUint32());
|
|
|
|
call.isMT = Boolean(Buf.readUint32());
|
|
|
|
call.als = Buf.readUint32();
|
|
|
|
call.isVoice = Boolean(Buf.readUint32());
|
|
|
|
call.isVoicePrivacy = Boolean(Buf.readUint32());
|
|
|
|
if (RILQUIRKS_CALLSTATE_EXTRA_UINT32) {
|
|
|
|
Buf.readUint32();
|
|
|
|
}
|
|
|
|
call.number = Buf.readString(); //TODO munge with TOA
|
|
|
|
call.numberPresentation = Buf.readUint32(); // CALL_PRESENTATION_*
|
|
|
|
call.name = Buf.readString();
|
|
|
|
call.namePresentation = Buf.readUint32();
|
|
|
|
|
|
|
|
call.uusInfo = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
let uusInfoPresent = Buf.readUint32();
|
|
|
|
if (uusInfoPresent == 1) {
|
2011-12-06 22:57:05 -08:00
|
|
|
call.uusInfo = {
|
2011-12-04 23:58:27 -08:00
|
|
|
type: Buf.readUint32(),
|
|
|
|
dcs: Buf.readUint32(),
|
|
|
|
userData: null //XXX TODO byte array?!?
|
|
|
|
};
|
|
|
|
}
|
2012-02-02 10:41:07 -08:00
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
calls[call.callIndex] = call;
|
2011-12-04 23:58:27 -08:00
|
|
|
}
|
2012-03-15 17:47:00 -07:00
|
|
|
this._processCalls(calls);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_DIAL] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_GET_IMSI] = function REQUEST_GET_IMSI(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this.IMSI = Buf.readString();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_HANGUP] = function REQUEST_HANGUP(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-05 01:12:42 -07:00
|
|
|
this.getCurrentCalls();
|
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_HANGUP_WAITING_OR_BACKGROUND] = null;
|
|
|
|
RIL[REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND] = null;
|
|
|
|
RIL[REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_SWITCH_HOLDING_AND_ACTIVE] = function REQUEST_SWITCH_HOLDING_AND_ACTIVE(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-05 01:12:42 -07:00
|
|
|
// XXX Normally we should get a UNSOLICITED_RESPONSE_CALL_STATE_CHANGED parcel
|
|
|
|
// notifying us of call state changes, but sometimes we don't (have no idea why).
|
|
|
|
// this.getCurrentCalls() helps update the call state actively.
|
|
|
|
this.getCurrentCalls();
|
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_CONFERENCE] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_UDUB] = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_LAST_CALL_FAIL_CAUSE] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_SIGNAL_STRENGTH] = function REQUEST_SIGNAL_STRENGTH(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
let obj = {};
|
|
|
|
|
|
|
|
// GSM
|
|
|
|
// Valid values are (0-31, 99) as defined in TS 27.007 8.5.
|
|
|
|
obj.gsmSignalStrength = Buf.readUint32();
|
2012-03-12 16:45:57 -07:00
|
|
|
// The SGS2 seems to compute the number of bars for us and expose those
|
|
|
|
// instead of the actual signal strength.
|
2012-03-20 12:28:15 -07:00
|
|
|
obj.bars = obj.gsmSignalStrength >> 8; //TODO remove this, see bug 729173
|
|
|
|
obj.gsmSignalStrength = obj.gsmSignalStrength & 0xff;
|
|
|
|
// GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5.
|
|
|
|
obj.gsmBitErrorRate = Buf.readUint32();
|
|
|
|
|
|
|
|
// CDMA
|
|
|
|
// The CDMA RSSI value.
|
|
|
|
obj.cdmaDBM = Buf.readUint32();
|
|
|
|
// The CDMA EC/IO.
|
|
|
|
obj.cdmaECIO = Buf.readUint32();
|
|
|
|
// The EVDO RSSI value.
|
|
|
|
|
|
|
|
// EVDO
|
|
|
|
obj.evdoDBM = Buf.readUint32();
|
|
|
|
// The EVDO EC/IO.
|
|
|
|
obj.evdoECIO = Buf.readUint32();
|
|
|
|
// Signal-to-noise ratio. Valid values are 0 to 8.
|
|
|
|
obj.evdoSNR = Buf.readUint32();
|
|
|
|
|
|
|
|
// LTE
|
|
|
|
if (!RILQUIRKS_V5_LEGACY) {
|
2011-12-04 23:58:27 -08:00
|
|
|
// Valid values are (0-31, 99) as defined in TS 27.007 8.5.
|
2012-03-20 12:28:15 -07:00
|
|
|
obj.lteSignalStrength = Buf.readUint32();
|
|
|
|
// Reference signal receive power in dBm, multiplied by -1.
|
|
|
|
// Valid values are 44 to 140.
|
|
|
|
obj.lteRSRP = Buf.readUint32();
|
|
|
|
// Reference signal receive quality in dB, multiplied by -1.
|
|
|
|
// Valid values are 3 to 20.
|
|
|
|
obj.lteRSRQ = Buf.readUint32();
|
|
|
|
// Signal-to-noise ratio for the reference signal.
|
|
|
|
// Valid values are -200 (20.0 dB) to +300 (30 dB).
|
|
|
|
obj.lteRSSNR = Buf.readUint32();
|
|
|
|
// Channel Quality Indicator, valid values are 0 to 15.
|
|
|
|
obj.lteCQI = Buf.readUint32();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) debug("Signal strength " + JSON.stringify(obj));
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "signalstrengthchange",
|
2012-03-20 12:28:15 -07:00
|
|
|
signalStrength: obj});
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_VOICE_REGISTRATION_STATE] = function REQUEST_VOICE_REGISTRATION_STATE(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
let state = Buf.readStringList();
|
2012-03-20 12:28:15 -07:00
|
|
|
debug("voice registration state: " + state);
|
2012-03-19 15:49:27 -07:00
|
|
|
this._processVoiceRegistrationState(state);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_DATA_REGISTRATION_STATE] = function REQUEST_DATA_REGISTRATION_STATE(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
let state = Buf.readStringList();
|
2012-03-19 15:49:27 -07:00
|
|
|
this._processDataRegistrationState(state);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_OPERATOR] = function REQUEST_OPERATOR(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
let operator = Buf.readStringList();
|
2012-03-20 12:28:15 -07:00
|
|
|
if (DEBUG) debug("Operator data: " + operator);
|
2012-03-15 17:47:00 -07:00
|
|
|
if (operator.length < 3) {
|
|
|
|
if (DEBUG) debug("Expected at least 3 strings for operator.");
|
|
|
|
}
|
|
|
|
if (!this.operator ||
|
|
|
|
this.operator.alphaLong != operator[0] ||
|
|
|
|
this.operator.alphaShort != operator[1] ||
|
|
|
|
this.operator.numeric != operator[2]) {
|
|
|
|
this.operator = {alphaLong: operator[0],
|
|
|
|
alphaShort: operator[1],
|
|
|
|
numeric: operator[2]};
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "operatorchange",
|
|
|
|
operator: this.operator});
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
|
|
|
RIL[REQUEST_RADIO_POWER] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_DTMF] = null;
|
2012-02-19 15:44:29 -08:00
|
|
|
RIL[REQUEST_SEND_SMS] = function REQUEST_SEND_SMS(length, options) {
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.rilRequestError) {
|
|
|
|
//TODO handle errors (bug 727319)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-19 15:44:29 -08:00
|
|
|
options.messageRef = Buf.readUint32();
|
|
|
|
options.ackPDU = Buf.readString();
|
|
|
|
options.errorCode = Buf.readUint32();
|
2012-03-16 16:59:35 -07:00
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.requestStatusReport) {
|
|
|
|
this._pendingSentSmsMap[options.messageRef] = options;
|
2012-03-16 16:59:35 -07:00
|
|
|
}
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
if ((options.segmentMaxSeq > 1)
|
|
|
|
&& (options.segmentSeq < options.segmentMaxSeq)) {
|
|
|
|
// Not last segment
|
|
|
|
if (!options.requestStatusReport) {
|
|
|
|
// Status-Report not requested, send next segment here.
|
|
|
|
this._processSentSmsSegment(options);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Last segment sent with success. Report it.
|
|
|
|
this.sendDOMMessage({
|
|
|
|
type: "sms-sent",
|
|
|
|
envelopeId: options.envelopeId,
|
|
|
|
});
|
|
|
|
}
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
|
|
|
RIL[REQUEST_SEND_SMS_EXPECT_MORE] = null;
|
2012-03-20 12:28:15 -07:00
|
|
|
|
|
|
|
RIL.readSetupDataCall_v5 = function readSetupDataCall_v5(options) {
|
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
2012-01-17 17:34:09 -08:00
|
|
|
let [cid, ifname, ipaddr, dns, gw] = Buf.readStringList();
|
2012-03-15 17:47:00 -07:00
|
|
|
options.cid = cid;
|
|
|
|
options.ifname = ifname;
|
|
|
|
options.ipaddr = ipaddr;
|
|
|
|
options.dns = dns;
|
|
|
|
options.gw = gw;
|
2012-03-15 17:47:00 -07:00
|
|
|
options.active = DATACALL_ACTIVE_UNKNOWN;
|
|
|
|
options.state = GECKO_NETWORK_STATE_CONNECTING;
|
2012-03-20 12:28:15 -07:00
|
|
|
return options;
|
|
|
|
};
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
RIL[REQUEST_SETUP_DATA_CALL] = function REQUEST_SETUP_DATA_CALL(length, options) {
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
if (RILQUIRKS_V5_LEGACY) {
|
|
|
|
this.readSetupDataCall_v5(options);
|
|
|
|
this.currentDataCalls[options.cid] = options;
|
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
|
|
|
datacall: options});
|
|
|
|
// Let's get the list of data calls to ensure we know whether it's active
|
|
|
|
// or not.
|
|
|
|
this.getDataCallList();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this[REQUEST_DATA_CALL_LIST](length, options);
|
2012-01-17 17:34:09 -08:00
|
|
|
};
|
2012-03-07 14:14:37 -08:00
|
|
|
RIL[REQUEST_SIM_IO] = function REQUEST_SIM_IO(length, options) {
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-28 20:46:06 -07:00
|
|
|
let sw1 = Buf.readUint32();
|
|
|
|
let sw2 = Buf.readUint32();
|
|
|
|
if (sw1 != ICC_STATUS_NORMAL_ENDING) {
|
|
|
|
// See GSM11.11, TS 51.011 clause 9.4, and ISO 7816-4 for the error
|
|
|
|
// description.
|
|
|
|
debug("ICC I/O Error EF id = " + options.fileid.toString(16) +
|
|
|
|
" command = " + options.command.toString(16) +
|
|
|
|
"(" + sw1.toString(16) + "/" + sw2.toString(16) + ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
switch (options.fileid) {
|
|
|
|
case ICC_EF_MSISDN:
|
|
|
|
this._processMSISDNResponse(options);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-07 14:14:37 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_SEND_USSD] = null;
|
|
|
|
RIL[REQUEST_CANCEL_USSD] = null;
|
|
|
|
RIL[REQUEST_GET_CLIR] = null;
|
|
|
|
RIL[REQUEST_SET_CLIR] = null;
|
|
|
|
RIL[REQUEST_QUERY_CALL_FORWARD_STATUS] = null;
|
|
|
|
RIL[REQUEST_SET_CALL_FORWARD] = null;
|
|
|
|
RIL[REQUEST_QUERY_CALL_WAITING] = null;
|
|
|
|
RIL[REQUEST_SET_CALL_WAITING] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_SMS_ACKNOWLEDGE] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_GET_IMEI] = function REQUEST_GET_IMEI(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this.IMEI = Buf.readString();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_GET_IMEISV] = function REQUEST_GET_IMEISV(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this.IMEISV = Buf.readString();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_ANSWER] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_DEACTIVATE_DATA_CALL] = function REQUEST_DEACTIVATE_DATA_CALL(length, options) {
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
let datacall = this.currentDataCalls[options.cid];
|
|
|
|
delete this.currentDataCalls[options.cid];
|
|
|
|
datacall.state = GECKO_NETWORK_STATE_DISCONNECTED;
|
2012-03-15 18:01:24 -07:00
|
|
|
this.sendDOMMessage({type: "datacallstatechange",
|
2012-03-15 17:47:00 -07:00
|
|
|
datacall: datacall});
|
2012-01-17 17:34:09 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_QUERY_FACILITY_LOCK] = null;
|
|
|
|
RIL[REQUEST_SET_FACILITY_LOCK] = null;
|
|
|
|
RIL[REQUEST_CHANGE_BARRING_PASSWORD] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_QUERY_NETWORK_SELECTION_MODE] = function REQUEST_QUERY_NETWORK_SELECTION_MODE(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
let mode = Buf.readUint32List();
|
|
|
|
this.networkSelectionMode = mode[0];
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
|
|
|
RIL[REQUEST_SET_NETWORK_SELECTION_AUTOMATIC] = null;
|
|
|
|
RIL[REQUEST_SET_NETWORK_SELECTION_MANUAL] = null;
|
|
|
|
RIL[REQUEST_QUERY_AVAILABLE_NETWORKS] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_DTMF_START] = null;
|
|
|
|
RIL[REQUEST_DTMF_STOP] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_BASEBAND_VERSION] = function REQUEST_BASEBAND_VERSION(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this.basebandVersion = Buf.readString();
|
2012-03-20 12:28:15 -07:00
|
|
|
if (DEBUG) debug("Baseband version: " + this.basebandVersion);
|
2012-01-17 17:34:09 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_SEPARATE_CONNECTION] = null;
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_SET_MUTE] = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_GET_MUTE] = null;
|
|
|
|
RIL[REQUEST_QUERY_CLIP] = null;
|
|
|
|
RIL[REQUEST_LAST_DATA_CALL_FAIL_CAUSE] = null;
|
2012-03-12 16:45:57 -07:00
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
RIL.readDataCall_v5 = function readDataCall_v5() {
|
|
|
|
return {
|
|
|
|
cid: Buf.readUint32().toString(),
|
|
|
|
active: Buf.readUint32(), // DATACALL_ACTIVE_*
|
|
|
|
type: Buf.readString(),
|
|
|
|
apn: Buf.readString(),
|
|
|
|
address: Buf.readString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
RIL.readDataCall_v6 = function readDataCall_v6(obj) {
|
|
|
|
if (!obj) {
|
|
|
|
obj = {};
|
|
|
|
}
|
|
|
|
obj.status = Buf.readUint32(); // DATACALL_FAIL_*
|
|
|
|
obj.suggestedRetryTime = Buf.readUint32();
|
|
|
|
obj.cid = Buf.readUint32().toString();
|
|
|
|
obj.active = Buf.readUint32(); // DATACALL_ACTIVE_*
|
|
|
|
obj.type = Buf.readString();
|
|
|
|
obj.ifname = Buf.readString();
|
|
|
|
obj.ipaddr = Buf.readString();
|
|
|
|
obj.dns = Buf.readString();
|
|
|
|
obj.gw = Buf.readString();
|
|
|
|
if (obj.dns) {
|
|
|
|
obj.dns = obj.dns.split(" ");
|
2012-02-10 11:27:38 -08:00
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
//TODO for now we only support one address and gateway
|
|
|
|
if (obj.ipaddr) {
|
|
|
|
obj.ipaddr = obj.ipaddr.split(" ")[0];
|
|
|
|
}
|
|
|
|
if (obj.gw) {
|
|
|
|
obj.gw = obj.gw.split(" ")[0];
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[REQUEST_DATA_CALL_LIST] = function REQUEST_DATA_CALL_LIST(length, options) {
|
|
|
|
if (options.rilRequestError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
this.initRILQuirks();
|
|
|
|
if (!length) {
|
2012-03-15 17:47:00 -07:00
|
|
|
this._processDataCallList(null);
|
2012-01-17 17:34:09 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
let version = 0;
|
|
|
|
if (!RILQUIRKS_V5_LEGACY) {
|
|
|
|
version = Buf.readUint32();
|
|
|
|
}
|
|
|
|
let num = num = Buf.readUint32();
|
2012-02-10 11:27:38 -08:00
|
|
|
let datacalls = {};
|
2012-01-17 17:34:09 -08:00
|
|
|
for (let i = 0; i < num; i++) {
|
2012-03-20 12:28:15 -07:00
|
|
|
let datacall;
|
|
|
|
if (version < 6) {
|
|
|
|
datacall = this.readDataCall_v5();
|
|
|
|
} else {
|
|
|
|
datacall = this.readDataCall_v6();
|
|
|
|
}
|
2012-02-10 11:27:38 -08:00
|
|
|
datacalls[datacall.cid] = datacall;
|
2012-01-17 17:34:09 -08:00
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this._processDataCallList(datacalls);
|
2012-01-17 17:34:09 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_RESET_RADIO] = null;
|
|
|
|
RIL[REQUEST_OEM_HOOK_RAW] = null;
|
|
|
|
RIL[REQUEST_OEM_HOOK_STRINGS] = null;
|
|
|
|
RIL[REQUEST_SCREEN_STATE] = null;
|
|
|
|
RIL[REQUEST_SET_SUPP_SVC_NOTIFICATION] = null;
|
|
|
|
RIL[REQUEST_WRITE_SMS_TO_SIM] = null;
|
|
|
|
RIL[REQUEST_DELETE_SMS_ON_SIM] = null;
|
|
|
|
RIL[REQUEST_SET_BAND_MODE] = null;
|
|
|
|
RIL[REQUEST_QUERY_AVAILABLE_BAND_MODE] = null;
|
|
|
|
RIL[REQUEST_STK_GET_PROFILE] = null;
|
|
|
|
RIL[REQUEST_STK_SET_PROFILE] = null;
|
|
|
|
RIL[REQUEST_STK_SEND_ENVELOPE_COMMAND] = null;
|
|
|
|
RIL[REQUEST_STK_SEND_TERMINAL_RESPONSE] = null;
|
|
|
|
RIL[REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM] = null;
|
|
|
|
RIL[REQUEST_EXPLICIT_CALL_TRANSFER] = null;
|
|
|
|
RIL[REQUEST_SET_PREFERRED_NETWORK_TYPE] = null;
|
|
|
|
RIL[REQUEST_GET_PREFERRED_NETWORK_TYPE] = null;
|
|
|
|
RIL[REQUEST_GET_NEIGHBORING_CELL_IDS] = null;
|
|
|
|
RIL[REQUEST_SET_LOCATION_UPDATES] = null;
|
2012-03-20 12:28:15 -07:00
|
|
|
RIL[REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE] = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_CDMA_SET_ROAMING_PREFERENCE] = null;
|
|
|
|
RIL[REQUEST_CDMA_QUERY_ROAMING_PREFERENCE] = null;
|
|
|
|
RIL[REQUEST_SET_TTY_MODE] = null;
|
|
|
|
RIL[REQUEST_QUERY_TTY_MODE] = null;
|
|
|
|
RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE] = null;
|
|
|
|
RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE] = null;
|
|
|
|
RIL[REQUEST_CDMA_FLASH] = null;
|
|
|
|
RIL[REQUEST_CDMA_BURST_DTMF] = null;
|
|
|
|
RIL[REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY] = null;
|
|
|
|
RIL[REQUEST_CDMA_SEND_SMS] = null;
|
|
|
|
RIL[REQUEST_CDMA_SMS_ACKNOWLEDGE] = null;
|
|
|
|
RIL[REQUEST_GSM_GET_BROADCAST_SMS_CONFIG] = null;
|
|
|
|
RIL[REQUEST_GSM_SET_BROADCAST_SMS_CONFIG] = null;
|
|
|
|
RIL[REQUEST_GSM_SMS_BROADCAST_ACTIVATION] = null;
|
|
|
|
RIL[REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG] = null;
|
|
|
|
RIL[REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG] = null;
|
|
|
|
RIL[REQUEST_CDMA_SMS_BROADCAST_ACTIVATION] = null;
|
|
|
|
RIL[REQUEST_CDMA_SUBSCRIPTION] = null;
|
|
|
|
RIL[REQUEST_CDMA_WRITE_SMS_TO_RUIM] = null;
|
|
|
|
RIL[REQUEST_CDMA_DELETE_SMS_ON_RUIM] = null;
|
|
|
|
RIL[REQUEST_DEVICE_IDENTITY] = null;
|
|
|
|
RIL[REQUEST_EXIT_EMERGENCY_CALLBACK_MODE] = null;
|
2012-02-23 07:29:38 -08:00
|
|
|
RIL[REQUEST_GET_SMSC_ADDRESS] = function REQUEST_GET_SMSC_ADDRESS(length, options) {
|
2012-04-05 14:16:56 -07:00
|
|
|
if (options.rilRequestError) {
|
|
|
|
//TODO: notify main thread if we fail retrieving the SMSC, especially
|
|
|
|
// if there was a pending SMS (bug 727319).
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
this.SMSC = Buf.readString();
|
|
|
|
// If the SMSC was not retrieved on RIL initialization, an attempt to
|
|
|
|
// get it is triggered from this.sendSMS followed by the 'options'
|
|
|
|
// parameter of the SMS, so that we can send it after successfully
|
|
|
|
// retrieving the SMSC.
|
|
|
|
if (this.SMSC && options.body) {
|
|
|
|
this.sendSMS(options);
|
|
|
|
}
|
2011-12-23 21:02:51 -08:00
|
|
|
};
|
2012-03-15 17:47:00 -07:00
|
|
|
RIL[REQUEST_SET_SMSC_ADDRESS] = null;
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[REQUEST_REPORT_SMS_MEMORY_STATUS] = null;
|
|
|
|
RIL[REQUEST_REPORT_STK_SERVICE_IS_RUNNING] = null;
|
|
|
|
RIL[UNSOLICITED_RESPONSE_RADIO_STATE_CHANGED] = function UNSOLICITED_RESPONSE_RADIO_STATE_CHANGED() {
|
2012-03-20 12:28:15 -07:00
|
|
|
let radioState = Buf.readUint32();
|
|
|
|
|
|
|
|
let newState;
|
|
|
|
if (radioState == RADIO_STATE_UNAVAILABLE) {
|
|
|
|
newState = GECKO_RADIOSTATE_UNAVAILABLE;
|
|
|
|
} else if (radioState == RADIO_STATE_OFF) {
|
|
|
|
newState = GECKO_RADIOSTATE_OFF;
|
|
|
|
} else {
|
|
|
|
newState = GECKO_RADIOSTATE_READY;
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) {
|
2012-03-20 12:28:15 -07:00
|
|
|
debug("Radio state changed from '" + this.radioState +
|
|
|
|
"' to '" + newState + "'");
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
|
|
|
if (this.radioState == newState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
// TODO hardcoded for now (see bug 726098)
|
|
|
|
let cdma = false;
|
2012-03-15 17:47:00 -07:00
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
if (this.radioState == GECKO_RADIOSTATE_UNAVAILABLE &&
|
|
|
|
newState != GECKO_RADIOSTATE_UNAVAILABLE) {
|
2012-03-15 17:47:00 -07:00
|
|
|
// The radio became available, let's get its info.
|
|
|
|
if (cdma) {
|
|
|
|
this.getDeviceIdentity();
|
2012-03-20 12:28:15 -07:00
|
|
|
} else {
|
|
|
|
this.getIMEI();
|
|
|
|
this.getIMEISV();
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
|
|
|
this.getBasebandVersion();
|
|
|
|
|
|
|
|
//XXX TODO For now, just turn the radio on if it's off. for the real
|
|
|
|
// deal we probably want to do the opposite: start with a known state
|
|
|
|
// when we boot up and let the UI layer control the radio power.
|
2012-03-20 12:28:15 -07:00
|
|
|
if (newState == GECKO_RADIOSTATE_OFF) {
|
2012-03-15 17:47:00 -07:00
|
|
|
this.setRadioPower(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 12:28:15 -07:00
|
|
|
this.radioState = newState;
|
|
|
|
this.sendDOMMessage({
|
|
|
|
type: "radiostatechange",
|
|
|
|
radioState: newState
|
|
|
|
});
|
|
|
|
|
|
|
|
// If the radio is up and on, so let's query the card state.
|
|
|
|
// On older RILs only if the card is actually ready, though.
|
|
|
|
if (radioState == RADIO_STATE_UNAVAILABLE ||
|
|
|
|
radioState == RADIO_STATE_OFF) {
|
|
|
|
return;
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
if (RILQUIRKS_V5_LEGACY &&
|
|
|
|
(radioState == RADIO_STATE_SIM_NOT_READY ||
|
|
|
|
radioState == RADIO_STATE_RUIM_NOT_READY ||
|
|
|
|
radioState == RADIO_STATE_NV_NOT_READY)) {
|
|
|
|
return;
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
2012-03-20 12:28:15 -07:00
|
|
|
this.getICCStatus();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
|
|
|
RIL[UNSOLICITED_RESPONSE_CALL_STATE_CHANGED] = function UNSOLICITED_RESPONSE_CALL_STATE_CHANGED() {
|
2012-03-15 17:47:00 -07:00
|
|
|
this.getCurrentCalls();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-03-19 15:49:27 -07:00
|
|
|
RIL[UNSOLICITED_RESPONSE_VOICE_NETWORK_STATE_CHANGED] = function UNSOLICITED_RESPONSE_VOICE_NETWORK_STATE_CHANGED() {
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) debug("Network state changed, re-requesting phone state.");
|
|
|
|
this.requestNetworkInfo();
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2011-12-23 21:02:51 -08:00
|
|
|
RIL[UNSOLICITED_RESPONSE_NEW_SMS] = function UNSOLICITED_RESPONSE_NEW_SMS(length) {
|
2012-04-05 14:16:56 -07:00
|
|
|
let result = this._processSmsDeliver(length);
|
|
|
|
this.acknowledgeSMS(result == PDU_FCS_OK, result);
|
2011-12-23 21:02:51 -08:00
|
|
|
};
|
|
|
|
RIL[UNSOLICITED_RESPONSE_NEW_SMS_STATUS_REPORT] = function UNSOLICITED_RESPONSE_NEW_SMS_STATUS_REPORT(length) {
|
2012-04-05 14:16:56 -07:00
|
|
|
let result = this._processSmsStatusReport(length);
|
|
|
|
this.acknowledgeSMS(result == PDU_FCS_OK, result);
|
2011-12-23 21:02:51 -08:00
|
|
|
};
|
|
|
|
RIL[UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM] = function UNSOLICITED_RESPONSE_NEW_SMS_ON_SIM(length) {
|
|
|
|
let info = Buf.readUint32List();
|
2012-03-15 17:47:00 -07:00
|
|
|
//TODO
|
2011-12-23 21:02:51 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[UNSOLICITED_ON_USSD] = null;
|
|
|
|
RIL[UNSOLICITED_ON_USSD_REQUEST] = null;
|
2012-03-08 20:16:06 -08:00
|
|
|
|
|
|
|
RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = function UNSOLICITED_NITZ_TIME_RECEIVED() {
|
|
|
|
let dateString = Buf.readString();
|
|
|
|
|
|
|
|
// The data contained in the NITZ message is
|
|
|
|
// in the form "yy/mm/dd,hh:mm:ss(+/-)tz,dt"
|
|
|
|
// for example: 12/02/16,03:36:08-20,00,310410
|
|
|
|
|
|
|
|
// Always print the NITZ info so we can collection what different providers
|
|
|
|
// send down the pipe (see bug XXX).
|
|
|
|
// TODO once data is collected, add in |if (DEBUG)|
|
|
|
|
|
|
|
|
debug("DateTimeZone string " + dateString);
|
|
|
|
|
|
|
|
let now = Date.now();
|
|
|
|
|
|
|
|
let year = parseInt(dateString.substr(0, 2), 10);
|
|
|
|
let month = parseInt(dateString.substr(3, 2), 10);
|
|
|
|
let day = parseInt(dateString.substr(6, 2), 10);
|
|
|
|
let hours = parseInt(dateString.substr(9, 2), 10);
|
|
|
|
let minutes = parseInt(dateString.substr(12, 2), 10);
|
|
|
|
let seconds = parseInt(dateString.substr(15, 2), 10);
|
|
|
|
let tz = parseInt(dateString.substr(17, 3), 10); // TZ is in 15 min. units
|
|
|
|
let dst = parseInt(dateString.substr(21, 2), 10); // DST already is in local time
|
|
|
|
|
|
|
|
let timeInSeconds = Date.UTC(year + PDU_TIMESTAMP_YEAR_OFFSET, month - 1, day,
|
|
|
|
hours, minutes, seconds) / 1000;
|
|
|
|
|
|
|
|
if (isNaN(timeInSeconds)) {
|
2012-03-15 18:01:24 -07:00
|
|
|
if (DEBUG) debug("NITZ failed to convert date");
|
|
|
|
return;
|
2012-03-08 20:16:06 -08:00
|
|
|
}
|
2012-03-15 18:01:24 -07:00
|
|
|
|
|
|
|
this.sendDOMMessage({type: "nitzTime",
|
|
|
|
networkTimeInSeconds: timeInSeconds,
|
|
|
|
networkTimeZoneInMinutes: tz * 15,
|
|
|
|
dstFlag: dst,
|
|
|
|
localTimeStampInMS: now});
|
2012-03-08 20:16:06 -08:00
|
|
|
};
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[UNSOLICITED_SIGNAL_STRENGTH] = function UNSOLICITED_SIGNAL_STRENGTH(length) {
|
|
|
|
this[REQUEST_SIGNAL_STRENGTH](length, {rilRequestError: ERROR_SUCCESS});
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[UNSOLICITED_DATA_CALL_LIST_CHANGED] = function UNSOLICITED_DATA_CALL_LIST_CHANGED(length) {
|
2012-03-20 12:28:15 -07:00
|
|
|
if (RILQUIRKS_V5_LEGACY) {
|
|
|
|
this.getDataCallList();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-05 14:16:56 -07:00
|
|
|
this[REQUEST_GET_DATA_CALL_LIST](length, {rilRequestError: ERROR_SUCCESS});
|
2012-02-10 11:27:38 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[UNSOLICITED_SUPP_SVC_NOTIFICATION] = null;
|
|
|
|
RIL[UNSOLICITED_STK_SESSION_END] = null;
|
|
|
|
RIL[UNSOLICITED_STK_PROACTIVE_COMMAND] = null;
|
|
|
|
RIL[UNSOLICITED_STK_EVENT_NOTIFY] = null;
|
|
|
|
RIL[UNSOLICITED_STK_CALL_SETUP] = null;
|
|
|
|
RIL[UNSOLICITED_SIM_SMS_STORAGE_FULL] = null;
|
|
|
|
RIL[UNSOLICITED_SIM_REFRESH] = null;
|
2011-12-06 22:57:05 -08:00
|
|
|
RIL[UNSOLICITED_CALL_RING] = function UNSOLICITED_CALL_RING() {
|
2011-12-12 14:34:18 -08:00
|
|
|
let info;
|
|
|
|
let isCDMA = false; //XXX TODO hard-code this for now
|
|
|
|
if (isCDMA) {
|
|
|
|
info = {
|
|
|
|
isPresent: Buf.readUint32(),
|
|
|
|
signalType: Buf.readUint32(),
|
|
|
|
alertPitch: Buf.readUint32(),
|
|
|
|
signal: Buf.readUint32()
|
|
|
|
};
|
|
|
|
}
|
2012-03-15 17:47:00 -07:00
|
|
|
// For now we don't need to do anything here because we'll also get a
|
|
|
|
// call state changed notification.
|
2011-12-06 22:57:05 -08:00
|
|
|
};
|
2012-01-10 14:53:08 -08:00
|
|
|
RIL[UNSOLICITED_RESPONSE_SIM_STATUS_CHANGED] = function UNSOLICITED_RESPONSE_SIM_STATUS_CHANGED() {
|
2012-03-15 17:47:00 -07:00
|
|
|
this.getICCStatus();
|
2012-01-10 14:53:08 -08:00
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
RIL[UNSOLICITED_RESPONSE_CDMA_NEW_SMS] = null;
|
|
|
|
RIL[UNSOLICITED_RESPONSE_NEW_BROADCAST_SMS] = null;
|
|
|
|
RIL[UNSOLICITED_CDMA_RUIM_SMS_STORAGE_FULL] = null;
|
|
|
|
RIL[UNSOLICITED_RESTRICTED_STATE_CHANGED] = null;
|
|
|
|
RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE] = null;
|
|
|
|
RIL[UNSOLICITED_CDMA_CALL_WAITING] = null;
|
|
|
|
RIL[UNSOLICITED_CDMA_OTA_PROVISION_STATUS] = null;
|
|
|
|
RIL[UNSOLICITED_CDMA_INFO_REC] = null;
|
|
|
|
RIL[UNSOLICITED_OEM_HOOK_RAW] = null;
|
|
|
|
RIL[UNSOLICITED_RINGBACK_TONE] = null;
|
|
|
|
RIL[UNSOLICITED_RESEND_INCALL_MUTE] = null;
|
2012-04-05 14:16:56 -07:00
|
|
|
RIL[UNSOLICITED_RIL_CONNECTED] = function UNSOLICITED_RIL_CONNECTED(length) {
|
2012-03-20 12:28:15 -07:00
|
|
|
let version = Buf.readUint32List()[0];
|
|
|
|
RILQUIRKS_V5_LEGACY = (version < 5);
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Detected RIL version " + version);
|
|
|
|
debug("RILQUIRKS_V5_LEGACY is " + RILQUIRKS_V5_LEGACY);
|
|
|
|
}
|
|
|
|
};
|
2011-12-04 23:58:27 -08:00
|
|
|
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* This object exposes the functionality to parse and serialize PDU strings
|
|
|
|
*
|
|
|
|
* A PDU is a string containing a series of hexadecimally encoded octets
|
|
|
|
* or nibble-swapped binary-coded decimals (BCDs). It contains not only the
|
2011-12-23 21:02:51 -08:00
|
|
|
* message text but information about the sender, the SMS service center,
|
2011-12-23 21:02:51 -08:00
|
|
|
* timestamp, etc.
|
|
|
|
*/
|
|
|
|
let GsmPDUHelper = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read one character (2 bytes) from a RIL string and decode as hex.
|
|
|
|
*
|
|
|
|
* @return the nibble as a number.
|
|
|
|
*/
|
|
|
|
readHexNibble: function readHexNibble() {
|
|
|
|
let nibble = Buf.readUint16();
|
|
|
|
if (nibble >= 48 && nibble <= 57) {
|
2011-12-23 21:02:51 -08:00
|
|
|
nibble -= 48; // ASCII '0'..'9'
|
2011-12-23 21:02:51 -08:00
|
|
|
} else if (nibble >= 65 && nibble <= 70) {
|
2011-12-23 21:02:51 -08:00
|
|
|
nibble -= 55; // ASCII 'A'..'F'
|
2011-12-23 21:02:51 -08:00
|
|
|
} else if (nibble >= 97 && nibble <= 102) {
|
2011-12-23 21:02:51 -08:00
|
|
|
nibble -= 87; // ASCII 'a'..'f'
|
2011-12-23 21:02:51 -08:00
|
|
|
} else {
|
|
|
|
throw "Found invalid nibble during PDU parsing: " +
|
|
|
|
String.fromCharCode(nibble);
|
|
|
|
}
|
|
|
|
return nibble;
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Encode a nibble as one hex character in a RIL string (2 bytes).
|
|
|
|
*
|
|
|
|
* @param nibble
|
|
|
|
* The nibble to encode (represented as a number)
|
|
|
|
*/
|
|
|
|
writeHexNibble: function writeHexNibble(nibble) {
|
|
|
|
nibble &= 0x0f;
|
|
|
|
if (nibble < 10) {
|
|
|
|
nibble += 48; // ASCII '0'
|
|
|
|
} else {
|
|
|
|
nibble += 55; // ASCII 'A'
|
|
|
|
}
|
|
|
|
Buf.writeUint16(nibble);
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Read a hex-encoded octet (two nibbles).
|
|
|
|
*
|
|
|
|
* @return the octet as a number.
|
|
|
|
*/
|
|
|
|
readHexOctet: function readHexOctet() {
|
|
|
|
return (this.readHexNibble() << 4) | this.readHexNibble();
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Write an octet as two hex-encoded nibbles.
|
|
|
|
*
|
|
|
|
* @param octet
|
|
|
|
* The octet (represented as a number) to encode.
|
|
|
|
*/
|
|
|
|
writeHexOctet: function writeHexOctet(octet) {
|
|
|
|
this.writeHexNibble(octet >> 4);
|
|
|
|
this.writeHexNibble(octet);
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Convert an octet (number) to a BCD number.
|
|
|
|
*
|
|
|
|
* Any nibbles that are not in the BCD range count as 0.
|
|
|
|
*
|
|
|
|
* @param octet
|
|
|
|
* The octet (a number, as returned by getOctet())
|
|
|
|
*
|
|
|
|
* @return the corresponding BCD number.
|
|
|
|
*/
|
|
|
|
octetToBCD: function octetToBCD(octet) {
|
|
|
|
return ((octet & 0xf0) <= 0x90) * ((octet >> 4) & 0x0f) +
|
|
|
|
((octet & 0x0f) <= 0x09) * (octet & 0x0f) * 10;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a *swapped nibble* binary coded decimal (BCD)
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* Number of nibble *pairs* to read.
|
|
|
|
*
|
|
|
|
* @return the decimal as a number.
|
|
|
|
*/
|
|
|
|
readSwappedNibbleBCD: function readSwappedNibbleBCD(length) {
|
|
|
|
let number = 0;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
let octet = this.readHexOctet();
|
2012-03-15 17:47:00 -07:00
|
|
|
// Ignore 'ff' octets as they're often used as filler.
|
|
|
|
if (octet == 0xff) {
|
2012-03-07 14:14:37 -08:00
|
|
|
continue;
|
2012-03-15 17:47:00 -07:00
|
|
|
}
|
2011-12-23 21:02:51 -08:00
|
|
|
// If the first nibble is an "F" , only the second nibble is to be taken
|
|
|
|
// into account.
|
|
|
|
if ((octet & 0xf0) == 0xf0) {
|
|
|
|
number *= 10;
|
|
|
|
number += octet & 0x0f;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
number *= 100;
|
|
|
|
number += this.octetToBCD(octet);
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
},
|
|
|
|
|
2012-03-07 14:14:37 -08:00
|
|
|
/**
|
|
|
|
* Read a string from Buf and convert it to BCD
|
|
|
|
*
|
|
|
|
* @return the decimal as a number.
|
|
|
|
*/
|
|
|
|
readStringAsBCD: function readStringAsBCD() {
|
|
|
|
let length = Buf.readUint32();
|
|
|
|
let bcd = this.readSwappedNibbleBCD(length / 2);
|
|
|
|
let delimiter = Buf.readUint16();
|
|
|
|
if (!(length & 1)) {
|
|
|
|
delimiter |= Buf.readUint16();
|
|
|
|
}
|
2012-03-15 17:47:00 -07:00
|
|
|
if (DEBUG) {
|
|
|
|
if (delimiter != 0) {
|
|
|
|
debug("Something's wrong, found string delimiter: " + delimiter);
|
|
|
|
}
|
|
|
|
}
|
2012-03-07 14:14:37 -08:00
|
|
|
return bcd;
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Write numerical data as swapped nibble BCD.
|
2012-01-10 14:53:08 -08:00
|
|
|
*
|
2011-12-23 21:02:51 -08:00
|
|
|
* @param data
|
|
|
|
* Data to write (as a string or a number)
|
|
|
|
*/
|
|
|
|
writeSwappedNibbleBCD: function writeSwappedNibbleBCD(data) {
|
|
|
|
data = data.toString();
|
|
|
|
if (data.length % 2) {
|
|
|
|
data += "F";
|
|
|
|
}
|
|
|
|
for (let i = 0; i < data.length; i += 2) {
|
|
|
|
Buf.writeUint16(data.charCodeAt(i + 1));
|
|
|
|
Buf.writeUint16(data.charCodeAt(i));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Read user data, convert to septets, look up relevant characters in a
|
|
|
|
* 7-bit alphabet, and construct string.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* Number of septets to read (*not* octets)
|
2012-03-02 04:51:47 -08:00
|
|
|
* @param paddingBits
|
|
|
|
* Number of padding bits in the first byte of user data.
|
|
|
|
* @param langIndex
|
|
|
|
* Table index used for normal 7-bit encoded character lookup.
|
|
|
|
* @param langShiftIndex
|
|
|
|
* Table index used for escaped 7-bit encoded character lookup.
|
2011-12-23 21:02:51 -08:00
|
|
|
*
|
|
|
|
* @return a string.
|
|
|
|
*/
|
2012-03-02 04:51:47 -08:00
|
|
|
readSeptetsToString: function readSeptetsToString(length, paddingBits, langIndex, langShiftIndex) {
|
2011-12-23 21:02:51 -08:00
|
|
|
let ret = "";
|
2012-03-02 04:51:47 -08:00
|
|
|
let byteLength = Math.ceil((length * 7 + paddingBits) / 8);
|
2011-12-23 21:02:51 -08:00
|
|
|
|
2012-03-02 04:51:47 -08:00
|
|
|
/**
|
|
|
|
* |<- last byte in header ->|
|
|
|
|
* |<- incompleteBits ->|<- last header septet->|
|
|
|
|
* +===7===|===6===|===5===|===4===|===3===|===2===|===1===|===0===|
|
|
|
|
*
|
|
|
|
* |<- 1st byte in user data ->|
|
|
|
|
* |<- data septet 1 ->|<-paddingBits->|
|
|
|
|
* +===7===|===6===|===5===|===4===|===3===|===2===|===1===|===0===|
|
|
|
|
*
|
|
|
|
* |<- 2nd byte in user data ->|
|
|
|
|
* |<- data spetet 2 ->|<-ds1->|
|
|
|
|
* +===7===|===6===|===5===|===4===|===3===|===2===|===1===|===0===|
|
|
|
|
*/
|
|
|
|
let data = 0;
|
|
|
|
let dataBits = 0;
|
|
|
|
if (paddingBits) {
|
|
|
|
data = this.readHexOctet() >> paddingBits;
|
|
|
|
dataBits = 8 - paddingBits;
|
|
|
|
--byteLength;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:51:47 -08:00
|
|
|
|
|
|
|
let escapeFound = false;
|
|
|
|
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[langIndex];
|
|
|
|
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[langShiftIndex];
|
|
|
|
do {
|
|
|
|
// Read as much as fits in 32bit word
|
|
|
|
let bytesToRead = Math.min(byteLength, dataBits ? 3 : 4);
|
|
|
|
for (let i = 0; i < bytesToRead; i++) {
|
|
|
|
data |= this.readHexOctet() << dataBits;
|
|
|
|
dataBits += 8;
|
|
|
|
--byteLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consume available full septets
|
|
|
|
for (; dataBits >= 7; dataBits -= 7) {
|
|
|
|
let septet = data & 0x7F;
|
|
|
|
data >>>= 7;
|
|
|
|
|
|
|
|
if (escapeFound) {
|
|
|
|
escapeFound = false;
|
|
|
|
if (septet == PDU_NL_EXTENDED_ESCAPE) {
|
|
|
|
// According to 3GPP TS 23.038, section 6.2.1.1, NOTE 1, "On
|
|
|
|
// receipt of this code, a receiving entity shall display a space
|
|
|
|
// until another extensiion table is defined."
|
|
|
|
ret += " ";
|
|
|
|
} else if (septet == PDU_NL_RESERVED_CONTROL) {
|
|
|
|
// According to 3GPP TS 23.038 B.2, "This code represents a control
|
|
|
|
// character and therefore must not be used for language specific
|
|
|
|
// characters."
|
|
|
|
ret += " ";
|
|
|
|
} else {
|
|
|
|
ret += langShiftTable[septet];
|
|
|
|
}
|
|
|
|
} else if (septet == PDU_NL_EXTENDED_ESCAPE) {
|
|
|
|
escapeFound = true;
|
2012-03-07 14:21:05 -08:00
|
|
|
|
|
|
|
// <escape> is not an effective character
|
|
|
|
--length;
|
2012-03-02 04:51:47 -08:00
|
|
|
} else {
|
|
|
|
ret += langTable[septet];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (byteLength);
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
if (ret.length != length) {
|
2012-03-07 14:21:05 -08:00
|
|
|
/**
|
|
|
|
* If num of effective characters does not equal to the length of read
|
|
|
|
* string, cut the tail off. This happens when the last octet of user
|
|
|
|
* data has following layout:
|
|
|
|
*
|
|
|
|
* |<- penultimate octet in user data ->|
|
|
|
|
* |<- data septet N ->|<- dsN-1 ->|
|
|
|
|
* +===7===|===6===|===5===|===4===|===3===|===2===|===1===|===0===|
|
|
|
|
*
|
|
|
|
* |<- last octet in user data ->|
|
|
|
|
* |<- fill bits ->|<-dsN->|
|
|
|
|
* +===7===|===6===|===5===|===4===|===3===|===2===|===1===|===0===|
|
|
|
|
*
|
|
|
|
* The fill bits in the last octet may happen to form a full septet and
|
|
|
|
* be appended at the end of result string.
|
|
|
|
*/
|
2011-12-23 21:02:51 -08:00
|
|
|
ret = ret.slice(0, length);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2012-03-02 04:41:37 -08:00
|
|
|
writeStringAsSeptets: function writeStringAsSeptets(message, paddingBits, langIndex, langShiftIndex) {
|
|
|
|
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[langIndex];
|
|
|
|
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[langShiftIndex];
|
|
|
|
|
|
|
|
let dataBits = paddingBits;
|
|
|
|
let data = 0;
|
|
|
|
for (let i = 0; i < message.length; i++) {
|
|
|
|
let septet = langTable.indexOf(message[i]);
|
|
|
|
if (septet == PDU_NL_EXTENDED_ESCAPE) {
|
|
|
|
continue;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:41:37 -08:00
|
|
|
|
|
|
|
if (septet >= 0) {
|
|
|
|
data |= septet << dataBits;
|
|
|
|
dataBits += 7;
|
|
|
|
} else {
|
|
|
|
septet = langShiftTable.indexOf(message[i]);
|
|
|
|
if (septet == -1) {
|
|
|
|
throw new Error(message[i] + " not in 7 bit alphabet "
|
|
|
|
+ langIndex + ":" + langShiftIndex + "!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (septet == PDU_NL_RESERVED_CONTROL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
data |= PDU_NL_EXTENDED_ESCAPE << dataBits;
|
|
|
|
dataBits += 7;
|
|
|
|
data |= septet << dataBits;
|
|
|
|
dataBits += 7;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:41:37 -08:00
|
|
|
|
|
|
|
for (; dataBits >= 8; dataBits -= 8) {
|
|
|
|
this.writeHexOctet(data & 0xFF);
|
|
|
|
data >>>= 8;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:41:37 -08:00
|
|
|
}
|
2011-12-23 21:02:51 -08:00
|
|
|
|
2012-03-02 04:41:37 -08:00
|
|
|
if (dataBits != 0) {
|
|
|
|
this.writeHexOctet(data & 0xFF);
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Read user data and decode as a UCS2 string.
|
|
|
|
*
|
2012-02-21 08:27:28 -08:00
|
|
|
* @param numOctets
|
|
|
|
* num of octets to read as UCS2 string.
|
2011-12-23 21:02:51 -08:00
|
|
|
*
|
|
|
|
* @return a string.
|
|
|
|
*/
|
2012-02-21 08:27:28 -08:00
|
|
|
readUCS2String: function readUCS2String(numOctets) {
|
|
|
|
let str = "";
|
|
|
|
let length = numOctets / 2;
|
|
|
|
for (let i = 0; i < length; ++i) {
|
|
|
|
let code = (this.readHexOctet() << 8) | this.readHexOctet();
|
|
|
|
str += String.fromCharCode(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) debug("Read UCS2 string: " + str);
|
|
|
|
|
|
|
|
return str;
|
2011-12-23 21:02:51 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write user data as a UCS2 string.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* Message string to encode as UCS2 in hex-encoded octets.
|
|
|
|
*/
|
|
|
|
writeUCS2String: function writeUCS2String(message) {
|
2012-02-21 08:27:28 -08:00
|
|
|
for (let i = 0; i < message.length; ++i) {
|
|
|
|
let code = message.charCodeAt(i);
|
|
|
|
this.writeHexOctet((code >> 8) & 0xFF);
|
|
|
|
this.writeHexOctet(code & 0xFF);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-02 04:51:47 -08:00
|
|
|
/**
|
|
|
|
* Read 1 + UDHL octets and construct user data header at return.
|
|
|
|
*
|
|
|
|
* @return A header object with properties contained in received message.
|
|
|
|
* The properties set include:
|
|
|
|
* <ul>
|
|
|
|
* <li>length: totoal length of the header, default 0.
|
|
|
|
* <li>langIndex: used locking shift table index, default
|
|
|
|
* PDU_NL_IDENTIFIER_DEFAULT.
|
|
|
|
* <li>langShiftIndex: used locking shift table index, default
|
|
|
|
* PDU_NL_IDENTIFIER_DEFAULT.
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
readUserDataHeader: function readUserDataHeader() {
|
|
|
|
let header = {
|
|
|
|
length: 0,
|
|
|
|
langIndex: PDU_NL_IDENTIFIER_DEFAULT,
|
|
|
|
langShiftIndex: PDU_NL_IDENTIFIER_DEFAULT
|
|
|
|
};
|
|
|
|
|
|
|
|
header.length = this.readHexOctet();
|
|
|
|
let dataAvailable = header.length;
|
|
|
|
while (dataAvailable >= 2) {
|
|
|
|
let id = this.readHexOctet();
|
|
|
|
let length = this.readHexOctet();
|
|
|
|
dataAvailable -= 2;
|
|
|
|
|
|
|
|
switch (id) {
|
2012-03-16 17:02:06 -07:00
|
|
|
case PDU_IEI_CONCATENATED_SHORT_MESSAGES_8BIT: {
|
|
|
|
let ref = this.readHexOctet();
|
|
|
|
let max = this.readHexOctet();
|
|
|
|
let seq = this.readHexOctet();
|
|
|
|
dataAvailable -= 3;
|
|
|
|
if (max && seq && (seq <= max)) {
|
|
|
|
header.segmentRef = ref;
|
|
|
|
header.segmentMaxSeq = max;
|
|
|
|
header.segmentSeq = seq;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PDU_IEI_CONCATENATED_SHORT_MESSAGES_16BIT: {
|
|
|
|
let ref = (this.readHexOctet() << 8) | this.readHexOctet();
|
|
|
|
let max = this.readHexOctet();
|
|
|
|
let seq = this.readHexOctet();
|
|
|
|
dataAvailable -= 4;
|
|
|
|
if (max && seq && (seq <= max)) {
|
|
|
|
header.segmentRef = ref;
|
|
|
|
header.segmentMaxSeq = max;
|
|
|
|
header.segmentSeq = seq;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-02 04:51:47 -08:00
|
|
|
case PDU_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT:
|
|
|
|
let langShiftIndex = this.readHexOctet();
|
|
|
|
--dataAvailable;
|
|
|
|
if (langShiftIndex < PDU_NL_SINGLE_SHIFT_TABLES.length) {
|
|
|
|
header.langShiftIndex = langShiftIndex;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PDU_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT:
|
|
|
|
let langIndex = this.readHexOctet();
|
|
|
|
--dataAvailable;
|
|
|
|
if (langIndex < PDU_NL_LOCKING_SHIFT_TABLES.length) {
|
|
|
|
header.langIndex = langIndex;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("readUserDataHeader: unsupported IEI(" + id
|
|
|
|
+ "), " + length + " bytes.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read out unsupported data
|
|
|
|
if (length) {
|
|
|
|
let octets;
|
|
|
|
if (DEBUG) octets = new Uint8Array(length);
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
let octet = this.readHexOctet();
|
|
|
|
if (DEBUG) octets[i] = octet;
|
|
|
|
}
|
|
|
|
dataAvailable -= length;
|
|
|
|
|
|
|
|
if (DEBUG) debug("readUserDataHeader: " + Array.slice(octets));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataAvailable != 0) {
|
|
|
|
throw new Error("Illegal user data header found!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write out user data header.
|
|
|
|
*
|
|
|
|
* @param options
|
|
|
|
* Options containing information for user data header write-out. The
|
|
|
|
* `userDataHeaderLength` property must be correctly pre-calculated.
|
|
|
|
*/
|
2012-03-02 04:41:37 -08:00
|
|
|
writeUserDataHeader: function writeUserDataHeader(options) {
|
|
|
|
this.writeHexOctet(options.userDataHeaderLength);
|
|
|
|
|
2012-03-16 16:59:35 -07:00
|
|
|
if (options.segmentMaxSeq > 1) {
|
|
|
|
if (options.segmentRef16Bit) {
|
|
|
|
this.writeHexOctet(PDU_IEI_CONCATENATED_SHORT_MESSAGES_16BIT);
|
|
|
|
this.writeHexOctet(4);
|
|
|
|
this.writeHexOctet((options.segmentRef >> 8) & 0xFF);
|
|
|
|
} else {
|
|
|
|
this.writeHexOctet(PDU_IEI_CONCATENATED_SHORT_MESSAGES_8BIT);
|
|
|
|
this.writeHexOctet(3);
|
|
|
|
}
|
|
|
|
this.writeHexOctet(options.segmentRef & 0xFF);
|
|
|
|
this.writeHexOctet(options.segmentMaxSeq & 0xFF);
|
|
|
|
this.writeHexOctet(options.segmentSeq & 0xFF);
|
|
|
|
}
|
|
|
|
|
2012-03-02 04:41:37 -08:00
|
|
|
if (options.langIndex != PDU_NL_IDENTIFIER_DEFAULT) {
|
|
|
|
this.writeHexOctet(PDU_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT);
|
|
|
|
this.writeHexOctet(1);
|
|
|
|
this.writeHexOctet(options.langIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.langShiftIndex != PDU_NL_IDENTIFIER_DEFAULT) {
|
|
|
|
this.writeHexOctet(PDU_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT);
|
|
|
|
this.writeHexOctet(1);
|
|
|
|
this.writeHexOctet(options.langShiftIndex);
|
2012-02-21 08:27:28 -08:00
|
|
|
}
|
2011-12-23 21:02:51 -08:00
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Read SM-TL Address.
|
|
|
|
*
|
|
|
|
* @see 3GPP TS 23.040 9.1.2.5
|
|
|
|
*/
|
|
|
|
readAddress: function readAddress(len) {
|
|
|
|
// Address Length
|
|
|
|
if (!len || (len < 0)) {
|
|
|
|
if (DEBUG) debug("PDU error: invalid sender address length: " + len);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (len % 2 == 1) {
|
|
|
|
len += 1;
|
|
|
|
}
|
|
|
|
if (DEBUG) debug("PDU: Going to read address: " + len);
|
|
|
|
|
|
|
|
// Type-of-Address
|
|
|
|
let toa = this.readHexOctet();
|
|
|
|
|
|
|
|
// Address-Value
|
|
|
|
let addr = this.readSwappedNibbleBCD(len / 2).toString();
|
|
|
|
if (addr.length <= 0) {
|
|
|
|
if (DEBUG) debug("PDU error: no number provided");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ((toa >> 4) == (PDU_TOA_INTERNATIONAL >> 4)) {
|
|
|
|
addr = '+' + addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read GSM TP-Service-Centre-Time-Stamp(TP-SCTS).
|
|
|
|
*
|
|
|
|
* @see 3GPP TS 23.040 9.2.3.11
|
|
|
|
*/
|
|
|
|
readTimestamp: function readTimestamp() {
|
|
|
|
let year = this.readSwappedNibbleBCD(1) + PDU_TIMESTAMP_YEAR_OFFSET;
|
|
|
|
let month = this.readSwappedNibbleBCD(1) - 1;
|
|
|
|
let day = this.readSwappedNibbleBCD(1);
|
|
|
|
let hour = this.readSwappedNibbleBCD(1);
|
|
|
|
let minute = this.readSwappedNibbleBCD(1);
|
|
|
|
let second = this.readSwappedNibbleBCD(1);
|
|
|
|
let timestamp = Date.UTC(year, month, day, hour, minute, second);
|
|
|
|
|
|
|
|
// If the most significant bit of the least significant nibble is 1,
|
|
|
|
// the timezone offset is negative (fourth bit from the right => 0x08).
|
|
|
|
let tzOctet = this.readHexOctet();
|
|
|
|
let tzOffset = this.octetToBCD(tzOctet & ~0x08) * 15 * 60 * 1000;
|
|
|
|
if (tzOctet & 0x08) {
|
|
|
|
timestamp -= tzOffset;
|
|
|
|
} else {
|
|
|
|
timestamp += tzOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timestamp;
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* User data can be 7 bit (default alphabet) data, 8 bit data, or 16 bit
|
|
|
|
* (UCS2) data.
|
2012-03-16 16:59:58 -07:00
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
* message object for output.
|
|
|
|
* @param length
|
|
|
|
* length of user data to read in octets.
|
2011-12-23 21:02:51 -08:00
|
|
|
*/
|
2012-04-05 14:16:56 -07:00
|
|
|
readUserData: function readUserData(msg, length) {
|
|
|
|
let dcs = msg.dcs;
|
2011-12-23 21:02:51 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
debug("Reading " + length + " bytes of user data.");
|
2012-04-05 14:16:56 -07:00
|
|
|
debug("Coding scheme: " + dcs);
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
// 7 bit is the default fallback encoding.
|
2011-12-23 21:02:51 -08:00
|
|
|
let encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET;
|
2012-04-05 14:16:56 -07:00
|
|
|
switch (dcs & 0xC0) {
|
2011-12-23 21:02:51 -08:00
|
|
|
case 0x0:
|
|
|
|
// bits 7..4 = 00xx
|
2012-04-05 14:16:56 -07:00
|
|
|
switch (dcs & 0x0C) {
|
2011-12-23 21:02:51 -08:00
|
|
|
case 0x4:
|
2011-12-23 21:02:51 -08:00
|
|
|
encoding = PDU_DCS_MSG_CODING_8BITS_ALPHABET;
|
2011-12-23 21:02:51 -08:00
|
|
|
break;
|
|
|
|
case 0x8:
|
2011-12-23 21:02:51 -08:00
|
|
|
encoding = PDU_DCS_MSG_CODING_16BITS_ALPHABET;
|
2011-12-23 21:02:51 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xC0:
|
|
|
|
// bits 7..4 = 11xx
|
2012-04-05 14:16:56 -07:00
|
|
|
switch (dcs & 0x30) {
|
2011-12-23 21:02:51 -08:00
|
|
|
case 0x20:
|
2011-12-23 21:02:51 -08:00
|
|
|
encoding = PDU_DCS_MSG_CODING_16BITS_ALPHABET;
|
2011-12-23 21:02:51 -08:00
|
|
|
break;
|
|
|
|
case 0x30:
|
2012-04-05 14:16:56 -07:00
|
|
|
if (!dcs & 0x04) {
|
2011-12-23 21:02:51 -08:00
|
|
|
encoding = PDU_DCS_MSG_CODING_8BITS_ALPHABET;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Falling back to default encoding.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-16 16:59:58 -07:00
|
|
|
if (DEBUG) debug("PDU: message encoding is " + encoding + " bit.");
|
|
|
|
|
2012-03-02 04:51:47 -08:00
|
|
|
let paddingBits = 0;
|
2012-04-05 14:16:56 -07:00
|
|
|
if (msg.udhi) {
|
2012-03-16 16:59:58 -07:00
|
|
|
msg.header = this.readUserDataHeader();
|
2012-03-02 04:51:47 -08:00
|
|
|
|
|
|
|
if (encoding == PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
|
2012-03-16 16:59:58 -07:00
|
|
|
let headerBits = (msg.header.length + 1) * 8;
|
2012-03-02 04:51:47 -08:00
|
|
|
let headerSeptets = Math.ceil(headerBits / 7);
|
|
|
|
|
|
|
|
length -= headerSeptets;
|
|
|
|
paddingBits = headerSeptets * 7 - headerBits;
|
|
|
|
} else {
|
2012-03-16 16:59:58 -07:00
|
|
|
length -= (msg.header.length + 1);
|
2012-03-02 04:51:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-16 16:59:58 -07:00
|
|
|
msg.body = null;
|
2011-12-23 21:02:51 -08:00
|
|
|
switch (encoding) {
|
2011-12-23 21:02:51 -08:00
|
|
|
case PDU_DCS_MSG_CODING_7BITS_ALPHABET:
|
2011-12-23 21:02:51 -08:00
|
|
|
// 7 bit encoding allows 140 octets, which means 160 characters
|
|
|
|
// ((140x8) / 7 = 160 chars)
|
|
|
|
if (length > PDU_MAX_USER_DATA_7BIT) {
|
|
|
|
if (DEBUG) debug("PDU error: user data is too long: " + length);
|
2012-03-16 16:59:58 -07:00
|
|
|
break;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:51:47 -08:00
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
let langIndex = msg.udhi ? msg.header.langIndex : PDU_NL_IDENTIFIER_DEFAULT;
|
|
|
|
let langShiftIndex = msg.udhi ? msg.header.langShiftIndex : PDU_NL_IDENTIFIER_DEFAULT;
|
2012-03-16 16:59:58 -07:00
|
|
|
msg.body = this.readSeptetsToString(length, paddingBits, langIndex,
|
|
|
|
langShiftIndex);
|
|
|
|
break;
|
2011-12-23 21:02:51 -08:00
|
|
|
case PDU_DCS_MSG_CODING_8BITS_ALPHABET:
|
2011-12-23 21:02:51 -08:00
|
|
|
// Unsupported.
|
2012-03-16 16:59:58 -07:00
|
|
|
break;
|
2011-12-23 21:02:51 -08:00
|
|
|
case PDU_DCS_MSG_CODING_16BITS_ALPHABET:
|
2012-03-16 16:59:58 -07:00
|
|
|
msg.body = this.readUCS2String(length);
|
|
|
|
break;
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Read extra parameters if TP-PI is set.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
* message object for output.
|
|
|
|
*/
|
|
|
|
readExtraParams: function readExtraParams(msg) {
|
|
|
|
// Because each PDU octet is converted to two UCS2 char2, we should always
|
|
|
|
// get even messageStringLength in this#_processReceivedSms(). So, we'll
|
|
|
|
// always need two delimitors at the end.
|
|
|
|
if (Buf.readAvailable <= 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TP-Parameter-Indicator
|
|
|
|
let pi;
|
|
|
|
do {
|
|
|
|
// `The most significant bit in octet 1 and any other TP-PI octets which
|
|
|
|
// may be added later is reserved as an extension bit which when set to a
|
|
|
|
// 1 shall indicate that another TP-PI octet follows immediately
|
|
|
|
// afterwards.` ~ 3GPP TS 23.040 9.2.3.27
|
|
|
|
pi = this.readHexOctet();
|
|
|
|
} while (pi & PDU_PI_EXTENSION);
|
|
|
|
|
|
|
|
// `If the TP-UDL bit is set to "1" but the TP-DCS bit is set to "0" then
|
|
|
|
// the receiving entity shall for TP-DCS assume a value of 0x00, i.e. the
|
|
|
|
// 7bit default alphabet.` ~ 3GPP 23.040 9.2.3.27
|
|
|
|
msg.dcs = 0;
|
|
|
|
|
|
|
|
// TP-Protocol-Identifier
|
|
|
|
if (pi & PDU_PI_PROTOCOL_IDENTIFIER) {
|
|
|
|
msg.pid = this.readHexOctet();
|
|
|
|
}
|
|
|
|
// TP-Data-Coding-Scheme
|
|
|
|
if (pi & PDU_PI_DATA_CODING_SCHEME) {
|
|
|
|
msg.dcs = this.readHexOctet();
|
|
|
|
}
|
|
|
|
// TP-User-Data-Length
|
|
|
|
if (pi & PDU_PI_USER_DATA_LENGTH) {
|
|
|
|
let userDataLength = this.readHexOctet();
|
|
|
|
this.readUserData(msg, userDataLength);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Read and decode a PDU-encoded message from the stream.
|
|
|
|
*
|
|
|
|
* TODO: add some basic sanity checks like:
|
|
|
|
* - do we have the minimum number of chars available
|
|
|
|
*/
|
|
|
|
readMessage: function readMessage() {
|
|
|
|
// An empty message object. This gets filled below and then returned.
|
|
|
|
let msg = {
|
2012-04-05 14:16:56 -07:00
|
|
|
// D:DELIVER, DR:DELIVER-REPORT, S:SUBMIT, SR:SUBMIT-REPORT,
|
|
|
|
// ST:STATUS-REPORT, C:COMMAND
|
|
|
|
// M:Mandatory, O:Optional, X:Unavailable
|
|
|
|
// D DR S SR ST C
|
|
|
|
SMSC: null, // M M M M M M
|
|
|
|
mti: null, // M M M M M M
|
|
|
|
udhi: null, // M M X M M M
|
|
|
|
sender: null, // M X X X X X
|
|
|
|
recipient: null, // X X M X M M
|
|
|
|
pid: null, // M O M O O M
|
|
|
|
dcs: null, // M O M O O X
|
|
|
|
body: null, // M O M O O O
|
|
|
|
timestamp: null, // M X X X X X
|
|
|
|
status: null, // X X X X M X
|
|
|
|
scts: null, // X X X M M X
|
|
|
|
dt: null, // X X X X M X
|
2011-12-23 21:02:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// SMSC info
|
|
|
|
let smscLength = this.readHexOctet();
|
|
|
|
if (smscLength > 0) {
|
|
|
|
let smscTypeOfAddress = this.readHexOctet();
|
|
|
|
// Subtract the type-of-address octet we just read from the length.
|
|
|
|
msg.SMSC = this.readSwappedNibbleBCD(smscLength - 1).toString();
|
|
|
|
if ((smscTypeOfAddress >> 4) == (PDU_TOA_INTERNATIONAL >> 4)) {
|
|
|
|
msg.SMSC = '+' + msg.SMSC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// First octet of this SMS-DELIVER or SMS-SUBMIT message
|
|
|
|
let firstOctet = this.readHexOctet();
|
2012-04-05 14:16:56 -07:00
|
|
|
// Message Type Indicator
|
|
|
|
msg.mti = firstOctet & 0x03;
|
2012-03-02 04:51:47 -08:00
|
|
|
// User data header indicator
|
2012-04-05 14:16:56 -07:00
|
|
|
msg.udhi = firstOctet & PDU_UDHI;
|
|
|
|
|
|
|
|
switch (msg.mti) {
|
|
|
|
case PDU_MTI_SMS_RESERVED:
|
|
|
|
// `If an MS receives a TPDU with a "Reserved" value in the TP-MTI it
|
|
|
|
// shall process the message as if it were an "SMS-DELIVER" but store
|
|
|
|
// the message exactly as received.` ~ 3GPP TS 23.040 9.2.3.1
|
|
|
|
case PDU_MTI_SMS_DELIVER:
|
|
|
|
return this.readDeliverMessage(msg);
|
2012-04-05 14:16:56 -07:00
|
|
|
case PDU_MTI_SMS_STATUS_REPORT:
|
|
|
|
return this.readStatusReportMessage(msg);
|
2012-04-05 14:16:56 -07:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2012-03-02 04:51:47 -08:00
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Read and decode a SMS-DELIVER PDU.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
* message object for output.
|
|
|
|
*/
|
|
|
|
readDeliverMessage: function readDeliverMessage(msg) {
|
2011-12-23 21:02:51 -08:00
|
|
|
// - Sender Address info -
|
|
|
|
let senderAddressLength = this.readHexOctet();
|
2012-04-05 14:16:56 -07:00
|
|
|
msg.sender = this.readAddress(senderAddressLength);
|
2011-12-23 21:02:51 -08:00
|
|
|
// - TP-Protocolo-Identifier -
|
2012-04-05 14:16:56 -07:00
|
|
|
msg.pid = this.readHexOctet();
|
2011-12-23 21:02:51 -08:00
|
|
|
// - TP-Data-Coding-Scheme -
|
2012-04-05 14:16:56 -07:00
|
|
|
msg.dcs = this.readHexOctet();
|
2012-04-05 14:16:56 -07:00
|
|
|
// - TP-Service-Center-Time-Stamp -
|
2012-04-05 14:16:56 -07:00
|
|
|
msg.timestamp = this.readTimestamp();
|
2011-12-23 21:02:51 -08:00
|
|
|
// - TP-User-Data-Length -
|
|
|
|
let userDataLength = this.readHexOctet();
|
|
|
|
|
|
|
|
// - TP-User-Data -
|
|
|
|
if (userDataLength > 0) {
|
2012-04-05 14:16:56 -07:00
|
|
|
this.readUserData(msg, userDataLength);
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
2011-12-23 21:02:51 -08:00
|
|
|
},
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
/**
|
|
|
|
* Read and decode a SMS-STATUS-REPORT PDU.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
* message object for output.
|
|
|
|
*/
|
|
|
|
readStatusReportMessage: function readStatusReportMessage(msg) {
|
|
|
|
// TP-Message-Reference
|
|
|
|
msg.messageRef = this.readHexOctet();
|
|
|
|
// TP-Recipient-Address
|
|
|
|
let recipientAddressLength = this.readHexOctet();
|
|
|
|
msg.recipient = this.readAddress(recipientAddressLength);
|
|
|
|
// TP-Service-Centre-Time-Stamp
|
|
|
|
msg.scts = this.readTimestamp();
|
|
|
|
// TP-Discharge-Time
|
|
|
|
msg.dt = this.readTimestamp();
|
|
|
|
// TP-Status
|
|
|
|
msg.status = this.readHexOctet();
|
|
|
|
|
|
|
|
this.readExtraParams(msg);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
},
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
/**
|
|
|
|
* Serialize a SMS-SUBMIT PDU message and write it to the output stream.
|
|
|
|
*
|
|
|
|
* This method expects that a data coding scheme has been chosen already
|
|
|
|
* and that the length of the user data payload in that encoding is known,
|
|
|
|
* too. Both go hand in hand together anyway.
|
|
|
|
*
|
|
|
|
* @param address
|
|
|
|
* String containing the address (number) of the SMS receiver
|
|
|
|
* @param userData
|
|
|
|
* String containing the message to be sent as user data
|
|
|
|
* @param dcs
|
|
|
|
* Data coding scheme. One of the PDU_DCS_MSG_CODING_*BITS_ALPHABET
|
|
|
|
* constants.
|
2012-03-02 04:41:37 -08:00
|
|
|
* @param userDataHeaderLength
|
|
|
|
* Length of embedded user data header, in bytes. The whole header
|
|
|
|
* size will be userDataHeaderLength + 1; 0 for no header.
|
|
|
|
* @param encodedBodyLength
|
|
|
|
* Length of the user data when encoded with the given DCS. For UCS2,
|
|
|
|
* in bytes; for 7-bit, in septets.
|
|
|
|
* @param langIndex
|
|
|
|
* Table index used for normal 7-bit encoded character lookup.
|
|
|
|
* @param langShiftIndex
|
|
|
|
* Table index used for escaped 7-bit encoded character lookup.
|
2012-04-05 14:16:56 -07:00
|
|
|
* @param requestStatusReport
|
|
|
|
* Request status report.
|
2012-03-02 04:41:37 -08:00
|
|
|
*/
|
|
|
|
writeMessage: function writeMessage(options) {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("writeMessage: " + JSON.stringify(options));
|
|
|
|
}
|
|
|
|
let address = options.number;
|
|
|
|
let body = options.body;
|
|
|
|
let dcs = options.dcs;
|
|
|
|
let userDataHeaderLength = options.userDataHeaderLength;
|
|
|
|
let encodedBodyLength = options.encodedBodyLength;
|
|
|
|
let langIndex = options.langIndex;
|
|
|
|
let langShiftIndex = options.langShiftIndex;
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
// SMS-SUBMIT Format:
|
|
|
|
//
|
|
|
|
// PDU Type - 1 octet
|
|
|
|
// Message Reference - 1 octet
|
|
|
|
// DA - Destination Address - 2 to 12 octets
|
|
|
|
// PID - Protocol Identifier - 1 octet
|
|
|
|
// DCS - Data Coding Scheme - 1 octet
|
|
|
|
// VP - Validity Period - 0, 1 or 7 octets
|
|
|
|
// UDL - User Data Length - 1 octet
|
|
|
|
// UD - User Data - 140 octets
|
|
|
|
|
|
|
|
let addressFormat = PDU_TOA_ISDN; // 81
|
|
|
|
if (address[0] == '+') {
|
|
|
|
addressFormat = PDU_TOA_INTERNATIONAL | PDU_TOA_ISDN; // 91
|
|
|
|
address = address.substring(1);
|
|
|
|
}
|
|
|
|
//TODO validity is unsupported for now
|
|
|
|
let validity = 0;
|
|
|
|
|
2012-03-02 04:41:37 -08:00
|
|
|
let headerOctets = (userDataHeaderLength ? userDataHeaderLength + 1 : 0);
|
|
|
|
let paddingBits;
|
|
|
|
let userDataLengthInSeptets;
|
|
|
|
let userDataLengthInOctets;
|
|
|
|
if (dcs == PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
|
|
|
|
let headerSeptets = Math.ceil(headerOctets * 8 / 7);
|
|
|
|
userDataLengthInSeptets = headerSeptets + encodedBodyLength;
|
|
|
|
userDataLengthInOctets = Math.ceil(userDataLengthInSeptets * 7 / 8);
|
|
|
|
paddingBits = headerSeptets * 7 - headerOctets * 8;
|
|
|
|
} else {
|
|
|
|
userDataLengthInOctets = headerOctets + encodedBodyLength;
|
|
|
|
paddingBits = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
let pduOctetLength = 4 + // PDU Type, Message Ref, address length + format
|
|
|
|
Math.ceil(address.length / 2) +
|
|
|
|
3 + // PID, DCS, UDL
|
|
|
|
userDataLengthInOctets;
|
|
|
|
if (validity) {
|
|
|
|
//TODO: add more to pduOctetLength
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the string. Since octets are represented in hex, we will need
|
|
|
|
// twice as many characters as octets.
|
|
|
|
Buf.writeUint32(pduOctetLength * 2);
|
|
|
|
|
|
|
|
// - PDU-TYPE-
|
|
|
|
|
|
|
|
// +--------+----------+---------+---------+--------+---------+
|
|
|
|
// | RP (1) | UDHI (1) | SRR (1) | VPF (2) | RD (1) | MTI (2) |
|
|
|
|
// +--------+----------+---------+---------+--------+---------+
|
|
|
|
// RP: 0 Reply path parameter is not set
|
|
|
|
// 1 Reply path parameter is set
|
|
|
|
// UDHI: 0 The UD Field contains only the short message
|
|
|
|
// 1 The beginning of the UD field contains a header in addition
|
|
|
|
// of the short message
|
|
|
|
// SRR: 0 A status report is not requested
|
|
|
|
// 1 A status report is requested
|
|
|
|
// VPF: bit4 bit3
|
|
|
|
// 0 0 VP field is not present
|
|
|
|
// 0 1 Reserved
|
|
|
|
// 1 0 VP field present an integer represented (relative)
|
|
|
|
// 1 1 VP field present a semi-octet represented (absolute)
|
|
|
|
// RD: Instruct the SMSC to accept(0) or reject(1) an SMS-SUBMIT
|
|
|
|
// for a short message still held in the SMSC which has the same
|
|
|
|
// MR and DA as a previously submitted short message from the
|
|
|
|
// same OA
|
|
|
|
// MTI: bit1 bit0 Message Type
|
|
|
|
// 0 0 SMS-DELIVER (SMSC ==> MS)
|
|
|
|
// 0 1 SMS-SUBMIT (MS ==> SMSC)
|
|
|
|
|
|
|
|
// PDU type. MTI is set to SMS-SUBMIT
|
|
|
|
let firstOctet = PDU_MTI_SMS_SUBMIT;
|
|
|
|
|
2012-04-05 14:16:56 -07:00
|
|
|
// Status-Report-Request
|
|
|
|
if (options.requestStatusReport) {
|
|
|
|
firstOctet |= PDU_SRI_SRR;
|
|
|
|
}
|
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
// Validity period
|
|
|
|
if (validity) {
|
|
|
|
//TODO: not supported yet, OR with one of PDU_VPF_*
|
|
|
|
}
|
2012-03-02 04:41:37 -08:00
|
|
|
// User data header indicator
|
|
|
|
if (headerOctets) {
|
2011-12-23 21:02:51 -08:00
|
|
|
firstOctet |= PDU_UDHI;
|
|
|
|
}
|
|
|
|
this.writeHexOctet(firstOctet);
|
|
|
|
|
|
|
|
// Message reference 00
|
|
|
|
this.writeHexOctet(0x00);
|
|
|
|
|
|
|
|
// - Destination Address -
|
|
|
|
this.writeHexOctet(address.length);
|
|
|
|
this.writeHexOctet(addressFormat);
|
|
|
|
this.writeSwappedNibbleBCD(address);
|
|
|
|
|
|
|
|
// - Protocol Identifier -
|
|
|
|
this.writeHexOctet(0x00);
|
|
|
|
|
|
|
|
// - Data coding scheme -
|
|
|
|
// For now it assumes bits 7..4 = 1111 except for the 16 bits use case
|
|
|
|
this.writeHexOctet(dcs);
|
|
|
|
|
|
|
|
// - Validity Period -
|
|
|
|
if (validity) {
|
|
|
|
this.writeHexOctet(validity);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - User Data -
|
2012-03-02 04:41:37 -08:00
|
|
|
if (dcs == PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
|
|
|
|
this.writeHexOctet(userDataLengthInSeptets);
|
|
|
|
} else {
|
|
|
|
this.writeHexOctet(userDataLengthInOctets);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (headerOctets) {
|
|
|
|
this.writeUserDataHeader(options);
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
2012-03-02 04:41:37 -08:00
|
|
|
|
2011-12-23 21:02:51 -08:00
|
|
|
switch (dcs) {
|
|
|
|
case PDU_DCS_MSG_CODING_7BITS_ALPHABET:
|
2012-03-02 04:41:37 -08:00
|
|
|
this.writeStringAsSeptets(body, paddingBits, langIndex, langShiftIndex);
|
2011-12-23 21:02:51 -08:00
|
|
|
break;
|
|
|
|
case PDU_DCS_MSG_CODING_8BITS_ALPHABET:
|
|
|
|
// Unsupported.
|
|
|
|
break;
|
|
|
|
case PDU_DCS_MSG_CODING_16BITS_ALPHABET:
|
2012-03-02 04:41:37 -08:00
|
|
|
this.writeUCS2String(body);
|
2011-12-23 21:02:51 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of the string. The string length is always even by definition, so
|
|
|
|
// we write two \0 delimiters.
|
|
|
|
Buf.writeUint16(0);
|
|
|
|
Buf.writeUint16(0);
|
2011-12-23 21:02:51 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-04 23:58:27 -08:00
|
|
|
/**
|
|
|
|
* Global stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!this.debug) {
|
|
|
|
// Debugging stub that goes nowhere.
|
|
|
|
this.debug = function debug(message) {
|
|
|
|
dump("RIL Worker: " + message + "\n");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize buffers. This is a separate function so that unit tests can
|
|
|
|
// re-initialize the buffers at will.
|
|
|
|
Buf.init();
|
|
|
|
|
|
|
|
function onRILMessage(data) {
|
|
|
|
Buf.processIncoming(data);
|
|
|
|
};
|
|
|
|
|
|
|
|
onmessage = function onmessage(event) {
|
2012-03-15 18:01:24 -07:00
|
|
|
RIL.handleDOMMessage(event.data);
|
2011-12-04 23:58:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
onerror = function onerror(event) {
|
|
|
|
debug("RIL Worker error" + event.message + "\n");
|
|
|
|
};
|