aboutsummaryrefslogtreecommitdiff
path: root/u300-ril-oem-parser.h
blob: 5023a046a9997d6e67ed6982f5c5e990d4fa310e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* ST-Ericsson U300 RIL
**
** Copyright (C) ST-Ericsson AB 2008-2010
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** Based on reference-ril by The Android Open Source Project.
**
** Heavily modified for ST-Ericsson U300 modems.
** Author: Dmitry Tarnyagin <dmitry.tarnyagin@stericsson.com>
*/

#ifndef U300_RIL_OEM_PARSER_H
#define U300_RIL_OEM_PARSER_H 1

#include <binder/Parcel.h>
#include <sys/endian.h>

#include <vector>

#include "u300-ril-oem-msg.h"

/* private */
namespace u300_ril
{

/** U300 OEM RIL serializer/deserializer */
class OemRilParser
{
    typedef android::status_t status_t;

public:
    typedef struct {
        long frequency;
        long strength;
     } pairFrequencyReportItem_t;
    typedef std::vector<pairFrequencyReportItem_t> vecFrequencyReport_t;

    OemRilParser();
    ~OemRilParser();

    /** Set data buffer
     *
     * This method should be called before any parseXXX methods.
     * OemRilParser makes a private copy of a buffer (according to
     * android::Parcel implementation).
     *
     * \param buffer:   [in] input buffer.
     * \param len:      [in] size of the buffer in bytes.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    inline status_t     setData(uint8_t *buffer, size_t len);

    /** Get data buffer
     *
     * This method returns a pointer to the internal data buffer.
     *
     * \retval          Pointer to the internal data buffer.
     */
    inline const uint8_t *data() const;

    /** Get data buffer size
     *
     * This method returns actual size of data in the internal data buffer.
     *
     * \retval          Data size in bytes.
     */
    inline size_t         dataSize() const;

    /** Parse header of U300 OEM RIL message.
     *
     * This method should be called before any other
     * parseXXX methods.
     *
     * \param msg_id:   [out] u300_ril_oem_msg_id of the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          BAD_TYPE indicates invalid U300 OEM signature.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NAME_NOT_FOUND indicates invalid message id.
     */
    status_t            parseHeader(/*out*/ uint32_t *msg_id);

#ifdef U300_RIL_OEM_MSG_SELFTEST
    /** Parse OEM PING request.
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parsePing(/*out*/ struct u300_ril_oem_ping_request *request);
#endif /* U300_RIL_OEM_MSG_SELFTEST */

    /** Parse OEM UPDATE_FREQUENCY_SUBSCRIPTION request.
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parseUpdateFrequencySubscription(/*out*/ struct u300_ril_oem_frequency_subscription_request *request);

    /** Parse OEM OPEN_LOGICAL_CHANNEL request
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parseOpenLogicalChannelRequest(/*out*/ struct
                            u300_ril_oem_open_logical_channel_request *request);

    /** Parse OEM CLOSE_LOGICAL_CHANNEL request
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parseCloseLogicalChannelRequest(/*out*/ struct
                           u300_ril_oem_close_logical_channel_request *request);

    /** Parse OEM UICC_LOGICAL_CHANNEL_ACCESS request
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parseUiccLogicalChannelAccessRequest(/*out*/ struct
                           u300_ril_oem_uicc_logical_channel_access_request
                           *request);

    /** Parse OEM SIM_ACCESS request
     *
     * \param request:  [out] structure to be filled by the request.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            parseSimAccessRequest(/*out*/ struct
                           u300_ril_oem_sim_access_request *request);

    /* TODO: Define new parseXXX methods here */


    /** Explicitly reset the parser.
     *
     * \retval          NO_ERROR indicates success.
     */
    inline status_t     reset();

#ifdef U300_RIL_OEM_MSG_SELFTEST
    /** Build OEM PING response.
     *
     * \param response: [in] structure to be serialized.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writePingResponse(/*in*/ const struct u300_ril_oem_ping_response *response);
#endif /* U300_RIL_OEM_MSG_SELFTEST */

     /** Build OEM NETWORK_SEARCH_AND_SET response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeNetworkSearchAndSetResponse();

     /** Build OEM REQUEST_FREQUENCY_REPORT response.
     *
     * \param           pairCurrent:  current cell
     * \param           vecNeighbors: neighbor cells
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeRequestFrequencyReportResponse(const pairFrequencyReportItem_t &pairCurrent,
                                                            const vecFrequencyReport_t &vecNeighbors);

     /** Build OEM UPDATE_FREQUENCY_SUBSCRIPTION response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeUpdateFrequencySubscriptionResponse();

     /** Build OEM UNSOL_FREQUENCY_REPORT response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeUnsolFrequencyNotification();

     /** Build OEM OPEN_LOGICAL_CHANNEL response.
     *
     * \param response: [in] structure to be serialized.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeOpenLogicalChannelResponse(const struct
                          u300_ril_oem_open_logical_channel_response *response);

     /** Build OEM CLOSE_LOGICAL_CHANNEL response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeCloseLogicalChannelResponse();

    /** Build OEM UICC_LOGICAL_CHANNEL_ACCESS response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeUiccLogicalChannelAccessResponse(const struct
                          u300_ril_oem_uicc_logical_channel_access_response
                          *response);

    /** Build OEM SIM_ACCESS response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeSimAccessResponse(const struct
                              u300_ril_oem_sim_access_response *response);

   /** Build OEM FAST DORMANCY response.
     *
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NO_MEMORY indicates memory allocation error.
     */
    status_t            writeFastDormancyResponse();


    /* TODO: Define new writeXXX methods here */

private:
    /** No copy semantic*/
    OemRilParser(const OemRilParser &o);
    /** No copy semantic*/
    OemRilParser       &operator=(const OemRilParser &o);

private:
    /** Write an OEM RIL header to the stream.
     *
     * \param msg_id:   [in] Message ID.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     */
    status_t            writeHeader(/*in*/ uint32_t msg_id);

    /** Get an integer from the stream.
     *
     * \param val:      [out] Integer value taken from the stream.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     */
    status_t            readInt32(/*out*/ uint32_t *val);

    /** Write an integer to the stream.
     *
     * \param val:      [in] Integer value put to the stream.
     * \retval          NO_ERROR indicates success.
     * \retval          NO_MEMORY indicates memory allocation failure.
     */
    status_t            writeInt32(/*in*/ uint32_t val);

    /** Get an string from the stream.
     *
     * \param val:      [out] String value taken from the stream.
     * \retval          NO_ERROR indicates success.
     * \retval          BAD_VALUE indicates invalid argument.
     * \retval          NOT_ENOUGH_DATA indicates buffer underrun.
     */
    status_t            readString(/*out*/ android::String8 *val);

    /** Write a string to the stream.
     *
     * \param val:      [in] String value put to the stream.
     * \retval          NO_ERROR indicates success.
     * \retval          NO_MEMORY indicates memory allocation failure.
     */
    status_t            writeString(/*in*/ const android::String8 &val);

    /** Write a frequency report item to the stream.
     *
     * \param val:      [in] Frequency report item put to the stream.
     * \retval          NO_ERROR indicates success.
     * \retval          NO_MEMORY indicates memory allocation failure.
     */
    status_t            writeFrequencyReportItem(const pairFrequencyReportItem_t &val);
private:
    android::Parcel     mParcel;
};

/* Implementation: inline delegates */

inline android::status_t OemRilParser::setData(uint8_t *buffer, size_t len)
{
    return mParcel.setData(buffer, len);
}

inline const uint8_t *OemRilParser::data() const
{
    return mParcel.data();
}

inline size_t OemRilParser::dataSize() const
{
    return mParcel.dataSize();
}

inline android::status_t OemRilParser::reset()
{
    return mParcel.setDataSize(0);
}

inline android::status_t OemRilParser::readInt32(/*out*/ uint32_t *val)
{
    return mParcel.readInt32((int32_t *)val);
}

inline android::status_t OemRilParser::writeInt32(/*in*/ uint32_t val)
{
    return mParcel.writeInt32(val);
}

} /* namespace u300_ril */

#endif