3
* oFono - Open Source Telephony
5
* Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License version 2 as
9
* published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
#include <arpa/inet.h>
34
int g_isi_msg_version_major(const GIsiMessage *msg)
36
if (msg == NULL || msg->version == NULL)
39
return msg->version->major;
42
int g_isi_msg_version_minor(const GIsiMessage *msg)
44
if (msg == NULL || msg->version == NULL)
47
return msg->version->minor;
50
int g_isi_msg_error(const GIsiMessage *msg)
52
return msg != NULL ? -msg->error : -EINVAL;
55
const char *g_isi_msg_strerror(const GIsiMessage *msg)
57
return strerror(-g_isi_msg_error(msg));
60
uint8_t g_isi_msg_resource(const GIsiMessage *msg)
62
if (msg == NULL || msg->addr == NULL)
65
return msg->addr->spn_resource;
68
uint16_t g_isi_msg_object(const GIsiMessage *msg)
70
if (msg == NULL || msg->addr == NULL)
73
return (msg->addr->spn_dev << 8) | msg->addr->spn_obj;
76
uint8_t g_isi_msg_id(const GIsiMessage *msg)
80
if (msg == NULL || msg->data == NULL || msg->len < 2)
88
uint8_t g_isi_msg_utid(const GIsiMessage *msg)
92
if (msg == NULL || msg->data == NULL || msg->len < 2)
100
size_t g_isi_msg_data_len(const GIsiMessage *msg)
102
if (msg == NULL || msg->data == NULL)
108
const void *g_isi_msg_data(const GIsiMessage *msg)
110
if (msg == NULL || msg->data == NULL)
113
return (void *)msg->data + 2;
116
gboolean g_isi_msg_data_get_byte(const GIsiMessage *msg, unsigned offset,
119
const uint8_t *buf = g_isi_msg_data(msg);
121
if (buf == NULL || g_isi_msg_data_len(msg) < offset)
130
gboolean g_isi_msg_data_get_word(const GIsiMessage *msg, unsigned offset,
133
const uint8_t *buf = g_isi_msg_data(msg);
136
if (buf == NULL || g_isi_msg_data_len(msg) < offset + 1)
139
memcpy(&val, buf + offset, sizeof(uint16_t));
147
gboolean g_isi_msg_data_get_struct(const GIsiMessage *msg, unsigned offset,
148
const void **type, size_t len)
150
if (g_isi_msg_data_len(msg) < offset + len)
154
*type = g_isi_msg_data(msg) + offset;