Re: [PATCH v2 03/18] plugins: add plugin for u8500
Hi Andreas, 2011/2/23 Andreas Westin : > From: Jessica Nilsson > > --- > Makefile.am | 3 + > plugins/u8500.c | 708 > +++ > 2 files changed, 711 insertions(+), 0 deletions(-) > create mode 100644 plugins/u8500.c I pushed this patch, but split it into two, and fixed the plugin description afterwards. Cheers, Aki > diff --git a/Makefile.am b/Makefile.am > index 7bd7f4f..aa4f3f9 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -144,6 +144,9 @@ builtin_sources += plugins/isiusb.c > > builtin_modules += n900 > builtin_sources += plugins/n900.c plugins/nokia-gpio.h plugins/nokia-gpio.c > + > +builtin_modules += u8500 > +builtin_sources += plugins/u8500.c > endif > > if ATMODEM > diff --git a/plugins/u8500.c b/plugins/u8500.c > new file mode 100644 > index 000..78e1a97 > --- /dev/null > +++ b/plugins/u8500.c > @@ -0,0 +1,708 @@ > +/* > + * > + * oFono - Open Source Telephony > + * > + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). > + * Copyright (C) ST-Ericsson SA 2011. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 > USA > + * > + */ > + > +#ifdef HAVE_CONFIG_H > +#include > +#endif > + > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#define OFONO_API_SUBJECT_TO_CHANGE > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "drivers/isimodem/isimodem.h" > +#include "drivers/isimodem/isiutil.h" > +#include "drivers/isimodem/mtc.h" > +#include "drivers/isimodem/debug.h" > + > +struct isi_data { > + char const *ifname; > + GIsiModem *modem; > + GIsiClient *client; > + GIsiPhonetNetlink *link; > + enum GIsiPhonetLinkState linkstate; > + unsigned interval; > + int reported; > + ofono_bool_t online; > + struct isi_cb_data *online_cbd; > +}; > + > +struct devinfo_data { > + GIsiClient *client; > +}; > + > +static gboolean check_response_status(const GIsiMessage *msg, uint8_t msgid) > +{ > + if (g_isi_msg_error(msg) < 0) { > + DBG("Error: %s", strerror(-g_isi_msg_error(msg))); > + return FALSE; > + } > + > + if (g_isi_msg_id(msg) != msgid) { > + DBG("Unexpected msg: %s", > + mce_message_id_name(g_isi_msg_id(msg))); > + return FALSE; > + } > + return TRUE; > +} > + > +static void report_powered(struct ofono_modem *modem, struct isi_data *isi, > + ofono_bool_t powered) > +{ > + if (powered == isi->reported) > + return; > + > + isi->reported = powered; > + ofono_modem_set_powered(modem, powered); > +} > + > +static void report_online(struct isi_data *isi, ofono_bool_t online) > +{ > + struct isi_cb_data *cbd = isi->online_cbd; > + ofono_modem_online_cb_t cb = cbd->cb; > + > + isi->online_cbd = NULL; > + > + if (isi->online == online) > + CALLBACK_WITH_SUCCESS(cb, cbd->data); > + else > + CALLBACK_WITH_FAILURE(cb, cbd->data); > + > + g_free(cbd); > +} > + > +static void set_power_by_mce_state(struct ofono_modem *modem, > + struct isi_data *isi, int mce_state) > +{ > + switch (mce_state) { > + case MCE_POWER_OFF: > + report_powered(modem, isi, FALSE); > + break; > + case MCE_NORMAL: > + if (isi->online_cbd) > + report_online(isi, mce_state == MCE_NORMAL); > + default: > + report_powered(modem, isi, TRUE); > + } > +} > + > +static void mce_state_ind_cb(const GIsiMessage *msg, void *data) > +{ > + struct ofono_modem *modem = data; > + struct isi_data *isi = ofono_modem_get_data(modem); > + uint8_t state; > + uint8_t action; > + > + if (isi == NULL || g_isi_msg_id(msg) != MCE_MODEM_STATE_IND) > + return; > + > + if (!g_isi_msg_data_get_byte(msg, 0, &state) || > + !g_isi_msg_data_get_byte(
[PATCH v2 03/18] plugins: add plugin for u8500
From: Jessica Nilsson --- Makefile.am |3 + plugins/u8500.c | 708 +++ 2 files changed, 711 insertions(+), 0 deletions(-) create mode 100644 plugins/u8500.c diff --git a/Makefile.am b/Makefile.am index 7bd7f4f..aa4f3f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,6 +144,9 @@ builtin_sources += plugins/isiusb.c builtin_modules += n900 builtin_sources += plugins/n900.c plugins/nokia-gpio.h plugins/nokia-gpio.c + +builtin_modules += u8500 +builtin_sources += plugins/u8500.c endif if ATMODEM diff --git a/plugins/u8500.c b/plugins/u8500.c new file mode 100644 index 000..78e1a97 --- /dev/null +++ b/plugins/u8500.c @@ -0,0 +1,708 @@ +/* + * + * oFono - Open Source Telephony + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * Copyright (C) ST-Ericsson SA 2011. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define OFONO_API_SUBJECT_TO_CHANGE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "drivers/isimodem/isimodem.h" +#include "drivers/isimodem/isiutil.h" +#include "drivers/isimodem/mtc.h" +#include "drivers/isimodem/debug.h" + +struct isi_data { + char const *ifname; + GIsiModem *modem; + GIsiClient *client; + GIsiPhonetNetlink *link; + enum GIsiPhonetLinkState linkstate; + unsigned interval; + int reported; + ofono_bool_t online; + struct isi_cb_data *online_cbd; +}; + +struct devinfo_data { + GIsiClient *client; +}; + +static gboolean check_response_status(const GIsiMessage *msg, uint8_t msgid) +{ + if (g_isi_msg_error(msg) < 0) { + DBG("Error: %s", strerror(-g_isi_msg_error(msg))); + return FALSE; + } + + if (g_isi_msg_id(msg) != msgid) { + DBG("Unexpected msg: %s", + mce_message_id_name(g_isi_msg_id(msg))); + return FALSE; + } + return TRUE; +} + +static void report_powered(struct ofono_modem *modem, struct isi_data *isi, + ofono_bool_t powered) +{ + if (powered == isi->reported) + return; + + isi->reported = powered; + ofono_modem_set_powered(modem, powered); +} + +static void report_online(struct isi_data *isi, ofono_bool_t online) +{ + struct isi_cb_data *cbd = isi->online_cbd; + ofono_modem_online_cb_t cb = cbd->cb; + + isi->online_cbd = NULL; + + if (isi->online == online) + CALLBACK_WITH_SUCCESS(cb, cbd->data); + else + CALLBACK_WITH_FAILURE(cb, cbd->data); + + g_free(cbd); +} + +static void set_power_by_mce_state(struct ofono_modem *modem, + struct isi_data *isi, int mce_state) +{ + switch (mce_state) { + case MCE_POWER_OFF: + report_powered(modem, isi, FALSE); + break; + case MCE_NORMAL: + if (isi->online_cbd) + report_online(isi, mce_state == MCE_NORMAL); + default: + report_powered(modem, isi, TRUE); + } +} + +static void mce_state_ind_cb(const GIsiMessage *msg, void *data) +{ + struct ofono_modem *modem = data; + struct isi_data *isi = ofono_modem_get_data(modem); + uint8_t state; + uint8_t action; + + if (isi == NULL || g_isi_msg_id(msg) != MCE_MODEM_STATE_IND) + return; + + if (!g_isi_msg_data_get_byte(msg, 0, &state) || + !g_isi_msg_data_get_byte(msg, 1, &action)) + return; + + switch (action) { + case MCE_START: + DBG("target modem state: %s (0x%02X)", + mce_modem_state_name(state), state); + break; + + case MCE_READY: + DBG("current modem state: %s (0x%02X)", + mce_modem_state_name(state), state); + set_power_by_mce_state(modem, isi, state); + break; + default: + b