3 * oFono - Open Source Telephony
5 * Copyright (C) 2010-2011 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
36 #include "cdma-smsutil.h"
38 static GSList *g_drivers;
40 struct ofono_cdma_sms {
41 const struct ofono_cdma_sms_driver *driver;
43 struct ofono_atom *atom;
46 static GDBusMethodTable cdma_sms_manager_methods[] = {
51 static GDBusSignalTable cdma_sms_manager_signals[] = {
52 { "IncomingMessage", "sa{sv}" },
57 static void cdma_dispatch_text_message(struct ofono_cdma_sms *cdma_sms,
61 const char *path = __ofono_atom_get_path(cdma_sms->atom);
62 DBusConnection *conn = ofono_dbus_get_connection();
66 const char *signal_name;
68 /* TODO: Support ImmediateMessage */
69 signal_name = "IncomingMessage";
71 signal = dbus_message_new_signal(path,
72 OFONO_CDMA_MESSAGE_MANAGER_INTERFACE,
77 dbus_message_iter_init_append(signal, &iter);
79 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &message);
81 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
82 OFONO_PROPERTIES_ARRAY_SIGNATURE,
85 ofono_dbus_dict_append(&dict, "Sender", DBUS_TYPE_STRING, &oaddr);
87 /* TODO: Other properties not supported yet */
89 dbus_message_iter_close_container(&iter, &dict);
91 g_dbus_send_message(conn, signal);
93 /*TODO: Add the message to history*/
96 static void ofono_cdma_sms_process_wmt_deliver(struct ofono_cdma_sms *cdma_sms,
97 const struct cdma_sms *incoming)
101 const struct cdma_sms_ud *ud;
103 ud = &incoming->p2p_msg.bd.wmt_deliver.ud;
106 * If incoming message does not contain USER DATA, still
107 * send indication to upper layer but with empty string.
109 if (check_bitmap(incoming->p2p_msg.bd.subparam_bitmap,
110 CDMA_SMS_SUBPARAM_ID_USER_DATA) == FALSE)
111 message = g_new0(char, 1);
113 message = cdma_sms_decode_text(ud);
118 oaddr = cdma_sms_address_to_string(&incoming->p2p_msg.oaddr);
124 cdma_dispatch_text_message(cdma_sms, message, oaddr);
129 static void ofono_cdma_sms_process_wmt(struct ofono_cdma_sms *cdma_sms,
130 struct cdma_sms *incoming)
132 /* TODO: Add duplicate detection support */
134 switch (incoming->p2p_msg.bd.id.msg_type) {
135 case CDMA_SMS_MSG_TYPE_RESERVED:
137 case CDMA_SMS_MSG_TYPE_DELIVER:
138 ofono_cdma_sms_process_wmt_deliver(cdma_sms, incoming);
140 case CDMA_SMS_MSG_TYPE_SUBMIT:
141 case CDMA_SMS_MSG_TYPE_CANCEL:
142 case CDMA_SMS_MSG_TYPE_DELIVER_ACK:
143 case CDMA_SMS_MSG_TYPE_USER_ACK:
144 case CDMA_SMS_MSG_TYPE_READ_ACK:
145 case CDMA_SMS_MSG_TYPE_DELIVER_REPORT:
146 case CDMA_SMS_MSG_TYPE_SUBMIT_REPORT:
152 static void ofono_cdma_sms_process_p2p(struct ofono_cdma_sms *cdma_sms,
153 struct cdma_sms *incoming)
155 switch (incoming->p2p_msg.teleservice_id) {
156 case CDMA_SMS_TELESERVICE_ID_CMT91:
157 case CDMA_SMS_TELESERVICE_ID_WPT:
158 break; /* TODO: Not supported yet */
159 case CDMA_SMS_TELESERVICE_ID_WMT:
160 ofono_cdma_sms_process_wmt(cdma_sms, incoming);
162 case CDMA_SMS_TELESERVICE_ID_VMN:
163 case CDMA_SMS_TELESERVICE_ID_WAP:
164 case CDMA_SMS_TELESERVICE_ID_WEMT:
165 case CDMA_SMS_TELESERVICE_ID_SCPT:
166 case CDMA_SMS_TELESERVICE_ID_CATPT:
167 break; /* TODO: Not supported yet */
171 void ofono_cdma_sms_deliver_notify(struct ofono_cdma_sms *cdma_sms,
172 unsigned char *pdu, int tpdu_len)
174 static struct cdma_sms s;
176 DBG("tpdu len %d", tpdu_len);
178 memset(&s, 0, sizeof(struct cdma_sms));
180 if (cdma_sms_decode(pdu, tpdu_len, &s) == FALSE)
184 case CDMA_SMS_TP_MSG_TYPE_P2P:
185 ofono_cdma_sms_process_p2p(cdma_sms, &s);
187 case CDMA_SMS_TP_MSG_TYPE_BCAST:
188 case CDMA_SMS_TP_MSG_TYPE_ACK:
190 * TODO: Support SMS Broadcast Message and SMS
191 * Acknowledge Message.
197 int ofono_cdma_sms_driver_register(const struct ofono_cdma_sms_driver *d)
199 DBG("driver: %p, name: %s", d, d->name);
201 if (d->probe == NULL)
204 g_drivers = g_slist_prepend(g_drivers, (void *)d);
209 void ofono_cdma_sms_driver_unregister(const struct ofono_cdma_sms_driver *d)
211 DBG("driver: %p, name: %s", d, d->name);
213 g_drivers = g_slist_remove(g_drivers, (void *)d);
216 static void cdma_sms_unregister(struct ofono_atom *atom)
218 DBusConnection *conn = ofono_dbus_get_connection();
219 struct ofono_modem *modem = __ofono_atom_get_modem(atom);
220 const char *path = __ofono_atom_get_path(atom);
222 g_dbus_unregister_interface(conn, path,
223 OFONO_CDMA_MESSAGE_MANAGER_INTERFACE);
225 ofono_modem_remove_interface(modem,
226 OFONO_CDMA_MESSAGE_MANAGER_INTERFACE);
229 static void cdma_sms_remove(struct ofono_atom *atom)
231 struct ofono_cdma_sms *cdma_sms = __ofono_atom_get_data(atom);
233 DBG("atom: %p", atom);
235 if (cdma_sms == NULL)
238 if (cdma_sms->driver && cdma_sms->driver->remove)
239 cdma_sms->driver->remove(cdma_sms);
245 * Create a CDMA SMS driver
247 * This creates a CDMA SMS driver that is hung off a @modem
248 * object. However, for the driver to be used by the system, it has to
249 * be registered with the oFono core using ofono_sms_register().
251 * This is done once the modem driver determines that SMS is properly
252 * supported by the hardware.
254 struct ofono_cdma_sms *ofono_cdma_sms_create(struct ofono_modem *modem,
259 struct ofono_cdma_sms *cdma_sms;
265 cdma_sms = g_try_new0(struct ofono_cdma_sms, 1);
266 if (cdma_sms == NULL)
269 cdma_sms->atom = __ofono_modem_add_atom(modem,
270 OFONO_ATOM_TYPE_CDMA_SMS,
271 cdma_sms_remove, cdma_sms);
273 for (l = g_drivers; l; l = l->next) {
274 const struct ofono_cdma_sms_driver *drv = l->data;
276 if (g_strcmp0(drv->name, driver))
279 if (drv->probe(cdma_sms, vendor, data) < 0)
282 cdma_sms->driver = drv;
290 * Indicate oFono that a CDMA SMS driver is ready for operation
292 * This is called after ofono_cdma_sms_create() was done and the modem
293 * driver determined that a modem supports SMS correctly. Once this
294 * call succeeds, the D-BUS interface for SMS goes live.
296 void ofono_cdma_sms_register(struct ofono_cdma_sms *cdma_sms)
298 DBusConnection *conn = ofono_dbus_get_connection();
299 struct ofono_modem *modem = __ofono_atom_get_modem(cdma_sms->atom);
300 const char *path = __ofono_atom_get_path(cdma_sms->atom);
302 if (!g_dbus_register_interface(conn, path,
303 OFONO_CDMA_MESSAGE_MANAGER_INTERFACE,
304 cdma_sms_manager_methods,
305 cdma_sms_manager_signals,
306 NULL, cdma_sms, NULL)) {
307 ofono_error("Could not create %s interface",
308 OFONO_CDMA_MESSAGE_MANAGER_INTERFACE);
312 ofono_modem_add_interface(modem, OFONO_CDMA_MESSAGE_MANAGER_INTERFACE);
314 __ofono_atom_register(cdma_sms->atom, cdma_sms_unregister);
317 void ofono_cdma_sms_remove(struct ofono_cdma_sms *cdma_sms)
319 __ofono_atom_free(cdma_sms->atom);
322 void ofono_cdma_sms_set_data(struct ofono_cdma_sms *cdma_sms, void *data)
324 cdma_sms->driver_data = data;
327 void *ofono_cdma_sms_get_data(struct ofono_cdma_sms *cdma_sms)
329 return cdma_sms->driver_data;