build: remove obsolete files

This will very likely create lots of conflicts until the branch gets merged
into master, but anyway...
This commit is contained in:
Aleksander Morgado
2012-02-27 16:14:58 +01:00
parent 17ef077797
commit 5c73e8d200
32 changed files with 0 additions and 27013 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,276 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
*/
#include "mm-callback-info.h"
#include <ModemManager.h>
#include <mm-errors-types.h>
#define CALLBACK_INFO_RESULT "callback-info-result"
static void
invoke_mm_modem_fn (MMCallbackInfo *info)
{
MMModemFn callback = (MMModemFn) info->callback;
callback (info->modem, info->error, info->user_data);
}
static void
invoke_mm_modem_uint_fn (MMCallbackInfo *info)
{
MMModemUIntFn callback = (MMModemUIntFn) info->callback;
callback (info->modem,
GPOINTER_TO_UINT (mm_callback_info_get_data (info, CALLBACK_INFO_RESULT)),
info->error, info->user_data);
}
static void
invoke_mm_modem_string_fn (MMCallbackInfo *info)
{
MMModemStringFn callback = (MMModemStringFn) info->callback;
callback (info->modem,
(const char *) mm_callback_info_get_data (info, CALLBACK_INFO_RESULT),
info->error, info->user_data);
}
static void
invoke_mm_modem_array_fn (MMCallbackInfo *info)
{
MMModemArrayFn callback = (MMModemArrayFn) info->callback;
callback (info->modem,
(GArray *) mm_callback_info_get_data (info, CALLBACK_INFO_RESULT),
info->error, info->user_data);
}
static void
modem_destroyed_cb (gpointer data, GObject *destroyed)
{
MMCallbackInfo *info = data;
/* Reset modem pointer, so that callback know that they shouldn't do
* anything else */
info->modem = NULL;
/* Overwrite any possible previous error set */
g_clear_error (&(info->error));
info->error = g_error_new_literal (MM_CORE_ERROR,
MM_CORE_ERROR_ABORTED,
"The modem was removed.");
/* Only schedule the info if not already done before */
if (!info->pending_id)
mm_callback_info_schedule (info);
}
static void
callback_info_done (gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
info->pending_id = 0;
info->called = TRUE;
if (info->invoke_fn && info->callback)
info->invoke_fn (info);
mm_callback_info_unref (info);
}
static gboolean
callback_info_do (gpointer user_data)
{
/* Nothing here, everything is done in callback_info_done to make sure the info->callback
always gets called, even if the pending call gets cancelled. */
return FALSE;
}
void
mm_callback_info_schedule (MMCallbackInfo *info)
{
g_return_if_fail (info != NULL);
g_return_if_fail (info->pending_id == 0);
g_return_if_fail (info->called == FALSE);
g_warn_if_fail (info->chain_left == 0);
info->pending_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, callback_info_do, info, callback_info_done);
}
MMCallbackInfo *
mm_callback_info_new_full (MMModem *modem,
MMCallbackInfoInvokeFn invoke_fn,
GCallback callback,
gpointer user_data)
{
MMCallbackInfo *info;
g_return_val_if_fail (modem != NULL, NULL);
info = g_slice_new0 (MMCallbackInfo);
g_datalist_init (&info->qdata);
info->modem = modem;
g_object_weak_ref (G_OBJECT (modem), modem_destroyed_cb, info);
info->invoke_fn = invoke_fn;
info->callback = callback;
info->user_data = user_data;
info->refcount = 1;
return info;
}
MMCallbackInfo *
mm_callback_info_new (MMModem *modem, MMModemFn callback, gpointer user_data)
{
g_return_val_if_fail (modem != NULL, NULL);
return mm_callback_info_new_full (modem, invoke_mm_modem_fn, (GCallback) callback, user_data);
}
MMCallbackInfo *
mm_callback_info_uint_new (MMModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_val_if_fail (modem != NULL, NULL);
return mm_callback_info_new_full (modem, invoke_mm_modem_uint_fn, (GCallback) callback, user_data);
}
MMCallbackInfo *
mm_callback_info_string_new (MMModem *modem,
MMModemStringFn callback,
gpointer user_data)
{
g_return_val_if_fail (modem != NULL, NULL);
return mm_callback_info_new_full (modem, invoke_mm_modem_string_fn, (GCallback) callback, user_data);
}
MMCallbackInfo *
mm_callback_info_array_new (MMModem *modem,
MMModemArrayFn callback,
gpointer user_data)
{
g_return_val_if_fail (modem != NULL, NULL);
return mm_callback_info_new_full (modem, invoke_mm_modem_array_fn, (GCallback) callback, user_data);
}
gpointer
mm_callback_info_get_result (MMCallbackInfo *info)
{
g_return_val_if_fail (info != NULL, NULL);
return mm_callback_info_get_data (info, CALLBACK_INFO_RESULT);
}
void
mm_callback_info_set_result (MMCallbackInfo *info,
gpointer data,
GDestroyNotify destroy)
{
g_return_if_fail (info != NULL);
mm_callback_info_set_data (info, CALLBACK_INFO_RESULT, data, destroy);
}
void
mm_callback_info_set_data (MMCallbackInfo *info,
const char *key,
gpointer data,
GDestroyNotify destroy)
{
g_return_if_fail (info != NULL);
g_return_if_fail (key != NULL);
g_datalist_id_set_data_full (&info->qdata, g_quark_from_string (key), data,
data ? destroy : (GDestroyNotify) NULL);
}
gpointer
mm_callback_info_get_data (MMCallbackInfo *info, const char *key)
{
GQuark quark;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
quark = g_quark_try_string (key);
return quark ? g_datalist_id_get_data (&info->qdata, quark) : NULL;
}
gboolean
mm_callback_info_check_modem_removed (MMCallbackInfo *info)
{
g_return_val_if_fail (info != NULL, TRUE);
return (info->modem ? FALSE : TRUE);
}
MMCallbackInfo *
mm_callback_info_ref (MMCallbackInfo *info)
{
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->refcount > 0, NULL);
info->refcount++;
return info;
}
void
mm_callback_info_unref (MMCallbackInfo *info)
{
g_return_if_fail (info != NULL);
info->refcount--;
if (info->refcount == 0) {
if (info->error)
g_error_free (info->error);
if (info->modem)
g_object_weak_unref (G_OBJECT (info->modem), modem_destroyed_cb, info);
g_datalist_clear (&info->qdata);
g_slice_free (MMCallbackInfo, info);
}
}
void
mm_callback_info_chain_start (MMCallbackInfo *info, guint num)
{
g_return_if_fail (info != NULL);
g_return_if_fail (num > 0);
g_return_if_fail (info->chain_left == 0);
info->chain_left = num;
}
void
mm_callback_info_chain_complete_one (MMCallbackInfo *info)
{
g_return_if_fail (info != NULL);
g_return_if_fail (info->chain_left > 0);
info->chain_left--;
if (info->chain_left == 0)
mm_callback_info_schedule (info);
}

View File

@@ -1,87 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
*/
#ifndef MM_CALLBACK_INFO_H
#define MM_CALLBACK_INFO_H
#include "mm-modem.h"
typedef struct _MMCallbackInfo MMCallbackInfo;
typedef void (*MMCallbackInfoInvokeFn) (MMCallbackInfo *info);
struct _MMCallbackInfo {
guint32 refcount;
/* # of ops left in this callback chain */
guint32 chain_left;
GData *qdata;
MMModem *modem;
MMCallbackInfoInvokeFn invoke_fn;
GCallback callback;
gboolean called;
gpointer user_data;
GError *error;
guint pending_id;
};
MMCallbackInfo *mm_callback_info_new_full (MMModem *modem,
MMCallbackInfoInvokeFn invoke_fn,
GCallback callback,
gpointer user_data);
MMCallbackInfo *mm_callback_info_new (MMModem *modem,
MMModemFn callback,
gpointer user_data);
MMCallbackInfo *mm_callback_info_uint_new (MMModem *modem,
MMModemUIntFn callback,
gpointer user_data);
MMCallbackInfo *mm_callback_info_string_new (MMModem *modem,
MMModemStringFn callback,
gpointer user_data);
MMCallbackInfo *mm_callback_info_array_new (MMModem *modem,
MMModemArrayFn callback,
gpointer user_data);
void mm_callback_info_schedule (MMCallbackInfo *info);
gpointer mm_callback_info_get_result (MMCallbackInfo *info);
void mm_callback_info_set_result (MMCallbackInfo *info,
gpointer data,
GDestroyNotify destroy);
void mm_callback_info_set_data (MMCallbackInfo *info,
const char *key,
gpointer data,
GDestroyNotify destroy);
gpointer mm_callback_info_get_data (MMCallbackInfo *info,
const char *key);
gboolean mm_callback_info_check_modem_removed (MMCallbackInfo *info);
MMCallbackInfo *mm_callback_info_ref (MMCallbackInfo *info);
void mm_callback_info_unref (MMCallbackInfo *info);
void mm_callback_info_chain_start (MMCallbackInfo *info, guint num);
void mm_callback_info_chain_complete_one (MMCallbackInfo *info);
#endif /* MM_CALLBACK_INFO_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,155 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#ifndef MM_GENERIC_CDMA_H
#define MM_GENERIC_CDMA_H
#include "mm-modem.h"
#include "mm-modem-base.h"
#include "mm-modem-cdma.h"
#include "mm-at-serial-port.h"
#include "mm-qcdm-serial-port.h"
#include "mm-callback-info.h"
#define MM_TYPE_GENERIC_CDMA (mm_generic_cdma_get_type ())
#define MM_GENERIC_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_CDMA, MMGenericCdma))
#define MM_GENERIC_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_GENERIC_CDMA, MMGenericCdmaClass))
#define MM_IS_GENERIC_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_GENERIC_CDMA))
#define MM_IS_GENERIC_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_GENERIC_CDMA))
#define MM_GENERIC_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_GENERIC_CDMA, MMGenericCdmaClass))
#define MM_GENERIC_CDMA_EVDO_REV0 "evdo-rev0"
#define MM_GENERIC_CDMA_EVDO_REVA "evdo-revA"
#define MM_GENERIC_CDMA_REGISTRATION_TRY_CSS "registration-try-css"
typedef struct {
MMModemBase parent;
} MMGenericCdma;
typedef struct {
MMModemBaseClass parent;
/* Called to allow subclasses to update port flags, attach unsolicited
* result code handlers, change port attributes, etc. This is called
* after the generic class has installed it's own handlers; if the
* generic class' behavior is not desired, subclasses can override the
* port_grabbed() method of MMModemBase.
*/
void (*port_grabbed) (MMGenericCdma *self,
MMPort *port,
MMAtPortFlags at_pflags,
gpointer user_data);
/* Called after all ports have been organized to allow subclasses to
* make changes to ports after we've assigned primary, secondary, and data
* designations.
*/
void (*ports_organized) (MMGenericCdma *self, MMAtSerialPort *primary);
/* Subclasses should implement this function if they can more accurately
* determine the registration state and/or roaming status than the base
* class can (by using manufacturer custom AT commands or whatever).
* The base class passes its detected registration state in the
* cur_cdma_state and cur_evdo_state arguments, which the subclass should
* override if necessary before passing to the callback.
*
* Subclasses can use the helper functions
* mm_generic_cdma_query_reg_state_callback_info_new(),
* mm_generic_cdma_query_reg_state_set_callback_1x_state(), and
* mm_generic_cdma_query_reg_state_set_callback_evdo_state() to create the
* MMCallbackInfo object and to set the registration state which is passed
* to the callback when the subclass' registration query completes.
*
* Subclasses should generally not return parsing or other non-critical
* errors to the callback since that fails the entire registration check,
* rendering the superclass' checks useless.
*/
void (*query_registration_state) (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data);
/* Called after generic enable operations, but before the modem has entered
* the ENABLED state.
*/
void (*post_enable) (MMGenericCdma *self,
MMModemFn callback,
gpointer user_data);
/* Called after generic disable operations, but before the modem has entered
* the DISABLED state.
*/
void (*post_disable) (MMGenericCdma *self,
MMModemFn callback,
gpointer user_data);
} MMGenericCdmaClass;
GType mm_generic_cdma_get_type (void);
MMModem *mm_generic_cdma_new (const char *device,
const char *driver,
const char *plugin,
gboolean evdo_rev0,
gboolean evdo_revA,
guint vendor,
guint product);
/* Private, for subclasses */
/* Returns the first port (if any) which has the given flag */
MMAtSerialPort *mm_generic_cdma_get_at_port (MMGenericCdma *modem, MMAtPortFlags flag);
MMAtSerialPort *mm_generic_cdma_get_best_at_port (MMGenericCdma *modem,
GError **error);
MMQcdmSerialPort *mm_generic_cdma_get_best_qcdm_port (MMGenericCdma *modem,
GError **error);
void mm_generic_cdma_update_cdma1x_quality (MMGenericCdma *self, guint32 quality);
void mm_generic_cdma_update_evdo_quality (MMGenericCdma *self, guint32 quality);
/* For unsolicited 1x registration state changes */
void mm_generic_cdma_set_1x_registration_state (MMGenericCdma *self,
MMModemCdmaRegistrationState new_state);
/* For unsolicited EVDO registration state changes */
void mm_generic_cdma_set_evdo_registration_state (MMGenericCdma *self,
MMModemCdmaRegistrationState new_state);
MMModemCdmaRegistrationState mm_generic_cdma_1x_get_registration_state_sync (MMGenericCdma *self);
MMModemCdmaRegistrationState mm_generic_cdma_evdo_get_registration_state_sync (MMGenericCdma *self);
/* query_registration_state class function helpers */
MMCallbackInfo *mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data);
MMModemCdmaRegistrationState mm_generic_cdma_query_reg_state_get_callback_1x_state (MMCallbackInfo *info);
void mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state);
MMModemCdmaRegistrationState mm_generic_cdma_query_reg_state_get_callback_evdo_state (MMCallbackInfo *info);
void mm_generic_cdma_query_reg_state_set_callback_evdo_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state);
#endif /* MM_GENERIC_CDMA_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,265 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
*/
#ifndef MM_GENERIC_GSM_H
#define MM_GENERIC_GSM_H
#include <config.h>
#include <ModemManager.h>
#include "mm-modem-gsm-network.h"
#include "mm-modem-base.h"
#include "mm-at-serial-port.h"
#include "mm-callback-info.h"
#include "mm-charsets.h"
#define MM_TYPE_GENERIC_GSM (mm_generic_gsm_get_type ())
#define MM_GENERIC_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsm))
#define MM_GENERIC_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_GENERIC_GSM, MMGenericGsmClass))
#define MM_IS_GENERIC_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_GENERIC_GSM))
#define MM_IS_GENERIC_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_GENERIC_GSM))
#define MM_GENERIC_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsmClass))
#define MM_GENERIC_GSM_POWER_UP_CMD "power-up-cmd"
#define MM_GENERIC_GSM_POWER_DOWN_CMD "power-down-cmd"
#define MM_GENERIC_GSM_INIT_CMD "init-cmd"
#define MM_GENERIC_GSM_INIT_CMD_OPTIONAL "init-cmd-optional"
#define MM_GENERIC_GSM_FLOW_CONTROL_CMD "flow-control-cmd"
#define MM_GENERIC_GSM_SMS_INDICATION_ENABLE_CMD "sms-enable-cmd"
#define MM_GENERIC_GSM_SMS_STORAGE_LOCATION_CMD "sms-storage-cmd"
#define MM_GENERIC_GSM_CMER_ENABLE_CMD "cmer-enable-cmd"
#define MM_GENERIC_GSM_PS_NETWORK_SUPPORTED "ps-network-supported"
typedef enum {
MM_GENERIC_GSM_PROP_FIRST = 0x2000,
MM_GENERIC_GSM_PROP_POWER_UP_CMD,
MM_GENERIC_GSM_PROP_POWER_DOWN_CMD,
MM_GENERIC_GSM_PROP_INIT_CMD,
MM_GENERIC_GSM_PROP_SUPPORTED_BANDS,
MM_GENERIC_GSM_PROP_SUPPORTED_MODES,
MM_GENERIC_GSM_PROP_INIT_CMD_OPTIONAL,
MM_GENERIC_GSM_PROP_ALLOWED_MODE,
MM_GENERIC_GSM_PROP_ACCESS_TECHNOLOGY,
MM_GENERIC_GSM_PROP_LOC_CAPABILITIES,
MM_GENERIC_GSM_PROP_LOC_ENABLED,
MM_GENERIC_GSM_PROP_LOC_SIGNAL,
MM_GENERIC_GSM_PROP_LOC_LOCATION,
MM_GENERIC_GSM_PROP_SIM_IDENTIFIER,
MM_GENERIC_GSM_PROP_USSD_STATE,
MM_GENERIC_GSM_PROP_USSD_NETWORK_REQUEST,
MM_GENERIC_GSM_PROP_USSD_NETWORK_NOTIFICATION,
MM_GENERIC_GSM_PROP_FLOW_CONTROL_CMD,
MM_GENERIC_GSM_PROP_SMS_INDICATION_ENABLE_CMD,
MM_GENERIC_GSM_PROP_SMS_STORAGE_LOCATION_CMD,
MM_GENERIC_GSM_PROP_CMER_ENABLE_CMD,
MM_GENERIC_GSM_PROP_ENABLED_FACILITY_LOCKS,
MM_GENERIC_GSM_PROP_PS_NETWORK_SUPPORTED
} MMGenericGsmProp;
typedef enum {
MM_GENERIC_GSM_REG_TYPE_UNKNOWN = 0,
MM_GENERIC_GSM_REG_TYPE_CS = 1,
MM_GENERIC_GSM_REG_TYPE_PS = 2
} MMGenericGsmRegType;
typedef struct {
MMModemBase parent;
} MMGenericGsm;
typedef struct {
MMModemBaseClass parent;
/* Called to allow subclasses to update port flags, attach unsolicited
* result code handlers, change port attributes, etc. This is called
* after the generic class has installed it's own handlers; if the
* generic class' behavior is not desired, subclasses can override the
* port_grabbed() method of MMModemBase.
*/
void (*port_grabbed) (MMGenericGsm *self,
MMPort *port,
MMAtPortFlags at_pflags,
gpointer user_data);
/* Called after all ports have been organized to allow subclasses to
* make changes to ports after we've assigned primary, secondary, and data
* designations.
*/
void (*ports_organized) (MMGenericGsm *self, MMAtSerialPort *primary);
/* Called after opening the primary serial port and updating the modem's
* state to ENABLING, but before sending any commands to the device. Modems
* that need to perform custom initialization sequences or other setup should
* generally override this method instead of the MMModem interface's enable()
* method, unless the customization must happen *after* the generic init
* sequence has completed. When the subclass' enable attempt is complete
* the subclass should call mm_generic_gsm_enable_complete() with any error
* encountered during the process and the MMCallbackInfo created from the
* callback and user_data passed in here.
*/
void (*do_enable) (MMGenericGsm *self,
MMModemFn callback,
gpointer user_data);
/* Called before issuing the power-up command, to check whether it should
* really be issued or not. */
void (*do_enable_power_up_check_needed) (MMGenericGsm *self,
MMModemUIntFn callback,
gpointer user_data);
/* Called after the generic class has attempted to power up the modem.
* Subclasses can handle errors here if they know the device supports their
* power up command. Will only be called if the device does *not* override
* the MMModem enable() command or allows the generic class' do_enable()
* handler to execute.
*/
void (*do_enable_power_up_done) (MMGenericGsm *self,
GString *response,
GError *error,
MMCallbackInfo *info);
/* Called to terminate the active data call and deactivate the given PDP
* context.
*/
void (*do_disconnect) (MMGenericGsm *self,
gint cid,
MMModemFn callback,
gpointer user_data);
/* Called by the generic class to set the allowed operating mode of the device */
void (*set_allowed_mode) (MMGenericGsm *self,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data);
/* Called by the generic class to get the allowed operating mode of the device */
void (*get_allowed_mode) (MMGenericGsm *self,
MMModemUIntFn callback,
gpointer user_data);
/* Called by the generic class to the current radio access technology the
* device is using while communicating with the base station.
*/
void (*get_access_technology) (MMGenericGsm *self,
MMModemUIntFn callback,
gpointer user_data);
/* Called by the generic class to get additional Location capabilities that
* subclasses may implement. The MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI
* capabilities is automatically provided by the generic class, and
* subclasses should return a bitfield of additional location capabilities
* they support in the callback here.
*/
void (*loc_get_capabilities) (MMGenericGsm *self,
MMModemUIntFn callback,
gpointer user_data);
/* Called by the generic class to retrieve the SIM's ICCID */
void (*get_sim_iccid) (MMGenericGsm *self,
MMModemStringFn callback,
gpointer user_data);
/* Called by the generic class to retrieve the Operator's name */
void (*get_operator_name) (MMGenericGsm *self,
MMModemStringFn callback,
gpointer user_data);
/* Called by the generic class to retrieve the Operator's code */
void (*get_operator_code) (MMGenericGsm *self,
MMModemStringFn callback,
gpointer user_data);
} MMGenericGsmClass;
GType mm_generic_gsm_get_type (void);
MMModem *mm_generic_gsm_new (const char *device,
const char *driver,
const char *plugin,
guint vendor,
guint product);
/* Private, for subclasses */
#define MM_GENERIC_GSM_PREV_STATE_TAG "prev-state"
void mm_generic_gsm_pending_registration_stop (MMGenericGsm *modem);
void mm_generic_gsm_ussd_cleanup (MMGenericGsm *modem);
gint mm_generic_gsm_get_cid (MMGenericGsm *modem);
void mm_generic_gsm_set_reg_status (MMGenericGsm *modem,
MMGenericGsmRegType reg_type,
MMModemGsmNetworkRegStatus status);
MMModemCharset mm_generic_gsm_get_charset (MMGenericGsm *modem);
/* Called to asynchronously update the current allowed operating mode that the
* device is allowed to use when connecting to a network. This isn't the
* specific access technology the device is currently using (see
* mm_generic_gsm_set_access_technology() for that) but the mode the device is
* allowed to choose from when connecting.
*/
void mm_generic_gsm_update_allowed_mode (MMGenericGsm *modem,
MMModemGsmAllowedMode mode);
/* Called to asynchronously update the current access technology of the device;
* this is NOT the 2G/3G mode preference, but the current radio access
* technology being used to communicate with the base station.
*/
void mm_generic_gsm_update_access_technology (MMGenericGsm *modem,
MMModemGsmAccessTech act);
/* Called to asynchronously update the current signal quality of the device;
* 'quality' is a 0 - 100% quality.
*/
void mm_generic_gsm_update_signal_quality (MMGenericGsm *modem, guint32 quality);
/* Returns the first port (if any) which has the given flag */
MMAtSerialPort *mm_generic_gsm_get_at_port (MMGenericGsm *modem,
MMAtPortFlags flag);
MMAtSerialPort *mm_generic_gsm_get_best_at_port (MMGenericGsm *modem,
GError **error);
/* stay_connected should be TRUE for unsolicited registration updates, otherwise
* the registration update will clear connected/connecting/disconnecting state
* which we don't want. stay_connected should be FALSE for other cases like
* updating the state after disconnecting, or after a connect error occurs.
*/
void mm_generic_gsm_update_enabled_state (MMGenericGsm *modem,
gboolean stay_connected,
MMModemStateReason reason);
/* Called to complete the enable operation for custom enable() handling; if an
* error is passed in, it copies the error to the callback info. This function
* always schedules the callback info. It will also update the modem with the
* correct state for both failure and success of the enable operation.
*/
void mm_generic_gsm_enable_complete (MMGenericGsm *modem,
GError *error,
MMCallbackInfo *info);
/* Called to complete the enable operation for custom connect() handling; if an
* error is passed in, it copies the error to the callback info. This function
* always schedules the callback info. It will also update the modem with the
* correct state for both failure and success of the connect operation.
*/
void mm_generic_gsm_connect_complete (MMGenericGsm *modem,
GError *error,
MMCallbackInfo *info);
#endif /* MM_GENERIC_GSM_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,121 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#ifndef MM_MODEM_BASE_H
#define MM_MODEM_BASE_H
#include <glib.h>
#include <glib-object.h>
#include "mm-port.h"
#include "mm-at-serial-port.h"
#include "mm-qcdm-serial-port.h"
#include "mm-modem.h"
#define MM_TYPE_MODEM_BASE (mm_modem_base_get_type ())
#define MM_MODEM_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_BASE, MMModemBase))
#define MM_MODEM_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_BASE, MMModemBaseClass))
#define MM_IS_MODEM_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_BASE))
#define MM_IS_MODEM_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_BASE))
#define MM_MODEM_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_BASE, MMModemBaseClass))
typedef struct _MMModemBase MMModemBase;
typedef struct _MMModemBaseClass MMModemBaseClass;
#define MM_MODEM_BASE_MAX_TIMEOUTS "max-timeouts"
struct _MMModemBase {
GObject parent;
};
struct _MMModemBaseClass {
GObjectClass parent;
/* Called after the base class grabs a port so that subclasses can
* set port flags and other properties on the new port.
*/
void (*port_grabbed) (MMModemBase *self,
MMPort *port,
MMAtPortFlags at_pflags,
gpointer user_data);
};
GType mm_modem_base_get_type (void);
MMPort *mm_modem_base_get_port (MMModemBase *self,
const char *subsys,
const char *name);
GSList *mm_modem_base_get_ports (MMModemBase *self);
gboolean mm_modem_base_remove_port (MMModemBase *self,
MMPort *port);
gboolean mm_modem_base_organize_ports (MMModemBase *self,
MMAtSerialPort **out_primary,
MMAtSerialPort **out_secondary,
MMPort **out_data,
MMQcdmSerialPort **out_qcdm,
GError **error);
void mm_modem_base_set_valid (MMModemBase *self,
gboolean valid);
gboolean mm_modem_base_get_valid (MMModemBase *self);
const char *mm_modem_base_get_equipment_identifier (MMModemBase *self);
void mm_modem_base_set_equipment_identifier (MMModemBase *self,
const char *ident);
const char *mm_modem_base_get_unlock_required (MMModemBase *self);
void mm_modem_base_set_unlock_required (MMModemBase *self,
const char *unlock_required);
void mm_modem_base_set_pin_retry_counts (MMModemBase *self,
GArray *pin_retries);
void mm_modem_base_set_network_timezone (MMModemBase *self,
gint *offset,
gint *dst_offset,
gint *leap_seconds);
void mm_modem_base_set_network_timezone_polling (MMModemBase *self,
gboolean should_poll);
const char *mm_modem_base_get_manf (MMModemBase *self);
void mm_modem_base_set_manf (MMModemBase *self, const char *manf);
const char *mm_modem_base_get_model (MMModemBase *self);
void mm_modem_base_set_model (MMModemBase *self, const char *model);
const char *mm_modem_base_get_revision (MMModemBase *self);
void mm_modem_base_set_revision (MMModemBase *self, const char *revision);
void mm_modem_base_get_card_info (MMModemBase *self,
MMAtSerialPort *port,
GError *port_error,
MMModemInfoFn callback,
gpointer user_data);
typedef struct {
const char *name;
guint count;
} PinRetryCount;
#endif /* MM_MODEM_BASE_H */

View File

@@ -1,433 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-cdma.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
#include "mm-auth-provider.h"
static void impl_modem_cdma_get_signal_quality (MMModemCdma *modem, DBusGMethodInvocation *context);
static void impl_modem_cdma_get_esn (MMModemCdma *modem, DBusGMethodInvocation *context);
static void impl_modem_cdma_get_serving_system (MMModemCdma *modem, DBusGMethodInvocation *context);
static void impl_modem_cdma_get_registration_state (MMModemCdma *modem, DBusGMethodInvocation *context);
static void impl_modem_cdma_activate (MMModemCdma *modem, DBusGMethodInvocation *context);
static void impl_modem_cdma_activate_manual (MMModemCdma *modem, DBusGMethodInvocation *context);
#include "mm-modem-cdma-glue.h"
enum {
SIGNAL_QUALITY,
REGISTRATION_STATE_CHANGED,
ACTIVATION_STATE_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/*****************************************************************************/
static void
str_call_done (MMModem *modem, const char *result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
static void
str_call_not_supported (MMModemCdma *self,
MMModemStringFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_string_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_op_not_supported (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_uint_new (self, callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_call_done (MMModem *modem, guint32 result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
static void
serving_system_call_done (MMModemCdma *self,
guint32 class,
unsigned char band,
guint32 sid,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else {
GValueArray *array;
GValue value = { 0, };
char band_str[2] = { 0, 0 };
array = g_value_array_new (3);
/* Band Class */
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, class);
g_value_array_append (array, &value);
g_value_unset (&value);
/* Band */
g_value_init (&value, G_TYPE_STRING);
band_str[0] = band;
g_value_set_string (&value, band_str);
g_value_array_append (array, &value);
g_value_unset (&value);
/* SID */
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, sid);
g_value_array_append (array, &value);
g_value_unset (&value);
dbus_g_method_return (context, array);
g_value_array_free (array);
}
}
static void
serving_system_invoke (MMCallbackInfo *info)
{
MMModemCdmaServingSystemFn callback = (MMModemCdmaServingSystemFn) info->callback;
callback (MM_MODEM_CDMA (info->modem), 0, 0, 0, info->error, info->user_data);
}
static void
serving_system_call_not_supported (MMModemCdma *self,
MMModemCdmaServingSystemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self), serving_system_invoke, G_CALLBACK (callback), user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
void
mm_modem_cdma_get_serving_system (MMModemCdma *self,
MMModemCdmaServingSystemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->get_serving_system)
MM_MODEM_CDMA_GET_INTERFACE (self)->get_serving_system (self, callback, user_data);
else
serving_system_call_not_supported (self, callback, user_data);
}
static void
impl_modem_cdma_get_serving_system (MMModemCdma *modem,
DBusGMethodInvocation *context)
{
mm_modem_cdma_get_serving_system (modem, serving_system_call_done, context);
}
void
mm_modem_cdma_get_esn (MMModemCdma *self,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->get_esn)
MM_MODEM_CDMA_GET_INTERFACE (self)->get_esn (self, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
static void
esn_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemCdma *self = MM_MODEM_CDMA (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the ESN */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_cdma_get_esn (self, str_call_done, context);
}
static void
impl_modem_cdma_get_esn (MMModemCdma *self, DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to get the ESN */
if (!mm_modem_auth_request (MM_MODEM (self),
MM_AUTHORIZATION_DEVICE_INFO,
context,
esn_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
void
mm_modem_cdma_get_signal_quality (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->get_signal_quality)
MM_MODEM_CDMA_GET_INTERFACE (self)->get_signal_quality (self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_modem_cdma_get_signal_quality (MMModemCdma *modem, DBusGMethodInvocation *context)
{
mm_modem_cdma_get_signal_quality (modem, uint_call_done, context);
}
void
mm_modem_cdma_emit_signal_quality_changed (MMModemCdma *self, guint32 quality)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality);
}
void mm_modem_cdma_activate(MMModemCdma *self, MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->activate)
MM_MODEM_CDMA_GET_INTERFACE (self)->activate(self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void impl_modem_cdma_activate(MMModemCdma *modem,
DBusGMethodInvocation *context)
{
mm_modem_cdma_activate (modem, uint_call_done, context);
}
void mm_modem_cdma_activate_manual(MMModemCdma *self, MMModemUIntFn callback,
gpointer user_data) {
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->activate_manual)
MM_MODEM_CDMA_GET_INTERFACE (self)->activate_manual(self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void impl_modem_cdma_activate_manual (MMModemCdma *modem,
DBusGMethodInvocation *context) {
mm_modem_cdma_activate_manual(modem, uint_call_done, context);
}
/*****************************************************************************/
static void
get_registration_state_call_done (MMModemCdma *self,
MMModemCdmaRegistrationState cdma_1x_reg_state,
MMModemCdmaRegistrationState evdo_reg_state,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, cdma_1x_reg_state, evdo_reg_state);
}
void
mm_modem_cdma_get_registration_state (MMModemCdma *self,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_CDMA_GET_INTERFACE (self)->get_registration_state)
MM_MODEM_CDMA_GET_INTERFACE (self)->get_registration_state (self, callback, user_data);
else {
GError *error;
error = g_error_new_literal (MM_MODEM_ERROR,
MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
callback (self,
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
error,
user_data);
g_error_free (error);
}
}
static void
impl_modem_cdma_get_registration_state (MMModemCdma *modem, DBusGMethodInvocation *context)
{
mm_modem_cdma_get_registration_state (modem, get_registration_state_call_done, context);
}
void
mm_modem_cdma_emit_registration_state_changed (MMModemCdma *self,
MMModemCdmaRegistrationState cdma_1x_new_state,
MMModemCdmaRegistrationState evdo_new_state)
{
g_return_if_fail (MM_IS_MODEM_CDMA (self));
g_signal_emit (self, signals[REGISTRATION_STATE_CHANGED], 0, cdma_1x_new_state, evdo_new_state);
}
/*****************************************************************************/
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
static void
mm_modem_cdma_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Properties */
g_object_interface_install_property
(g_iface,
g_param_spec_string (MM_MODEM_CDMA_MEID,
"MEID",
"MEID",
NULL,
G_PARAM_READABLE));
/* Signals */
signals[SIGNAL_QUALITY] =
g_signal_new ("signal-quality",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemCdma, signal_quality),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1, G_TYPE_UINT);
signals[REGISTRATION_STATE_CHANGED] =
g_signal_new ("registration-state-changed",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemCdma, registration_state_changed),
NULL, NULL,
mm_marshal_VOID__UINT_UINT,
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
signals[ACTIVATION_STATE_CHANGED] =
g_signal_new ("activation-state-changed",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemCdma, registration_state_changed),
NULL, NULL,
mm_marshal_VOID__UINT_UINT_BOXED,
G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, DBUS_TYPE_G_MAP_OF_VARIANT);
initialized = TRUE;
}
GType
mm_modem_cdma_get_type (void)
{
static GType modem_type = 0;
if (!G_UNLIKELY (modem_type)) {
const GTypeInfo modem_info = {
sizeof (MMModemCdma), /* class_size */
mm_modem_cdma_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
modem_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemCdma",
&modem_info, 0);
g_type_interface_add_prerequisite (modem_type, MM_TYPE_MODEM);
dbus_g_object_type_install_info (modem_type, &dbus_glib_mm_modem_cdma_object_info);
}
return modem_type;
}

View File

@@ -1,126 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#ifndef MM_MODEM_CDMA_H
#define MM_MODEM_CDMA_H
#include <ModemManager.h>
#include <mm-modem.h>
#define MM_TYPE_MODEM_CDMA (mm_modem_cdma_get_type ())
#define MM_MODEM_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_CDMA, MMModemCdma))
#define MM_IS_MODEM_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_CDMA))
#define MM_MODEM_CDMA_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_CDMA, MMModemCdma))
#define MM_MODEM_CDMA_REGISTRATION_STATE_CHANGED "registration-state-changed"
#define MM_MODEM_CDMA_MEID "meid"
typedef enum {
MM_MODEM_CDMA_PROP_FIRST = 0x1200,
MM_MODEM_CDMA_PROP_MEID = MM_MODEM_CDMA_PROP_FIRST,
} MMModemCdmaProp;
typedef struct _MMModemCdma MMModemCdma;
typedef void (*MMModemCdmaServingSystemFn) (MMModemCdma *modem,
guint32 class,
unsigned char band,
guint32 sid,
GError *error,
gpointer user_data);
typedef void (*MMModemCdmaRegistrationStateFn) (MMModemCdma *modem,
MMModemCdmaRegistrationState cdma_1x_reg_state,
MMModemCdmaRegistrationState evdo_reg_state,
GError *error,
gpointer user_data);
struct _MMModemCdma {
GTypeInterface g_iface;
/* Methods */
void (*get_signal_quality) (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data);
void (*get_esn) (MMModemCdma *self,
MMModemStringFn callback,
gpointer user_data);
void (*get_serving_system) (MMModemCdma *self,
MMModemCdmaServingSystemFn callback,
gpointer user_data);
void (*get_registration_state) (MMModemCdma *self,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data);
void (*activate) (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data);
void (*activate_manual) (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data);
void (*activate_manual_debug) (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data);
/* Signals */
void (*signal_quality) (MMModemCdma *self,
guint32 quality);
void (*registration_state_changed) (MMModemCdma *self,
MMModemCdmaRegistrationState cdma_1x_new_state,
MMModemCdmaRegistrationState evdo_new_state);
};
GType mm_modem_cdma_get_type (void);
void mm_modem_cdma_get_signal_quality (MMModemCdma *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_cdma_get_esn (MMModemCdma *self,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_cdma_get_serving_system (MMModemCdma *self,
MMModemCdmaServingSystemFn callback,
gpointer user_data);
void mm_modem_cdma_get_registration_state (MMModemCdma *self,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data);
void mm_modem_cdma_activate (MMModemCdma *self, MMModemUIntFn callback,
gpointer user_data);
void mm_modem_cdma_activate_manual (MMModemCdma *self, MMModemUIntFn callback,
gpointer user_data);
/* Protected */
void mm_modem_cdma_emit_signal_quality_changed (MMModemCdma *self, guint32 new_quality);
void mm_modem_cdma_emit_registration_state_changed (MMModemCdma *self,
MMModemCdmaRegistrationState cdma_1x_new_state,
MMModemCdmaRegistrationState evdo_new_state);
#endif /* MM_MODEM_CDMA_H */

View File

@@ -1,316 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2011 The Chromium OS Authors
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-firmware.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
static void impl_modem_firmware_list (MMModemFirmware *modem,
DBusGMethodInvocation *context);
static void impl_modem_firmware_select (MMModemFirmware *modem,
const char *slot,
DBusGMethodInvocation *context);
static void impl_modem_firmware_install (MMModemFirmware *modem,
const char *image,
const char *slot,
DBusGMethodInvocation *context);
#include "mm-modem-firmware-glue.h"
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemFirmware *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
firmware_list_done (MMModemFirmware *self,
const char *selected,
GHashTable *installed,
GHashTable *available,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, selected, installed, available);
}
/*****************************************************************************/
static void
firmware_list_invoke (MMCallbackInfo *info)
{
MMModemFirmwareListFn callback = (MMModemFirmwareListFn) info->callback;
callback (MM_MODEM_FIRMWARE (info->modem), NULL, NULL, NULL, info->error, info->user_data);
}
void
mm_modem_firmware_list (MMModemFirmware *self,
MMModemFirmwareListFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_FIRMWARE (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_FIRMWARE_GET_INTERFACE (self)->list)
MM_MODEM_FIRMWARE_GET_INTERFACE (self)->list (self, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
firmware_list_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
void
mm_modem_firmware_select (MMModemFirmware *self,
const char *slot,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_FIRMWARE (self));
g_return_if_fail (slot != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_FIRMWARE_GET_INTERFACE (self)->select)
MM_MODEM_FIRMWARE_GET_INTERFACE (self)->select (self, slot, callback, user_data);
else
async_call_not_supported (self, async_call_done, user_data);
}
void
mm_modem_firmware_install (MMModemFirmware *self,
const char *image,
const char *slot,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_FIRMWARE (self));
g_return_if_fail (slot != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_FIRMWARE_GET_INTERFACE (self)->install)
MM_MODEM_FIRMWARE_GET_INTERFACE (self)->install (self, image, slot, callback, user_data);
else
async_call_not_supported (self, async_call_done, user_data);
}
typedef struct {
char *image;
char *slot;
} FirmwareAuthInfo;
static void
firmware_auth_info_destroy (gpointer data)
{
FirmwareAuthInfo *info = data;
g_free (info->image);
g_free (info->slot);
memset (info, 0, sizeof (FirmwareAuthInfo));
g_free (info);
}
static FirmwareAuthInfo *
firmware_auth_info_new (const char *image,
const char *slot)
{
FirmwareAuthInfo *info;
info = g_malloc0 (sizeof (FirmwareAuthInfo));
info->image = g_strdup(image);
info->slot = g_strdup(slot);
return info;
}
static void
firmware_list_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemFirmware *self = MM_MODEM_FIRMWARE (owner);
GError *error = NULL;
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_firmware_list (self, firmware_list_done, context);
}
static void
impl_modem_firmware_list (MMModemFirmware *modem, DBusGMethodInvocation *context)
{
GError *error = NULL;
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE,
context,
firmware_list_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free(error);
}
}
static void
firmware_select_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemFirmware *self = MM_MODEM_FIRMWARE (owner);
FirmwareAuthInfo *info = user_data;
const char *slot = info->slot;
GError *error = NULL;
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_firmware_select (self, slot, async_call_done, context);
}
static void
impl_modem_firmware_select (MMModemFirmware *modem,
const char *slot,
DBusGMethodInvocation *context)
{
GError *error = NULL;
FirmwareAuthInfo *info;
info = firmware_auth_info_new (NULL, slot);
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE,
context,
firmware_select_auth_cb,
info,
firmware_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static void
firmware_install_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemFirmware *self = MM_MODEM_FIRMWARE (owner);
FirmwareAuthInfo *info = user_data;
const char *image = info->image;
const char *slot = info->slot;
GError *error = NULL;
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_firmware_install (self, image, slot, async_call_done, context);
}
static void
impl_modem_firmware_install (MMModemFirmware *modem,
const char *image,
const char *slot,
DBusGMethodInvocation *context)
{
GError *error = NULL;
FirmwareAuthInfo *info;
info = firmware_auth_info_new (image, slot);
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE,
context,
firmware_install_auth_cb,
info,
firmware_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
GType
mm_modem_firmware_get_type (void)
{
static GType firmware_type = 0;
if (!G_UNLIKELY (firmware_type)) {
const GTypeInfo firmware_info = {
sizeof (MMModemFirmware), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
firmware_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemFirmware",
&firmware_info, 0);
g_type_interface_add_prerequisite (firmware_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (firmware_type, &dbus_glib_mm_modem_firmware_object_info);
}
return firmware_type;
}

View File

@@ -1,72 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2011 The Chromium OS Authors
*/
#ifndef MM_MODEM_FIRMWARE_H
#define MM_MODEM_FIRMWARE_H
#include <mm-modem.h>
#define MM_TYPE_MODEM_FIRMWARE (mm_modem_firmware_get_type ())
#define MM_MODEM_FIRMWARE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_FIRMWARE, MMModemFirmware))
#define MM_IS_MODEM_FIRMWARE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_FIRMWARE))
#define MM_MODEM_FIRMWARE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_FIRMWARE, MMModemFirmware))
typedef struct _MMModemFirmware MMModemFirmware;
typedef void (*MMModemFirmwareListFn) (MMModemFirmware *modem,
const char *selected,
GHashTable *installed,
GHashTable *available,
GError *error,
gpointer user_data);
struct _MMModemFirmware {
GTypeInterface g_iface;
/* Methods */
void (*list) (MMModemFirmware *modem,
MMModemFirmwareListFn callback,
gpointer user_data);
void (*select) (MMModemFirmware *modem,
const char *slot,
MMModemFn callback,
gpointer user_data);
void (*install) (MMModemFirmware *modem,
const char *image,
const char *slot,
MMModemFn callback,
gpointer user_data);
};
GType mm_modem_firmware_get_type (void);
void mm_modem_firmware_list (MMModemFirmware *self,
MMModemFirmwareListFn callback,
gpointer user_data);
void mm_modem_firmware_select (MMModemFirmware *self,
const char *slot,
MMModemFn callback,
gpointer user_data);
void mm_modem_firmware_install (MMModemFirmware *self,
const char *image,
const char *slot,
MMModemFn callback,
gpointer user_data);
#endif /* MM_MODEM_FIRMWARE_H */

View File

@@ -1,702 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#include <dbus/dbus-glib.h>
#include <string.h>
#include <ModemManager.h>
#include "mm-modem-gsm-card.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
static void impl_gsm_modem_get_imei (MMModemGsmCard *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_imsi (MMModemGsmCard *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_operator_id (MMModemGsmCard *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_spn (MMModemGsmCard *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_send_pin (MMModemGsmCard *modem,
const char *pin,
DBusGMethodInvocation *context);
static void impl_gsm_modem_send_puk (MMModemGsmCard *modem,
const char *puk,
const char *pin,
DBusGMethodInvocation *context);
static void impl_gsm_modem_enable_pin (MMModemGsmCard *modem,
const char *pin,
gboolean enabled,
DBusGMethodInvocation *context);
static void impl_gsm_modem_change_pin (MMModemGsmCard *modem,
const char *old_pin,
const char *new_pin,
DBusGMethodInvocation *context);
#include "mm-modem-gsm-card-glue.h"
/*****************************************************************************/
static void
str_call_done (MMModem *modem, const char *result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
static void
str_call_not_supported (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_string_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
array_call_not_supported (MMModemGsmCard *self,
MMModemArrayFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_array_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemGsmCard *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
/*****************************************************************************/
void
mm_modem_gsm_card_get_imei (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_imei)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_imei (self, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_get_imsi (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_imsi)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_imsi (self, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void mm_modem_gsm_card_get_unlock_retries (MMModemGsmCard *self,
MMModemArrayFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_unlock_retries)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_unlock_retries (self, callback, user_data);
else
array_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_get_operator_id (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_operator_id)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_operator_id (self, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_get_spn (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_spn)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_spn (self, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_send_puk (MMModemGsmCard *self,
const char *puk,
const char *pin,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (puk != NULL);
g_return_if_fail (pin != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->send_puk)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->send_puk (self, puk, pin, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_send_pin (MMModemGsmCard *self,
const char *pin,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (pin != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->send_pin)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->send_pin (self, pin, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_enable_pin (MMModemGsmCard *self,
const char *pin,
gboolean enabled,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (pin != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->enable_pin)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->enable_pin (self, pin, enabled, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_card_change_pin (MMModemGsmCard *self,
const char *old_pin,
const char *new_pin,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_CARD (self));
g_return_if_fail (old_pin != NULL);
g_return_if_fail (new_pin != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->change_pin)
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->change_pin (self, old_pin, new_pin, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
/*****************************************************************************/
static void
imei_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the IMEI */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_get_imei (self, str_call_done, context);
}
static void
impl_gsm_modem_get_imei (MMModemGsmCard *modem, DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to get the IMEI */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO,
context,
imei_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
imsi_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the IMSI */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_get_imsi (self, str_call_done, context);
}
static void
impl_gsm_modem_get_imsi (MMModemGsmCard *modem, DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to get the IMSI */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO,
context,
imsi_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
spn_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the SPN */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_get_spn (self, str_call_done, context);
}
static void
impl_gsm_modem_get_spn (MMModemGsmCard *modem, DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to get the SPN */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO,
context,
spn_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
operator_id_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the operator id */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_get_operator_id (self, str_call_done, context);
}
static void
impl_gsm_modem_get_operator_id (MMModemGsmCard *modem, DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to get the operator id */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO,
context,
operator_id_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
typedef struct {
char *puk;
char *pin;
char *pin2;
gboolean enabled;
} SendPinPukInfo;
static void
send_pin_puk_info_destroy (gpointer data)
{
SendPinPukInfo *info = data;
g_free (info->puk);
g_free (info->pin);
g_free (info->pin2);
memset (info, 0, sizeof (SendPinPukInfo));
g_free (info);
}
static SendPinPukInfo *
send_pin_puk_info_new (const char *puk,
const char *pin,
const char *pin2,
gboolean enabled)
{
SendPinPukInfo *info;
info = g_malloc0 (sizeof (SendPinPukInfo));
info->puk = g_strdup (puk);
info->pin = g_strdup (pin);
info->pin2 = g_strdup (pin2);
info->enabled = enabled;
return info;
}
/*****************************************************************************/
static void
send_puk_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
SendPinPukInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise send the PUK */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_send_puk (self, info->puk, info->pin, async_call_done, context);
}
static void
impl_gsm_modem_send_puk (MMModemGsmCard *modem,
const char *puk,
const char *pin,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SendPinPukInfo *info;
info = send_pin_puk_info_new (puk, pin, NULL, FALSE);
/* Make sure the caller is authorized to send the PUK */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL,
context,
send_puk_auth_cb,
info,
send_pin_puk_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
send_pin_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
SendPinPukInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise unlock the modem */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_send_pin (self, info->pin, async_call_done, context);
}
static void
impl_gsm_modem_send_pin (MMModemGsmCard *modem,
const char *pin,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SendPinPukInfo *info;
info = send_pin_puk_info_new (NULL, pin, NULL, FALSE);
/* Make sure the caller is authorized to unlock the modem */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL,
context,
send_pin_auth_cb,
info,
send_pin_puk_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
enable_pin_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
SendPinPukInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise enable the PIN */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_enable_pin (self, info->pin, info->enabled, async_call_done, context);
}
static void
impl_gsm_modem_enable_pin (MMModemGsmCard *modem,
const char *pin,
gboolean enabled,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SendPinPukInfo *info;
info = send_pin_puk_info_new (NULL, pin, NULL, enabled);
/* Make sure the caller is authorized to enable a PIN */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL,
context,
enable_pin_auth_cb,
info,
send_pin_puk_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
change_pin_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner);
SendPinPukInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise change the PIN */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_card_change_pin (self, info->pin, info->pin2, async_call_done, context);
}
static void
impl_gsm_modem_change_pin (MMModemGsmCard *modem,
const char *old_pin,
const char *new_pin,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SendPinPukInfo *info;
info = send_pin_puk_info_new (NULL, old_pin, new_pin, FALSE);
/* Make sure the caller is authorized to change the PIN */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL,
context,
change_pin_auth_cb,
info,
send_pin_puk_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
mm_modem_gsm_card_init (gpointer g_iface)
{
static gboolean initialized = FALSE;
if (G_LIKELY (initialized))
return;
initialized = TRUE;
g_object_interface_install_property
(g_iface,
g_param_spec_string (MM_MODEM_GSM_CARD_SIM_IDENTIFIER,
"SimIdentifier",
"An obfuscated identifier of the SIM",
NULL,
G_PARAM_READABLE));
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_GSM_CARD_SUPPORTED_BANDS,
"Supported Modes",
"Supported frequency bands of the card",
MM_MODEM_GSM_BAND_UNKNOWN,
G_MAXUINT32,
MM_MODEM_GSM_BAND_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_GSM_CARD_SUPPORTED_MODES,
"Supported Modes",
"Supported modes of the card (ex 2G preferred, 3G preferred, 2G only, etc",
MM_MODEM_GSM_MODE_UNKNOWN,
G_MAXUINT32,
MM_MODEM_GSM_MODE_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_GSM_CARD_ENABLED_FACILITY_LOCKS,
"Enabled Facility Locks",
"Facility locks (i.e. PINs) that are enabled",
MM_MODEM_GSM_FACILITY_NONE,
G_MAXUINT32,
MM_MODEM_GSM_FACILITY_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
GType
mm_modem_gsm_card_get_type (void)
{
static GType card_type = 0;
if (G_UNLIKELY (!card_type)) {
const GTypeInfo card_info = {
sizeof (MMModemGsmCard), /* class_size */
mm_modem_gsm_card_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
card_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemGsmCard",
&card_info, 0);
g_type_interface_add_prerequisite (card_type, G_TYPE_OBJECT);
g_type_interface_add_prerequisite (card_type, MM_TYPE_MODEM);
dbus_g_object_type_install_info (card_type, &dbus_glib_mm_modem_gsm_card_object_info);
}
return card_type;
}

View File

@@ -1,134 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#ifndef MM_MODEM_GSM_CARD_H
#define MM_MODEM_GSM_CARD_H
#include <mm-modem.h>
#define MM_MODEM_GSM_CARD_DBUS_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Card"
#define MM_TYPE_MODEM_GSM_CARD (mm_modem_gsm_card_get_type ())
#define MM_MODEM_GSM_CARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GSM_CARD, MMModemGsmCard))
#define MM_IS_MODEM_GSM_CARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GSM_CARD))
#define MM_MODEM_GSM_CARD_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_GSM_CARD, MMModemGsmCard))
#define MM_MODEM_GSM_CARD_SUPPORTED_BANDS "supported-bands"
#define MM_MODEM_GSM_CARD_SUPPORTED_MODES "supported-modes"
#define MM_MODEM_GSM_CARD_SIM_IDENTIFIER "sim-identifier"
#define MM_MODEM_GSM_CARD_ENABLED_FACILITY_LOCKS "enabled-facility-locks"
#define MM_MODEM_GSM_CARD_SIM_PIN "sim-pin"
#define MM_MODEM_GSM_CARD_SIM_PIN2 "sim-pin2"
#define MM_MODEM_GSM_CARD_SIM_PUK "sim-puk"
#define MM_MODEM_GSM_CARD_SIM_PUK2 "sim-puk2"
typedef struct _MMModemGsmCard MMModemGsmCard;
struct _MMModemGsmCard {
GTypeInterface g_iface;
/* Methods */
void (*get_imei) (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void (*get_imsi) (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void (*get_unlock_retries) (MMModemGsmCard *self,
MMModemArrayFn callback,
gpointer user_data);
void (*get_operator_id) (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void (*get_spn) (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void (*send_puk) (MMModemGsmCard *self,
const char *puk,
const char *pin,
MMModemFn callback,
gpointer user_data);
void (*send_pin) (MMModemGsmCard *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
void (*enable_pin) (MMModemGsmCard *self,
const char *pin,
gboolean enabled,
MMModemFn callback,
gpointer user_data);
void (*change_pin) (MMModemGsmCard *self,
const char *old_pin,
const char *new_pin,
MMModemFn callback,
gpointer user_data);
};
GType mm_modem_gsm_card_get_type (void);
void mm_modem_gsm_card_get_imei (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_card_get_imsi (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_card_get_unlock_retries (MMModemGsmCard *self,
MMModemArrayFn callback,
gpointer user_data);
void mm_modem_gsm_card_get_operator_id (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_card_get_spn (MMModemGsmCard *self,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_card_send_puk (MMModemGsmCard *self,
const char *puk,
const char *pin,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_card_send_pin (MMModemGsmCard *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_card_enable_pin (MMModemGsmCard *self,
const char *pin,
gboolean enabled,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_card_change_pin (MMModemGsmCard *self,
const char *old_pin,
const char *new_pin,
MMModemFn callback,
gpointer user_data);
#endif /* MM_MODEM_GSM_CARD_H */

View File

@@ -1,647 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2010 Red Hat, Inc.
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-gsm-network.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
#include "mm-utils.h"
static void impl_gsm_modem_register (MMModemGsmNetwork *modem,
const char *network_id,
DBusGMethodInvocation *context);
static void impl_gsm_modem_scan (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_set_apn (MMModemGsmNetwork *modem,
const char *apn,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_signal_quality (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_set_band (MMModemGsmNetwork *modem,
MMModemGsmBand band,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_band (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_set_allowed_mode (MMModemGsmNetwork *modem,
MMModemGsmAllowedMode mode,
DBusGMethodInvocation *context);
static void impl_gsm_modem_set_network_mode (MMModemGsmNetwork *modem,
MMModemGsmNetworkDeprecatedMode old_mode,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_network_mode (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_get_reg_info (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context);
#include "mm-modem-gsm-network-glue.h"
/*****************************************************************************/
enum {
SIGNAL_QUALITY,
REGISTRATION_INFO,
NETWORK_MODE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/*****************************************************************************/
MMModemGsmAllowedMode
mm_modem_gsm_network_old_mode_to_allowed (MMModemGsmNetworkDeprecatedMode old_mode)
{
/* Translate deprecated mode into new mode */
switch (old_mode) {
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_PREFERRED:
return MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED;
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_PREFERRED:
return MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED;
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY:
return MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY;
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY:
return MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY;
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY:
default:
return MM_MODEM_GSM_ALLOWED_MODE_ANY;
}
}
MMModemGsmNetworkDeprecatedMode
mm_modem_gsm_network_act_to_old_mode (MMModemGsmAccessTech act)
{
/* Translate new mode into old deprecated mode */
if (act & MM_MODEM_GSM_ACCESS_TECH_GPRS)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_GPRS;
else if (act & MM_MODEM_GSM_ACCESS_TECH_EDGE)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_EDGE;
else if (act & MM_MODEM_GSM_ACCESS_TECH_UMTS)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_UMTS;
else if (act & MM_MODEM_GSM_ACCESS_TECH_HSDPA)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSDPA;
else if (act & MM_MODEM_GSM_ACCESS_TECH_HSUPA)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSUPA;
else if (act & MM_MODEM_GSM_ACCESS_TECH_HSPA)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA;
else if (act & MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS)
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA;
return MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY;
}
/*****************************************************************************/
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemGsmNetwork *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_call_done (MMModem *modem, guint32 result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
static void
uint_call_not_supported (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
reg_info_call_done (MMModemGsmNetwork *self,
MMModemGsmNetworkRegStatus status,
const char *oper_code,
const char *oper_name,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else {
GValueArray *array;
GValue value = { 0, };
array = g_value_array_new (3);
/* Status */
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, (guint32) status);
g_value_array_append (array, &value);
g_value_unset (&value);
/* Operator code */
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, oper_code);
g_value_array_append (array, &value);
g_value_unset (&value);
/* Operator name */
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, oper_name);
g_value_array_append (array, &value);
g_value_unset (&value);
dbus_g_method_return (context, array);
g_value_array_free (array);
}
}
static void
reg_info_invoke (MMCallbackInfo *info)
{
MMModemGsmNetworkRegInfoFn callback = (MMModemGsmNetworkRegInfoFn) info->callback;
callback (MM_MODEM_GSM_NETWORK (info->modem), 0, NULL, NULL, info->error, info->user_data);
}
static void
reg_info_call_not_supported (MMModemGsmNetwork *self,
MMModemGsmNetworkRegInfoFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self), reg_info_invoke, G_CALLBACK (callback), user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
scan_call_done (MMModemGsmNetwork *self,
GPtrArray *results,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, results);
}
static void
gsm_network_scan_invoke (MMCallbackInfo *info)
{
MMModemGsmNetworkScanFn callback = (MMModemGsmNetworkScanFn) info->callback;
callback (MM_MODEM_GSM_NETWORK (info->modem), NULL, info->error, info->user_data);
}
static void
scan_call_not_supported (MMModemGsmNetwork *self,
MMModemGsmNetworkScanFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self), gsm_network_scan_invoke, G_CALLBACK (callback), user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
/*****************************************************************************/
void
mm_modem_gsm_network_register (MMModemGsmNetwork *self,
const char *network_id,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->do_register)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->do_register (self, network_id, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_scan (MMModemGsmNetwork *self,
MMModemGsmNetworkScanFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->scan)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->scan (self, callback, user_data);
else
scan_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_set_apn (MMModemGsmNetwork *self,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (apn != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_apn)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_apn (self, apn, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_get_signal_quality (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_signal_quality)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_signal_quality (self, callback, user_data);
else
uint_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_set_band (MMModemGsmNetwork *self,
MMModemGsmBand band,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_band)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_band (self, band, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_get_band (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_band)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_band (self, callback, user_data);
else
uint_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_set_allowed_mode (MMModemGsmNetwork *self,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_allowed_mode)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->set_allowed_mode (self, mode, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_get_registration_info (MMModemGsmNetwork *self,
MMModemGsmNetworkRegInfoFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_registration_info)
MM_MODEM_GSM_NETWORK_GET_INTERFACE (self)->get_registration_info (self, callback, user_data);
else
reg_info_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_network_signal_quality (MMModemGsmNetwork *self,
guint32 quality)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality);
}
void
mm_modem_gsm_network_registration_info (MMModemGsmNetwork *self,
MMModemGsmNetworkRegStatus status,
const char *oper_code,
const char *oper_name)
{
g_return_if_fail (MM_IS_MODEM_GSM_NETWORK (self));
g_signal_emit (self, signals[REGISTRATION_INFO], 0, status,
oper_code ? oper_code : "",
oper_name ? oper_name : "");
}
/*****************************************************************************/
static void
impl_gsm_modem_register (MMModemGsmNetwork *modem,
const char *network_id,
DBusGMethodInvocation *context)
{
const char *id;
/* DBus does not support NULL strings, so the caller should pass an empty string
for manual registration. */
if (strlen (network_id) < 1)
id = NULL;
else
id = network_id;
mm_modem_gsm_network_register (modem, id, async_call_done, context);
}
static void
scan_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmNetwork *self = MM_MODEM_GSM_NETWORK (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the IMEI */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_network_scan (self, scan_call_done, context);
}
static void
impl_gsm_modem_scan (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to request a scan */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL,
context,
scan_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static void
impl_gsm_modem_set_apn (MMModemGsmNetwork *modem,
const char *apn,
DBusGMethodInvocation *context)
{
mm_modem_gsm_network_set_apn (modem, apn, async_call_done, context);
}
static void
impl_gsm_modem_get_signal_quality (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context)
{
mm_modem_gsm_network_get_signal_quality (modem, uint_call_done, context);
}
static void
impl_gsm_modem_set_band (MMModemGsmNetwork *modem,
MMModemGsmBand band,
DBusGMethodInvocation *context)
{
mm_modem_gsm_network_set_band (modem, band, async_call_done, context);
}
static void
impl_gsm_modem_get_band (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context)
{
mm_modem_gsm_network_get_band (modem, uint_call_done, context);
}
static void
impl_gsm_modem_set_network_mode (MMModemGsmNetwork *modem,
MMModemGsmNetworkDeprecatedMode old_mode,
DBusGMethodInvocation *context)
{
if (!utils_check_for_single_value (old_mode)) {
GError *error;
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Invalid arguments (more than one value given)");
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
mm_modem_gsm_network_set_allowed_mode (modem,
mm_modem_gsm_network_old_mode_to_allowed (old_mode),
async_call_done,
context);
}
static void
impl_gsm_modem_set_allowed_mode (MMModemGsmNetwork *modem,
MMModemGsmAllowedMode mode,
DBusGMethodInvocation *context)
{
if (mode > MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY) {
GError *error;
error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Unknown allowed mode %d", mode);
dbus_g_method_return_error (context, error);
g_error_free (error);
return;
}
mm_modem_gsm_network_set_allowed_mode (modem, mode, async_call_done, context);
}
static void
impl_gsm_modem_get_network_mode (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context)
{
MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
/* DEPRECATED; it's now a property so it's quite easy to handle */
g_object_get (G_OBJECT (modem),
MM_MODEM_GSM_NETWORK_ACCESS_TECHNOLOGY, &act,
NULL);
dbus_g_method_return (context, mm_modem_gsm_network_act_to_old_mode (act));
}
static void
impl_gsm_modem_get_reg_info (MMModemGsmNetwork *modem,
DBusGMethodInvocation *context)
{
mm_modem_gsm_network_get_registration_info (modem, reg_info_call_done, context);
}
/*****************************************************************************/
static void
mm_modem_gsm_network_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Properties */
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_GSM_NETWORK_ALLOWED_MODE,
"Allowed Mode",
"Allowed network access mode",
MM_MODEM_GSM_ALLOWED_MODE_ANY,
MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY,
MM_MODEM_GSM_ALLOWED_MODE_ANY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_GSM_NETWORK_ACCESS_TECHNOLOGY,
"Access Technology",
"Current access technology in use when connected to "
"a mobile network.",
MM_MODEM_GSM_ACCESS_TECH_UNKNOWN,
MM_MODEM_GSM_ACCESS_TECH_LTE,
MM_MODEM_GSM_ACCESS_TECH_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* Signals */
signals[SIGNAL_QUALITY] =
g_signal_new ("signal-quality",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemGsmNetwork, signal_quality),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
signals[REGISTRATION_INFO] =
g_signal_new ("registration-info",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemGsmNetwork, registration_info),
NULL, NULL,
mm_marshal_VOID__UINT_STRING_STRING,
G_TYPE_NONE, 3,
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
signals[NETWORK_MODE] =
g_signal_new ("network-mode",
iface_type,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
initialized = TRUE;
}
GType
mm_modem_gsm_network_get_type (void)
{
static GType network_type = 0;
if (!G_UNLIKELY (network_type)) {
const GTypeInfo network_info = {
sizeof (MMModemGsmNetwork), /* class_size */
mm_modem_gsm_network_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
network_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemGsmNetwork",
&network_info, 0);
g_type_interface_add_prerequisite (network_type, G_TYPE_OBJECT);
g_type_interface_add_prerequisite (network_type, MM_TYPE_MODEM);
dbus_g_object_type_install_info (network_type, &dbus_glib_mm_modem_gsm_network_object_info);
}
return network_type;
}

View File

@@ -1,158 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
*/
#ifndef MM_MODEM_GSM_NETWORK_H
#define MM_MODEM_GSM_NETWORK_H
#include <ModemManager.h>
#include <mm-modem.h>
#define MM_MODEM_GSM_NETWORK_DBUS_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Network"
#define MM_TYPE_MODEM_GSM_NETWORK (mm_modem_gsm_network_get_type ())
#define MM_MODEM_GSM_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GSM_NETWORK, MMModemGsmNetwork))
#define MM_IS_MODEM_GSM_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GSM_NETWORK))
#define MM_MODEM_GSM_NETWORK_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_GSM_NETWORK, MMModemGsmNetwork))
#define MM_MODEM_GSM_NETWORK_ALLOWED_MODE "allowed-mode"
#define MM_MODEM_GSM_NETWORK_ACCESS_TECHNOLOGY "access-technology"
typedef enum {
MM_MODEM_GSM_NETWORK_PROP_FIRST = 0x1200,
MM_MODEM_GSM_NETWORK_PROP_ALLOWED_MODE = MM_MODEM_GSM_NETWORK_PROP_FIRST,
MM_MODEM_GSM_NETWORK_PROP_ACCESS_TECHNOLOGY,
} MMModemGsmNetworkProp;
typedef struct _MMModemGsmNetwork MMModemGsmNetwork;
typedef void (*MMModemGsmNetworkScanFn) (MMModemGsmNetwork *self,
GPtrArray *results,
GError *error,
gpointer user_data);
typedef void (*MMModemGsmNetworkRegInfoFn) (MMModemGsmNetwork *self,
MMModemGsmNetworkRegStatus status,
const char *oper_code,
const char *oper_name,
GError *error,
gpointer user_data);
struct _MMModemGsmNetwork {
GTypeInterface g_iface;
/* Methods */
/* 'register' is a reserved word */
void (*do_register) (MMModemGsmNetwork *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void (*scan) (MMModemGsmNetwork *self,
MMModemGsmNetworkScanFn callback,
gpointer user_data);
void (*set_apn) (MMModemGsmNetwork *self,
const char *apn,
MMModemFn callback,
gpointer user_data);
void (*get_signal_quality) (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_band) (MMModemGsmNetwork *self,
MMModemGsmBand band,
MMModemFn callback,
gpointer user_data);
void (*get_band) (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_allowed_mode) (MMModemGsmNetwork *self,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data);
void (*get_registration_info) (MMModemGsmNetwork *self,
MMModemGsmNetworkRegInfoFn callback,
gpointer user_data);
/* Signals */
void (*signal_quality) (MMModemGsmNetwork *self,
guint32 quality);
void (*registration_info) (MMModemGsmNetwork *self,
MMModemGsmNetworkRegStatus status,
const char *open_code,
const char *oper_name);
};
GType mm_modem_gsm_network_get_type (void);
void mm_modem_gsm_network_register (MMModemGsmNetwork *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_network_scan (MMModemGsmNetwork *self,
MMModemGsmNetworkScanFn callback,
gpointer user_data);
void mm_modem_gsm_network_set_apn (MMModemGsmNetwork *self,
const char *apn,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_network_get_signal_quality (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_gsm_network_set_band (MMModemGsmNetwork *self,
MMModemGsmBand band,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_network_get_band (MMModemGsmNetwork *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_gsm_network_get_registration_info (MMModemGsmNetwork *self,
MMModemGsmNetworkRegInfoFn callback,
gpointer user_data);
/* Protected */
void mm_modem_gsm_network_signal_quality (MMModemGsmNetwork *self,
guint32 quality);
void mm_modem_gsm_network_set_allowed_mode (MMModemGsmNetwork *self,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_network_registration_info (MMModemGsmNetwork *self,
MMModemGsmNetworkRegStatus status,
const char *oper_code,
const char *oper_name);
/* Private */
MMModemGsmNetworkDeprecatedMode mm_modem_gsm_network_act_to_old_mode (MMModemGsmAccessTech act);
MMModemGsmAllowedMode mm_modem_gsm_network_old_mode_to_allowed (MMModemGsmNetworkDeprecatedMode old_mode);
#endif /* MM_MODEM_GSM_NETWORK_H */

View File

@@ -1,836 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2009 Novell, Inc.
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-gsm-sms.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
static void impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_get (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_get_format (MMModemGsmSms *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_set_format (MMModemGsmSms *modem,
guint format,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_get_smsc (MMModemGsmSms *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
const char *smsc,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_list (MMModemGsmSms *modem,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_save (MMModemGsmSms *modem,
GHashTable *properties,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_send (MMModemGsmSms *modem,
GHashTable *properties,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context);
static void impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
guint mode,
guint mt,
guint bm,
guint ds,
guint bfr,
DBusGMethodInvocation *context);
#include "mm-modem-gsm-sms-glue.h"
enum {
SMS_RECEIVED,
COMPLETED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/*****************************************************************************/
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemGsmSms *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
sms_get_done (MMModemGsmSms *self,
GHashTable *properties,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, properties);
}
static void
sms_list_done (MMModemGsmSms *self,
GPtrArray *results,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, results);
}
/*****************************************************************************/
static void
sms_send_invoke (MMCallbackInfo *info)
{
MMModemGsmSmsSendFn callback = (MMModemGsmSmsSendFn) info->callback;
callback (MM_MODEM_GSM_SMS (info->modem), NULL, info->error, info->user_data);
}
void
mm_modem_gsm_sms_send (MMModemGsmSms *self,
const char *number,
const char *text,
const char *smsc,
guint validity,
guint class,
MMModemGsmSmsSendFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_return_if_fail (number != NULL);
g_return_if_fail (text != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_SMS_GET_INTERFACE (self)->send)
MM_MODEM_GSM_SMS_GET_INTERFACE (self)->send (self, number, text, smsc, validity, class, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
sms_send_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
static void
sms_get_invoke (MMCallbackInfo *info)
{
MMModemGsmSmsGetFn callback = (MMModemGsmSmsGetFn) info->callback;
callback (MM_MODEM_GSM_SMS (info->modem), NULL, info->error, info->user_data);
}
void
mm_modem_gsm_sms_get (MMModemGsmSms *self,
guint idx,
MMModemGsmSmsGetFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_SMS_GET_INTERFACE (self)->get)
MM_MODEM_GSM_SMS_GET_INTERFACE (self)->get (self, idx, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
sms_get_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
void
mm_modem_gsm_sms_delete (MMModemGsmSms *self,
guint idx,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_SMS_GET_INTERFACE (self)->delete)
MM_MODEM_GSM_SMS_GET_INTERFACE (self)->delete (self, idx, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
static void
sms_list_invoke (MMCallbackInfo *info)
{
MMModemGsmSmsListFn callback = (MMModemGsmSmsListFn) info->callback;
callback (MM_MODEM_GSM_SMS (info->modem), NULL, info->error, info->user_data);
}
void
mm_modem_gsm_sms_list (MMModemGsmSms *self,
MMModemGsmSmsListFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_SMS_GET_INTERFACE (self)->list)
MM_MODEM_GSM_SMS_GET_INTERFACE (self)->list (self, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
sms_list_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
void
mm_modem_gsm_sms_received (MMModemGsmSms *self,
guint idx,
gboolean complete)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_signal_emit (self, signals[SMS_RECEIVED], 0,
idx,
complete);
}
void
mm_modem_gsm_sms_completed (MMModemGsmSms *self,
guint idx,
gboolean complete)
{
g_return_if_fail (MM_IS_MODEM_GSM_SMS (self));
g_signal_emit (self, signals[COMPLETED], 0,
idx,
complete);
}
/*****************************************************************************/
typedef struct {
guint num1;
guint num2;
guint num3;
guint num4;
guint num5;
char *str;
GHashTable *hash;
} SmsAuthInfo;
static void
sms_auth_info_destroy (gpointer data)
{
SmsAuthInfo *info = data;
if (info->hash)
g_hash_table_destroy (info->hash);
g_free (info->str);
memset (info, 0, sizeof (SmsAuthInfo));
g_free (info);
}
static void
destroy_gvalue (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static SmsAuthInfo *
sms_auth_info_new (guint num1,
guint num2,
guint num3,
guint num4,
guint num5,
const char *str,
GHashTable *hash)
{
SmsAuthInfo *info;
info = g_malloc0 (sizeof (SmsAuthInfo));
info->num1 = num1;
info->num2 = num2;
info->num3 = num3;
info->num4 = num4;
info->num5 = num5;
info->str = g_strdup (str);
/* Copy the hash table if we're given one */
if (hash) {
GHashTableIter iter;
gpointer key, value;
info->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, destroy_gvalue);
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, &key, &value)) {
const char *str_key = (const char *) key;
GValue *src = (GValue *) value;
GValue *dst;
dst = g_slice_new0 (GValue);
g_value_init (dst, G_VALUE_TYPE (src));
g_value_copy (src, dst);
g_hash_table_insert (info->hash, g_strdup (str_key), dst);
}
}
return info;
}
/*****************************************************************************/
static void
sms_delete_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
SmsAuthInfo *info = user_data;
GError *error = NULL;
guint idx;
/* Return any authorization error, otherwise delete the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else {
idx = info->num1;
mm_modem_gsm_sms_delete (self, idx, async_call_done, context);
}
}
static void
impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
/* Make sure the caller is authorized to delete an SMS */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_delete_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
sms_get_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
SmsAuthInfo *info = user_data;
guint idx;
GError *error = NULL;
/* Return any authorization error, otherwise get the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else {
idx = info->num1;
mm_modem_gsm_sms_get (self, idx, sms_get_done, context);
}
}
static void
impl_gsm_modem_sms_get (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
/* Make sure the caller is authorized to get an SMS */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_get_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
impl_gsm_modem_sms_get_format (MMModemGsmSms *modem,
DBusGMethodInvocation *context)
{
async_call_not_supported (modem, async_call_done, context);
}
static void
impl_gsm_modem_sms_set_format (MMModemGsmSms *modem,
guint format,
DBusGMethodInvocation *context)
{
async_call_not_supported (modem, async_call_done, context);
}
static void
impl_gsm_modem_sms_get_smsc (MMModemGsmSms *modem,
DBusGMethodInvocation *context)
{
async_call_not_supported (modem, async_call_done, context);
}
/*****************************************************************************/
static void
sms_set_smsc_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
GError *error = NULL;
/* Return any authorization error, otherwise set the SMS service center */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
async_call_not_supported (self, async_call_done, context);
}
static void
impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
const char *smsc,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (0, 0, 0, 0, 0, smsc, NULL);
/* Make sure the caller is authorized to set the SMS service center */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_set_smsc_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
sms_list_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
GError *error = NULL;
/* Return any authorization error, otherwise list SMSs */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_gsm_sms_list (self, sms_list_done, context);
}
static void
impl_gsm_modem_sms_list (MMModemGsmSms *modem,
DBusGMethodInvocation *context)
{
GError *error = NULL;
/* Make sure the caller is authorized to list SMSs */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_list_auth_cb,
NULL,
NULL,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
sms_save_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
GError *error = NULL;
/* Return any authorization error, otherwise save the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
async_call_not_supported (self, async_call_done, context);
}
static void
impl_gsm_modem_sms_save (MMModemGsmSms *modem,
GHashTable *properties,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties);
/* Make sure the caller is authorized to save the SMS */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_save_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
send_sms_call_done (MMModemGsmSms *modem,
GArray *indexes,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, indexes);
}
static void
sms_send_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
SmsAuthInfo *info = user_data;
GError *error = NULL;
GValue *value;
const char *number = NULL;
const char *text = NULL ;
const char *smsc = NULL;
guint validity = 0;
guint class = 0;
/* Return any authorization error, otherwise delete the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error))
goto done;
value = (GValue *) g_hash_table_lookup (info->hash, "number");
if (value)
number = g_value_get_string (value);
value = (GValue *) g_hash_table_lookup (info->hash, "text");
if (value)
text = g_value_get_string (value);
value = (GValue *) g_hash_table_lookup (info->hash, "smsc");
if (value)
smsc = g_value_get_string (value);
value = (GValue *) g_hash_table_lookup (info->hash, "relative-validity");
if (value)
validity = g_value_get_uint (value);
value = (GValue *) g_hash_table_lookup (info->hash, "class");
if (value)
class = g_value_get_uint (value);
if (!number) {
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Missing number");
} else if (!text) {
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Missing message text");
}
done:
if (error) {
send_sms_call_done (self, NULL, error, context);
g_error_free (error);
} else
mm_modem_gsm_sms_send (self, number, text, smsc, validity, class, send_sms_call_done, context);
}
static void
impl_gsm_modem_sms_send (MMModemGsmSms *modem,
GHashTable *properties,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (0, 0, 0, 0, 0, NULL, properties);
/* Make sure the caller is authorized to send the PUK */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_send_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
sms_send_from_storage_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
GError *error = NULL;
/* Return any authorization error, otherwise delete the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
async_call_not_supported (self, async_call_done, context);
}
static void
impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
guint idx,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (idx, 0, 0, 0, 0, NULL, NULL);
/* Make sure the caller is authorized to send the PUK */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_send_from_storage_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
sms_set_indication_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmSms *self = MM_MODEM_GSM_SMS (owner);
GError *error = NULL;
/* Return any authorization error, otherwise delete the SMS */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
async_call_not_supported (self, async_call_done, context);
}
static void
impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
guint mode,
guint mt,
guint bm,
guint ds,
guint bfr,
DBusGMethodInvocation *context)
{
GError *error = NULL;
SmsAuthInfo *info;
info = sms_auth_info_new (mode, mt, bm, ds, bfr, NULL, NULL);
/* Make sure the caller is authorized to send the PUK */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS,
context,
sms_set_indication_auth_cb,
info,
sms_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
mm_modem_gsm_sms_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Signals */
signals[SMS_RECEIVED] =
g_signal_new ("sms-received",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemGsmSms, sms_received),
NULL, NULL,
mm_marshal_VOID__UINT_BOOLEAN,
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_BOOLEAN);
signals[COMPLETED] =
g_signal_new ("completed",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModemGsmSms, completed),
NULL, NULL,
mm_marshal_VOID__UINT_BOOLEAN,
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_BOOLEAN);
initialized = TRUE;
}
GType
mm_modem_gsm_sms_get_type (void)
{
static GType sms_type = 0;
if (!G_UNLIKELY (sms_type)) {
const GTypeInfo sms_info = {
sizeof (MMModemGsmSms), /* class_size */
mm_modem_gsm_sms_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
sms_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemGsmSms",
&sms_info, 0);
g_type_interface_add_prerequisite (sms_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (sms_type, &dbus_glib_mm_modem_gsm_sms_object_info);
}
return sms_type;
}

View File

@@ -1,114 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2009 Novell, Inc.
*/
#ifndef MM_MODEM_GSM_SMS_H
#define MM_MODEM_GSM_SMS_H
#include <mm-modem.h>
#define MM_TYPE_MODEM_GSM_SMS (mm_modem_gsm_sms_get_type ())
#define MM_MODEM_GSM_SMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GSM_SMS, MMModemGsmSms))
#define MM_IS_MODEM_GSM_SMS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GSM_SMS))
#define MM_MODEM_GSM_SMS_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_GSM_SMS, MMModemGsmSms))
typedef struct _MMModemGsmSms MMModemGsmSms;
typedef void (*MMModemGsmSmsGetFn) (MMModemGsmSms *modem,
GHashTable *properties,
GError *error,
gpointer user_data);
typedef void (*MMModemGsmSmsListFn) (MMModemGsmSms *modem,
GPtrArray *resultlist,
GError *error,
gpointer user_data);
typedef void (*MMModemGsmSmsSendFn) (MMModemGsmSms *modem,
GArray *indexes,
GError *error,
gpointer user_data);
struct _MMModemGsmSms {
GTypeInterface g_iface;
/* Methods */
void (*send) (MMModemGsmSms *modem,
const char *number,
const char *text,
const char *smsc,
guint validity,
guint class,
MMModemGsmSmsSendFn callback,
gpointer user_data);
void (*get) (MMModemGsmSms *modem,
guint32 index,
MMModemGsmSmsGetFn callback,
gpointer user_data);
void (*delete) (MMModemGsmSms *modem,
guint32 index,
MMModemFn callback,
gpointer user_data);
void (*list) (MMModemGsmSms *modem,
MMModemGsmSmsListFn callback,
gpointer user_data);
/* Signals */
void (*sms_received) (MMModemGsmSms *self,
guint32 index,
gboolean completed);
void (*completed) (MMModemGsmSms *self,
guint32 index,
gboolean completed);
};
GType mm_modem_gsm_sms_get_type (void);
void mm_modem_gsm_sms_send (MMModemGsmSms *self,
const char *number,
const char *text,
const char *smsc,
guint validity,
guint class,
MMModemGsmSmsSendFn callback,
gpointer user_data);
void mm_modem_gsm_sms_get (MMModemGsmSms *self,
guint idx,
MMModemGsmSmsGetFn callback,
gpointer user_data);
void mm_modem_gsm_sms_delete (MMModemGsmSms *self,
guint idx,
MMModemFn callback,
gpointer user_data);
void mm_modem_gsm_sms_list (MMModemGsmSms *self,
MMModemGsmSmsListFn callback,
gpointer user_data);
void mm_modem_gsm_sms_received (MMModemGsmSms *self,
guint idx,
gboolean complete);
void mm_modem_gsm_sms_completed (MMModemGsmSms *self,
guint idx,
gboolean complete);
#endif /* MM_MODEM_GSM_SMS_H */

View File

@@ -1,404 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2010 Guido Guenther <agx@sigxcpu.org>
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-gsm-ussd.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
static void impl_modem_gsm_ussd_initiate(MMModemGsmUssd *modem,
const char*command,
DBusGMethodInvocation *context);
static void impl_modem_gsm_ussd_respond(MMModemGsmUssd *modem,
const char *response,
DBusGMethodInvocation *context);
static void impl_modem_gsm_ussd_cancel(MMModemGsmUssd *modem,
DBusGMethodInvocation *context);
#include "mm-modem-gsm-ussd-glue.h"
/*****************************************************************************/
static void
str_call_done (MMModem *modem, const char *result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
static void
str_call_not_supported (MMModemGsmUssd *self,
MMModemStringFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_string_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemGsmUssd *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
/*****************************************************************************/
void
mm_modem_gsm_ussd_initiate (MMModemGsmUssd *self,
const char *command,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_USSD (self));
g_return_if_fail (command != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_USSD_GET_INTERFACE (self)->initiate)
MM_MODEM_GSM_USSD_GET_INTERFACE (self)->initiate(self, command, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_ussd_respond (MMModemGsmUssd *self,
const char *command,
MMModemStringFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_USSD (self));
g_return_if_fail (command != NULL);
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_USSD_GET_INTERFACE (self)->respond)
MM_MODEM_GSM_USSD_GET_INTERFACE (self)->respond(self, command, callback, user_data);
else
str_call_not_supported (self, callback, user_data);
}
void
mm_modem_gsm_ussd_cancel (MMModemGsmUssd *self,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_GSM_USSD (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GSM_USSD_GET_INTERFACE (self)->cancel)
MM_MODEM_GSM_USSD_GET_INTERFACE (self)->cancel(self, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
char*
mm_modem_gsm_ussd_encode (MMModemGsmUssd *self,
const char* command,
guint *schema)
{
if (MM_MODEM_GSM_USSD_GET_INTERFACE (self)->encode)
return MM_MODEM_GSM_USSD_GET_INTERFACE (self)->encode(self,
command,
schema);
else
return NULL;
}
char*
mm_modem_gsm_ussd_decode (MMModemGsmUssd *self,
const char* reply,
guint schema)
{
if (MM_MODEM_GSM_USSD_GET_INTERFACE (self)->decode)
return MM_MODEM_GSM_USSD_GET_INTERFACE (self)->decode(self,
reply,
schema);
else
return NULL;
}
/*****************************************************************************/
typedef struct {
char *command;
} UssdAuthInfo;
static void
ussd_auth_info_destroy (gpointer data)
{
UssdAuthInfo *info = data;
g_free (info->command);
g_free (info);
}
static UssdAuthInfo *
ussd_auth_info_new (const char* command)
{
UssdAuthInfo *info;
info = g_malloc0 (sizeof (UssdAuthInfo));
info->command = g_strdup (command);
return info;
}
/*****************************************************************************/
static void
ussd_initiate_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmUssd *self = MM_MODEM_GSM_USSD (owner);
UssdAuthInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise initiate the USSD */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error))
goto done;
if (!info->command) {
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Missing USSD command");
}
done:
if (error) {
str_call_done (MM_MODEM (self), NULL, error, context);
g_error_free (error);
} else
mm_modem_gsm_ussd_initiate (self, info->command, str_call_done, context);
}
static void
impl_modem_gsm_ussd_initiate (MMModemGsmUssd *modem,
const char *command,
DBusGMethodInvocation *context)
{
GError *error = NULL;
UssdAuthInfo *info;
info = ussd_auth_info_new (command);
/* Make sure the caller is authorized to initiate the USSD */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD,
context,
ussd_initiate_auth_cb,
info,
ussd_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static void
ussd_respond_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmUssd *self = MM_MODEM_GSM_USSD (owner);
UssdAuthInfo *info = user_data;
GError *error = NULL;
/* Return any authorization error, otherwise respond to the USSD */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error))
goto done;
if (!info->command) {
error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Missing USSD command");
}
done:
if (error) {
str_call_done (MM_MODEM (self), NULL, error, context);
g_error_free (error);
} else
mm_modem_gsm_ussd_respond (self, info->command, str_call_done, context);
}
static void
impl_modem_gsm_ussd_respond (MMModemGsmUssd *modem,
const char *command,
DBusGMethodInvocation *context)
{
GError *error = NULL;
UssdAuthInfo *info;
info = ussd_auth_info_new (command);
/* Make sure the caller is authorized to respond to the USSD */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD,
context,
ussd_respond_auth_cb,
info,
ussd_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
static void
ussd_cancel_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemGsmUssd *self = MM_MODEM_GSM_USSD (owner);
GError *error = NULL;
/* Return any authorization error, otherwise cancel the USSD */
mm_modem_auth_finish (MM_MODEM (self), req, &error);
if (error) {
str_call_done (MM_MODEM (self), NULL, error, context);
g_error_free (error);
} else
mm_modem_gsm_ussd_cancel (self, async_call_done, context);
}
static void
impl_modem_gsm_ussd_cancel (MMModemGsmUssd *modem,
DBusGMethodInvocation *context)
{
GError *error = NULL;
UssdAuthInfo *info;
info = ussd_auth_info_new (NULL);
/* Make sure the caller is authorized to cancel USSD */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD,
context,
ussd_cancel_auth_cb,
info,
ussd_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
mm_modem_gsm_ussd_init (gpointer g_iface)
{
static gboolean initialized = FALSE;
if (initialized)
return;
/* Properties */
g_object_interface_install_property
(g_iface,
g_param_spec_string (MM_MODEM_GSM_USSD_STATE,
"State",
"Current state of USSD session",
NULL,
G_PARAM_READABLE));
g_object_interface_install_property
(g_iface,
g_param_spec_string (MM_MODEM_GSM_USSD_NETWORK_NOTIFICATION,
"NetworkNotification",
"Network initiated request, no response required",
NULL,
G_PARAM_READABLE));
g_object_interface_install_property
(g_iface,
g_param_spec_string (MM_MODEM_GSM_USSD_NETWORK_REQUEST,
"NetworkRequest",
"Network initiated request, reponse required",
NULL,
G_PARAM_READABLE));
initialized = TRUE;
}
GType
mm_modem_gsm_ussd_get_type (void)
{
static GType ussd_type = 0;
if (!G_UNLIKELY (ussd_type)) {
const GTypeInfo ussd_info = {
sizeof (MMModemGsmUssd), /* class_size */
mm_modem_gsm_ussd_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
ussd_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemGsmUssd",
&ussd_info, 0);
g_type_interface_add_prerequisite (ussd_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (ussd_type, &dbus_glib_mm_modem_gsm_ussd_object_info);
dbus_g_object_type_register_shadow_property (ussd_type,
"State",
MM_MODEM_GSM_USSD_STATE);
}
return ussd_type;
}

View File

@@ -1,95 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2010 Guido Guenther <agx@sigxcpu.org>
*/
#ifndef MM_MODEM_GSM_USSD_H
#define MM_MODEM_GSM_USSD_H
#include <mm-modem.h>
typedef enum {
MM_MODEM_GSM_USSD_STATE_IDLE = 0x00000000,
MM_MODEM_GSM_USSD_STATE_ACTIVE = 0x00000001,
MM_MODEM_GSM_USSD_STATE_USER_RESPONSE = 0x00000002,
} MMModemGsmUssdState;
#define MM_MODEM_GSM_USSD_STATE "ussd-state"
#define MM_MODEM_GSM_USSD_NETWORK_NOTIFICATION "network-notification"
#define MM_MODEM_GSM_USSD_NETWORK_REQUEST "network-request"
#define MM_TYPE_MODEM_GSM_USSD (mm_modem_gsm_ussd_get_type ())
#define MM_MODEM_GSM_USSD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GSM_USSD, MMModemGsmUssd))
#define MM_IS_MODEM_GSM_USSD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GSM_USSD))
#define MM_MODEM_GSM_USSD_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_GSM_USSD, MMModemGsmUssd))
#define MM_MODEM_GSM_USSD_DBUS_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Ussd"
typedef struct _MMModemGsmUssd MMModemGsmUssd;
struct _MMModemGsmUssd {
GTypeInterface g_iface;
/* Methods */
void (*initiate) (MMModemGsmUssd *modem,
const char *command,
MMModemStringFn callback,
gpointer user_data);
void (*respond) (MMModemGsmUssd *modem,
const char *command,
MMModemStringFn callback,
gpointer user_data);
void (*cancel) (MMModemGsmUssd *modem,
MMModemFn callback,
gpointer user_data);
gchar* (*encode) (MMModemGsmUssd *modem,
const char* command,
guint *scheme);
gchar* (*decode) (MMModemGsmUssd *modem,
const char* command,
guint scheme);
};
GType mm_modem_gsm_ussd_get_type (void);
void mm_modem_gsm_ussd_initiate (MMModemGsmUssd *self,
const char *command,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_ussd_respond (MMModemGsmUssd *self,
const char *command,
MMModemStringFn callback,
gpointer user_data);
void mm_modem_gsm_ussd_cancel (MMModemGsmUssd *self,
MMModemFn callback,
gpointer user_data);
/* CBS data coding scheme - 3GPP TS 23.038 */
#define MM_MODEM_GSM_USSD_SCHEME_7BIT 0b00001111
#define MM_MODEM_GSM_USSD_SCHEME_UCS2 0b01001000
char *mm_modem_gsm_ussd_encode (MMModemGsmUssd *self,
const char* command,
guint *scheme);
char *mm_modem_gsm_ussd_decode (MMModemGsmUssd *self,
const char* reply,
guint scheme);
#endif /* MM_MODEM_GSM_USSD_H */

View File

@@ -1,331 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2010 Red Hat, Inc.
*/
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem-location.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
static void impl_modem_location_enable (MMModemLocation *modem,
gboolean enable,
gboolean signal_location,
DBusGMethodInvocation *context);
static void impl_modem_location_get_location (MMModemLocation *modem,
DBusGMethodInvocation *context);
#include "mm-modem-location-glue.h"
/*****************************************************************************/
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
async_call_not_supported (MMModemLocation *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
/*****************************************************************************/
typedef struct {
gboolean enable;
gboolean signals_location;
} LocAuthInfo;
static void
loc_auth_info_destroy (gpointer data)
{
LocAuthInfo *info = data;
memset (info, 0, sizeof (LocAuthInfo));
g_free (info);
}
static LocAuthInfo *
loc_auth_info_new (gboolean enable, gboolean signals_location)
{
LocAuthInfo *info;
info = g_malloc0 (sizeof (LocAuthInfo));
info->enable = enable;
info->signals_location = signals_location;
return info;
}
/*****************************************************************************/
void
mm_modem_location_enable (MMModemLocation *self,
gboolean enable,
gboolean signals_location,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_LOCATION (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_LOCATION_GET_INTERFACE (self)->enable)
MM_MODEM_LOCATION_GET_INTERFACE (self)->enable (self, enable, signals_location, callback, user_data);
else
async_call_not_supported (self, callback, user_data);
}
/*****************************************************************************/
static void
loc_enable_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemLocation *self = MM_MODEM_LOCATION (owner);
LocAuthInfo *info = (LocAuthInfo *) user_data;
GError *error = NULL;
/* Return any authorization error, otherwise enable location gathering */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_location_enable (self, info->enable, info->signals_location, async_call_done, context);
}
static void
impl_modem_location_enable (MMModemLocation *modem,
gboolean enable,
gboolean signals_location,
DBusGMethodInvocation *context)
{
GError *error = NULL;
LocAuthInfo *info;
info = loc_auth_info_new (enable, signals_location);
/* Make sure the caller is authorized to enable location gathering */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_LOCATION,
context,
loc_enable_auth_cb,
info,
loc_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
loc_get_invoke (MMCallbackInfo *info)
{
MMModemLocationGetFn callback = (MMModemLocationGetFn) info->callback;
callback ((MMModemLocation *) info->modem, NULL, info->error, info->user_data);
}
static void
async_get_call_not_supported (MMModemLocation *self,
MMModemLocationGetFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
loc_get_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
void
mm_modem_location_get_location (MMModemLocation *self,
MMModemLocationGetFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_LOCATION (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_LOCATION_GET_INTERFACE (self)->get_location)
MM_MODEM_LOCATION_GET_INTERFACE (self)->get_location (self, callback, user_data);
else
async_get_call_not_supported (self, callback, user_data);
}
/*****************************************************************************/
static void
async_get_call_done (MMModemLocation *self,
GHashTable *locations,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, locations);
}
static void
loc_get_auth_cb (MMAuthRequest *req,
GObject *owner,
DBusGMethodInvocation *context,
gpointer user_data)
{
MMModemLocation *self = MM_MODEM_LOCATION (owner);
GError *error = NULL;
/* Return any authorization error, otherwise get the location */
if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
} else
mm_modem_location_get_location (self, async_get_call_done, context);
}
static void
impl_modem_location_get_location (MMModemLocation *modem,
DBusGMethodInvocation *context)
{
GError *error = NULL;
LocAuthInfo *info;
info = loc_auth_info_new (FALSE, FALSE);
/* Make sure the caller is authorized to enable location gathering */
if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_LOCATION,
context,
loc_get_auth_cb,
info,
loc_auth_info_destroy,
&error)) {
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
/*****************************************************************************/
static void
mm_modem_location_init (gpointer g_iface)
{
static gboolean initialized = FALSE;
if (initialized)
return;
/* Properties */
g_object_interface_install_property
(g_iface,
g_param_spec_boxed (MM_MODEM_LOCATION_LOCATION,
"Location",
"Available location information",
MM_MODEM_LOCATION_PROP_TYPE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_uint (MM_MODEM_LOCATION_CAPABILITIES,
"Capabilities",
"Supported location information methods",
MM_MODEM_LOCATION_CAPABILITY_UNKNOWN,
MM_MODEM_LOCATION_CAPABILITY_GPS_NMEA
| MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI
| MM_MODEM_LOCATION_CAPABILITY_GPS_RAW,
MM_MODEM_LOCATION_CAPABILITY_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_boolean (MM_MODEM_LOCATION_ENABLED,
"Enabled",
"Whether or not location gathering is enabled",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_interface_install_property
(g_iface,
g_param_spec_boolean (MM_MODEM_LOCATION_SIGNALS_LOCATION,
"SignalsLocation",
"Whether or not location updates are emitted as signals",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
initialized = TRUE;
}
GType
mm_modem_location_get_type (void)
{
static GType loc_type = 0;
if (!G_UNLIKELY (loc_type)) {
const GTypeInfo loc_info = {
sizeof (MMModemLocation), /* class_size */
mm_modem_location_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
loc_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemLocation",
&loc_info, 0);
g_type_interface_add_prerequisite (loc_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (loc_type, &dbus_glib_mm_modem_location_object_info);
/* Register some shadow properties to handle Enabled and Capabilities
* since these could be used by other interfaces.
*/
dbus_g_object_type_register_shadow_property (loc_type,
"Enabled",
MM_MODEM_LOCATION_ENABLED);
dbus_g_object_type_register_shadow_property (loc_type,
"Capabilities",
MM_MODEM_LOCATION_CAPABILITIES);
}
return loc_type;
}

View File

@@ -1,69 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2010 Red Hat, Inc.
*/
#ifndef MM_MODEM_LOCATION_H
#define MM_MODEM_LOCATION_H
#include <mm-modem.h>
#define MM_TYPE_MODEM_LOCATION (mm_modem_location_get_type ())
#define MM_MODEM_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_LOCATION, MMModemLocation))
#define MM_IS_MODEM_LOCATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_LOCATION))
#define MM_MODEM_LOCATION_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_LOCATION, MMModemLocation))
#define MM_MODEM_LOCATION_DBUS_INTERFACE "org.freedesktop.ModemManager.Modem.Location"
#define MM_MODEM_LOCATION_PROP_TYPE (dbus_g_type_get_map ("GHashTable", G_TYPE_UINT, G_TYPE_VALUE))
#define MM_MODEM_LOCATION_CAPABILITIES "location-capabilities"
#define MM_MODEM_LOCATION_ENABLED "location-enabled"
#define MM_MODEM_LOCATION_SIGNALS_LOCATION "signals-location"
#define MM_MODEM_LOCATION_LOCATION "location"
typedef struct _MMModemLocation MMModemLocation;
typedef void (*MMModemLocationGetFn) (MMModemLocation *modem,
GHashTable *locations,
GError *error,
gpointer user_data);
struct _MMModemLocation {
GTypeInterface g_iface;
/* Methods */
void (*enable) (MMModemLocation *modem,
gboolean enable,
gboolean signal_location,
MMModemFn callback,
gpointer user_data);
void (*get_location) (MMModemLocation *modem,
MMModemLocationGetFn callback,
gpointer user_data);
};
GType mm_modem_location_get_type (void);
void mm_modem_location_enable (MMModemLocation *self,
gboolean enable,
gboolean signal_location,
MMModemFn callback,
gpointer user_data);
void mm_modem_location_get_location (MMModemLocation *self,
MMModemLocationGetFn callback,
gpointer user_data);
#endif /* MM_MODEM_LOCATION_H */

View File

@@ -1,156 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2009 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#include <dbus/dbus-glib.h>
#include "mm-modem-simple.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
static void impl_modem_simple_connect (MMModemSimple *self, GHashTable *properties, DBusGMethodInvocation *context);
static void impl_modem_simple_get_status (MMModemSimple *self, DBusGMethodInvocation *context);
#include "mm-modem-simple-glue.h"
void
mm_modem_simple_connect (MMModemSimple *self,
GHashTable *properties,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
g_return_if_fail (properties != NULL);
if (MM_MODEM_SIMPLE_GET_INTERFACE (self)->connect)
MM_MODEM_SIMPLE_GET_INTERFACE (self)->connect (self, properties, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
static void
simple_get_status_invoke (MMCallbackInfo *info)
{
MMModemSimpleGetStatusFn callback = (MMModemSimpleGetStatusFn) info->callback;
callback (MM_MODEM_SIMPLE (info->modem), NULL, info->error, info->user_data);
}
void
mm_modem_simple_get_status (MMModemSimple *self,
MMModemSimpleGetStatusFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_SIMPLE (self));
if (MM_MODEM_SIMPLE_GET_INTERFACE (self)->get_status)
MM_MODEM_SIMPLE_GET_INTERFACE (self)->get_status (self, callback, user_data);
else {
MMCallbackInfo *info;
info = mm_callback_info_new_full (MM_MODEM (self),
simple_get_status_invoke,
G_CALLBACK (callback),
user_data);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"Operation not supported");
mm_callback_info_schedule (info);
}
}
/*****************************************************************************/
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
impl_modem_simple_connect (MMModemSimple *self,
GHashTable *properties,
DBusGMethodInvocation *context)
{
mm_modem_simple_connect (self, properties, async_call_done, context);
}
static void
get_status_done (MMModemSimple *modem,
GHashTable *properties,
GError *error,
gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, properties);
}
static void
impl_modem_simple_get_status (MMModemSimple *self,
DBusGMethodInvocation *context)
{
mm_modem_simple_get_status (self, get_status_done, context);
}
/*****************************************************************************/
static void
mm_modem_simple_init (gpointer g_iface)
{
}
GType
mm_modem_simple_get_type (void)
{
static GType modem_type = 0;
if (!G_UNLIKELY (modem_type)) {
const GTypeInfo modem_info = {
sizeof (MMModemSimple), /* class_size */
mm_modem_simple_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
modem_type = g_type_register_static (G_TYPE_INTERFACE,
"MMModemSimple",
&modem_info, 0);
g_type_interface_add_prerequisite (modem_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (modem_type, &dbus_glib_mm_modem_simple_object_info);
}
return modem_type;
}

View File

@@ -1,59 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2009 Novell, Inc.
*/
#ifndef MM_MODEM_SIMPLE_H
#define MM_MODEM_SIMPLE_H
#include <glib-object.h>
#include <mm-modem.h>
#define MM_TYPE_MODEM_SIMPLE (mm_modem_simple_get_type ())
#define MM_MODEM_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_SIMPLE, MMModemSimple))
#define MM_IS_MODEM_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_SIMPLE))
#define MM_MODEM_SIMPLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_SIMPLE, MMModemSimple))
typedef struct _MMModemSimple MMModemSimple;
typedef void (*MMModemSimpleGetStatusFn) (MMModemSimple *modem,
GHashTable *properties,
GError *error,
gpointer user_data);
struct _MMModemSimple {
GTypeInterface g_iface;
/* Methods */
void (*connect) (MMModemSimple *self,
GHashTable *properties,
MMModemFn callback,
gpointer user_data);
void (*get_status) (MMModemSimple *self,
MMModemSimpleGetStatusFn callback,
gpointer user_data);
};
GType mm_modem_simple_get_type (void);
void mm_modem_simple_connect (MMModemSimple *self,
GHashTable *properties,
MMModemFn callback,
gpointer user_data);
void mm_modem_simple_get_status (MMModemSimple *self,
MMModemSimpleGetStatusFn callback,
gpointer user_data);
#endif /* MM_MODEM_SIMPLE_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,300 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
*/
#ifndef MM_MODEM_H
#define MM_MODEM_H
#include <glib-object.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <ModemManager.h>
#include "mm-port.h"
#include "mm-at-serial-port.h"
#include "mm-auth-provider.h"
#include "mm-charsets.h"
#define DBUS_PATH_TAG "dbus-path"
#define MM_TYPE_MODEM (mm_modem_get_type ())
#define MM_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM, MMModem))
#define MM_IS_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM))
#define MM_MODEM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM, MMModem))
#define MM_MODEM_DATA_DEVICE "device"
#define MM_MODEM_MASTER_DEVICE "master-device"
#define MM_MODEM_DRIVER "driver"
#define MM_MODEM_TYPE "type"
#define MM_MODEM_IP_METHOD "ip-method"
#define MM_MODEM_IP_TIMEOUT "ip-timeout"
#define MM_MODEM_ENABLED "enabled"
#define MM_MODEM_EQUIPMENT_IDENTIFIER "equipment-identifier"
#define MM_MODEM_DEVICE_IDENTIFIER "device-identifier"
#define MM_MODEM_UNLOCK_REQUIRED "unlock-required"
#define MM_MODEM_UNLOCK_RETRIES "unlock-retries"
#define MM_MODEM_PIN_RETRY_COUNTS "pin-retry-counts"
#define MM_MODEM_VALID "valid" /* not exported */
#define MM_MODEM_PLUGIN "plugin" /* not exported */
#define MM_MODEM_STATE "state" /* not exported */
#define MM_MODEM_HW_VID "hw-vid" /* not exported */
#define MM_MODEM_HW_PID "hw-pid" /* not exported */
#define MM_MODEM_UNLOCK_RETRIES_NOT_SUPPORTED 999
typedef enum {
MM_MODEM_PROP_FIRST = 0x1000,
MM_MODEM_PROP_DATA_DEVICE = MM_MODEM_PROP_FIRST,
MM_MODEM_PROP_MASTER_DEVICE,
MM_MODEM_PROP_DRIVER,
MM_MODEM_PROP_TYPE,
MM_MODEM_PROP_IP_METHOD,
MM_MODEM_PROP_VALID, /* Not exported */
MM_MODEM_PROP_PLUGIN, /* Not exported */
MM_MODEM_PROP_STATE, /* Not exported */
MM_MODEM_PROP_ENABLED,
MM_MODEM_PROP_EQUIPMENT_IDENTIFIER,
MM_MODEM_PROP_UNLOCK_REQUIRED,
MM_MODEM_PROP_UNLOCK_RETRIES,
MM_MODEM_PROP_PIN_RETRY_COUNTS,
MM_MODEM_PROP_DEVICE_IDENTIFIER,
MM_MODEM_PROP_HW_VID, /* Not exported */
MM_MODEM_PROP_HW_PID, /* Not exported */
MM_MODEM_PROP_NETWORK_TIMEZONE,
MM_MODEM_PROP_IP_TIMEOUT
} MMModemProp;
typedef struct _MMModem MMModem;
typedef void (*MMModemFn) (MMModem *modem,
GError *error,
gpointer user_data);
typedef void (*MMModemUIntFn) (MMModem *modem,
guint32 result,
GError *error,
gpointer user_data);
typedef void (*MMModemStringFn) (MMModem *modem,
const char *result,
GError *error,
gpointer user_data);
typedef void (*MMModemIp4Fn) (MMModem *modem,
guint32 address,
GArray *dns,
GError *error,
gpointer user_data);
typedef void (*MMModemInfoFn) (MMModem *modem,
const char *manufacturer,
const char *model,
const char *version,
GError *error,
gpointer user_data);
typedef void (*MMModemArrayFn) (MMModem *modem,
GArray *items,
GError *error,
gpointer user_data);
struct _MMModem {
GTypeInterface g_iface;
/* Methods */
gboolean (*owns_port) (MMModem *self,
const char *subsys,
const char *name);
/* Subclasses use this function to claim a particular port */
gboolean (*grab_port) (MMModem *self,
const char *subsys,
const char *name,
MMPortType ptype,
MMAtPortFlags at_pflags,
gpointer user_data,
GError **error);
/* Subclasses use this function to determine which of their
* grabbed ports should be used for data, command and status,
* PPP, etc. Called after all ports have been detected and
* grabbed by the modem.
*/
gboolean (*organize_ports) (MMModem *self,
GError **error);
void (*release_port) (MMModem *self,
const char *subsys,
const char *name);
void (*enable) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*disable) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*connect) (MMModem *self,
const char *number,
MMModemFn callback,
gpointer user_data);
void (*get_ip4_config) (MMModem *self,
MMModemIp4Fn callback,
gpointer user_data);
void (*disconnect) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*get_info) (MMModem *self,
MMModemInfoFn callback,
gpointer user_data);
void (*get_supported_charsets) (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_charset) (MMModem *self,
MMModemCharset charset,
MMModemFn callback,
gpointer user_data);
/* Normally implemented by the modem base class; plugins should
* never need to implement this.
*/
gboolean (*auth_request) (MMModem *self,
const char *authorization,
DBusGMethodInvocation *context,
MMAuthRequestCb callback,
gpointer callback_data,
GDestroyNotify notify,
GError **error);
gboolean (*auth_finish) (MMModem *self,
MMAuthRequest *req,
GError **error);
void (*reset) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*factory_reset) (MMModem *self,
const char *code,
MMModemFn callback,
gpointer user_data);
/* Signals */
void (*state_changed) (MMModem *self,
MMModemState old_state,
MMModemState new_state,
MMModemStateReason reason);
};
GType mm_modem_get_type (void);
gboolean mm_modem_owns_port (MMModem *self,
const char *subsys,
const char *name);
gboolean mm_modem_grab_port (MMModem *self,
const char *subsys,
const char *name,
MMPortType ptype,
MMAtPortFlags at_pflags,
gpointer user_data,
GError **error);
gboolean mm_modem_organize_ports (MMModem *self,
GError **error);
void mm_modem_release_port (MMModem *self,
const char *subsys,
const char *name);
void mm_modem_enable (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_disable (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_connect (MMModem *self,
const char *number,
MMModemFn callback,
gpointer user_data);
void mm_modem_get_ip4_config (MMModem *self,
MMModemIp4Fn callback,
gpointer user_data);
void mm_modem_disconnect (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_get_info (MMModem *self,
MMModemInfoFn callback,
gpointer user_data);
void mm_modem_get_supported_charsets (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_set_charset (MMModem *self,
MMModemCharset charset,
MMModemFn callback,
gpointer user_data);
void mm_modem_reset (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_factory_reset (MMModem *self,
const char *code,
MMModemFn callback,
gpointer user_data);
gboolean mm_modem_get_valid (MMModem *self);
char *mm_modem_get_device (MMModem *self);
MMModemState mm_modem_get_state (MMModem *self);
void mm_modem_set_state (MMModem *self,
MMModemState new_state,
MMModemStateReason reason);
/* Request authorization to perform an action. Used by D-Bus method
* handlers to ensure that the incoming request is authorized to perform
* the action it's requesting.
*/
gboolean mm_modem_auth_request (MMModem *self,
const char *authorization,
DBusGMethodInvocation *context,
MMAuthRequestCb callback,
gpointer callback_data,
GDestroyNotify notify,
GError **error);
gboolean mm_modem_auth_finish (MMModem *self,
MMAuthRequest *req,
GError **error);
#endif /* MM_MODEM_H */

View File

@@ -1,352 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2008 - 2010 Red Hat, Inc.
*/
#include <string.h>
#include <stdio.h>
#include <dbus/dbus-glib.h>
#include "mm-marshal.h"
#include "mm-properties-changed-signal.h"
#include "mm-properties-changed-glue.h"
#include "mm-log.h"
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#define DBUS_TYPE_G_ARRAY_OF_STRING (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING))
#define MM_PC_SIGNAL_NAME "mm-properties-changed"
#define DBUS_PC_SIGNAL_NAME "properties-changed"
#define MM_DBUS_PROPERTY_CHANGED "MM_DBUS_PROPERTY_CHANGED"
/*****************************************************************************/
typedef struct {
char *real_property;
char *interface;
} ChangeInfo;
typedef struct {
/* Whitelist of GObject property names for which changes will be emitted
* over the bus.
*
* Mapping of {property-name -> ChangeInfo}
*/
GHashTable *registered;
/* Table of each D-Bus interface of the object for which one or more
* properties have changed, and those properties and their new values.
* Destroyed after the changed signal has been sent.
*
* Mapping of {dbus-interface -> {property-name -> value}}
*/
GHashTable *hash;
guint idle_id;
} PropertiesChangedInfo;
static void
destroy_value (gpointer data)
{
GValue *val = (GValue *) data;
g_value_unset (val);
g_slice_free (GValue, val);
}
static void
change_info_free (gpointer data)
{
ChangeInfo *info = data;
g_free (info->real_property);
g_free (info->interface);
memset (info, 0, sizeof (ChangeInfo));
g_free (info);
}
static PropertiesChangedInfo *
properties_changed_info_new (void)
{
PropertiesChangedInfo *info;
info = g_slice_new0 (PropertiesChangedInfo);
info->registered = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, change_info_free);
info->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_hash_table_destroy);
return info;
}
static void
properties_changed_info_destroy (gpointer data)
{
PropertiesChangedInfo *info = (PropertiesChangedInfo *) data;
if (info->idle_id)
g_source_remove (info->idle_id);
g_hash_table_destroy (info->hash);
g_hash_table_destroy (info->registered);
g_slice_free (PropertiesChangedInfo, info);
}
#ifdef DEBUG
static void
add_to_string (gpointer key, gpointer value, gpointer user_data)
{
char *buf = (char *) user_data;
GValue str_val = { 0, };
g_value_init (&str_val, G_TYPE_STRING);
if (!g_value_transform ((GValue *) value, &str_val)) {
if (G_VALUE_HOLDS_OBJECT (value)) {
GObject *obj = g_value_get_object (value);
if (g_value_get_object (value)) {
sprintf (buf + strlen (buf), "{%s: %p (%s)}, ",
(const char *) key, obj, G_OBJECT_TYPE_NAME (obj));
} else {
sprintf (buf + strlen (buf), "{%s: %p}, ", (const char *) key, obj);
}
} else
sprintf (buf + strlen (buf), "{%s: <transform error>}, ", (const char *) key);
} else {
sprintf (buf + strlen (buf), "{%s: %s}, ", (const char *) key, g_value_get_string (&str_val));
}
g_value_unset (&str_val);
}
#endif
static gboolean
properties_changed (gpointer data)
{
GObject *object = G_OBJECT (data);
PropertiesChangedInfo *info;
GHashTableIter iter;
gpointer key, value;
info = (PropertiesChangedInfo *) g_object_get_data (object, MM_DBUS_PROPERTY_CHANGED);
g_assert (info);
g_hash_table_iter_init (&iter, info->hash);
while (g_hash_table_iter_next (&iter, &key, &value)) {
const char *interface = (const char *) key;
GHashTable *props = (GHashTable *) value;
GPtrArray *ignore = g_ptr_array_new ();
#ifdef DEBUG
{
char buf[2048] = { 0, };
g_hash_table_foreach (props, add_to_string, &buf);
mm_dbg ("%s: %s -> (%s) %s", __func__,
G_OBJECT_TYPE_NAME (object),
interface,
buf);
}
#endif
/* Send the PropertiesChanged signal */
g_signal_emit_by_name (object, MM_PC_SIGNAL_NAME, interface, props);
g_signal_emit_by_name (object, DBUS_PC_SIGNAL_NAME, interface, props, ignore);
g_ptr_array_free (ignore, TRUE);
}
g_hash_table_remove_all (info->hash);
return FALSE;
}
static void
idle_id_reset (gpointer data)
{
GObject *object = G_OBJECT (data);
PropertiesChangedInfo *info = (PropertiesChangedInfo *) g_object_get_data (object, MM_DBUS_PROPERTY_CHANGED);
/* info is unset when the object is being destroyed */
if (info)
info->idle_id = 0;
}
static char*
uscore_to_wincaps (const char *uscore)
{
const char *p;
GString *str;
gboolean last_was_uscore;
last_was_uscore = TRUE;
str = g_string_new (NULL);
p = uscore;
while (p && *p) {
if (*p == '-' || *p == '_')
last_was_uscore = TRUE;
else {
if (last_was_uscore) {
g_string_append_c (str, g_ascii_toupper (*p));
last_was_uscore = FALSE;
} else
g_string_append_c (str, *p);
}
++p;
}
return g_string_free (str, FALSE);
}
static PropertiesChangedInfo *
get_properties_changed_info (GObject *object)
{
PropertiesChangedInfo *info = NULL;
info = (PropertiesChangedInfo *) g_object_get_data (object, MM_DBUS_PROPERTY_CHANGED);
if (!info) {
info = properties_changed_info_new ();
g_object_set_data_full (object, MM_DBUS_PROPERTY_CHANGED, info, properties_changed_info_destroy);
}
g_assert (info);
return info;
}
static void
notify (GObject *object, GParamSpec *pspec)
{
GHashTable *interfaces;
PropertiesChangedInfo *info;
ChangeInfo *ch_info;
GValue *value;
info = get_properties_changed_info (object);
ch_info = g_hash_table_lookup (info->registered, pspec->name);
if (!ch_info)
return;
/* Check if there are other changed properties for this interface already,
* otherwise create a new hash table for all changed properties for this
* D-Bus interface.
*/
interfaces = g_hash_table_lookup (info->hash, ch_info->interface);
if (!interfaces) {
interfaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_value);
g_hash_table_insert (info->hash, g_strdup (ch_info->interface), interfaces);
}
/* Now put the changed property value into the hash table of changed values
* for its D-Bus interface.
*/
value = g_slice_new0 (GValue);
g_value_init (value, pspec->value_type);
g_object_get_property (object, pspec->name, value);
/* Use real property name, which takes shadow properties into accound */
g_hash_table_insert (interfaces, uscore_to_wincaps (ch_info->real_property), value);
if (!info->idle_id)
info->idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, properties_changed, object, idle_id_reset);
}
void
mm_properties_changed_signal_register_property (GObject *object,
const char *gobject_property,
const char *real_property,
const char *interface)
{
PropertiesChangedInfo *info;
ChangeInfo *ch_info;
/* All exported properties need to be registered explicitly for now since
* dbus-glib doesn't expose any method to find out the properties registered
* in the XML.
*/
info = get_properties_changed_info (object);
ch_info = g_hash_table_lookup (info->registered, gobject_property);
if (ch_info) {
g_warning ("%s: property '%s' already registerd on interface '%s'",
__func__, gobject_property, ch_info->interface);
} else {
ch_info = g_malloc0 (sizeof (ChangeInfo));
ch_info->real_property = g_strdup (real_property ? real_property : gobject_property);
ch_info->interface = g_strdup (interface);
g_hash_table_insert (info->registered, g_strdup (gobject_property), ch_info);
}
}
void
mm_properties_changed_signal_enable (GObjectClass *object_class)
{
object_class->notify = notify;
}
/*****************************************************************************/
static void
mm_properties_changed_init (gpointer g_iface)
{
static gboolean initialized = FALSE;
if (initialized)
return;
g_signal_new (MM_PC_SIGNAL_NAME,
G_TYPE_FROM_INTERFACE (g_iface),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
mm_marshal_VOID__STRING_BOXED,
G_TYPE_NONE, 2, G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT);
g_signal_new (DBUS_PC_SIGNAL_NAME,
G_TYPE_FROM_INTERFACE (g_iface),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
mm_marshal_VOID__STRING_BOXED_BOXED,
G_TYPE_NONE, 3,
G_TYPE_STRING,
DBUS_TYPE_G_MAP_OF_VARIANT,
DBUS_TYPE_G_ARRAY_OF_STRING);
initialized = TRUE;
}
GType
mm_properties_changed_get_type (void)
{
static GType pc_type = 0;
if (!G_UNLIKELY (pc_type)) {
const GTypeInfo pc_info = {
sizeof (MMPropertiesChanged), /* class_size */
mm_properties_changed_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
pc_type = g_type_register_static (G_TYPE_INTERFACE,
"MMPropertiesChanged",
&pc_info, 0);
g_type_interface_add_prerequisite (pc_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (pc_type, &dbus_glib_mm_properties_changed_object_info);
}
return pc_type;
}

View File

@@ -1,40 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2008 - 2010 Red Hat, Inc.
*/
#ifndef _MM_PROPERTIES_CHANGED_SIGNAL_H_
#define _MM_PROPERTIES_CHANGED_SIGNAL_H_
#include <glib-object.h>
#define MM_TYPE_PROPERTIES_CHANGED (mm_properties_changed_get_type ())
#define MM_PROPERTIES_CHANGED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PROPERTIES_CHANGED, MMPropertiesChanged))
#define MM_IS_PROPERTIES_CHANGED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PROPERTIES_CHANGED))
#define MM_PROPERTIES_CHANGED_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_PROPERTIES_CHANGED, MMPropertiesChanged))
typedef struct {
GTypeInterface g_iface;
} MMPropertiesChanged;
GType mm_properties_changed_get_type (void);
void mm_properties_changed_signal_enable (GObjectClass *object_class);
void mm_properties_changed_signal_register_property (GObject *object,
const char *gobject_property,
const char *real_property,
const char *interface);
#endif /* _MM_PROPERTIES_CHANGED_SIGNAL_H_ */

View File

@@ -1,795 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#include <ctype.h>
#include <string.h>
#include <glib.h>
#include <ModemManager.h>
#include <mm-errors-types.h>
#include "mm-charsets.h"
#include "mm-utils.h"
#include "mm-sms-utils.h"
#include "mm-log.h"
#include "dbus/dbus-glib.h"
#define SMS_TP_MTI_MASK 0x03
#define SMS_TP_MTI_SMS_DELIVER 0x00
#define SMS_TP_MTI_SMS_SUBMIT_REPORT 0x01
#define SMS_TP_MTI_SMS_STATUS_REPORT 0x02
#define SMS_NUMBER_TYPE_MASK 0x70
#define SMS_NUMBER_TYPE_UNKNOWN 0x00
#define SMS_NUMBER_TYPE_INTL 0x10
#define SMS_NUMBER_TYPE_ALPHA 0x50
#define SMS_NUMBER_PLAN_MASK 0x0f
#define SMS_NUMBER_PLAN_TELEPHONE 0x01
#define SMS_TP_MMS 0x04
#define SMS_TP_SRI 0x20
#define SMS_TP_UDHI 0x40
#define SMS_TP_RP 0x80
#define SMS_DCS_CODING_MASK 0xec
#define SMS_DCS_CODING_DEFAULT 0x00
#define SMS_DCS_CODING_8BIT 0x04
#define SMS_DCS_CODING_UCS2 0x08
#define SMS_DCS_CLASS_VALID 0x10
#define SMS_DCS_CLASS_MASK 0x03
#define SMS_TIMESTAMP_LEN 7
#define SMS_MIN_PDU_LEN (7 + SMS_TIMESTAMP_LEN)
typedef enum {
MM_SMS_ENCODING_UNKNOWN = 0x0,
MM_SMS_ENCODING_GSM7,
MM_SMS_ENCODING_8BIT,
MM_SMS_ENCODING_UCS2
} SmsEncoding;
static char sms_bcd_chars[] = "0123456789*#abc\0\0";
static void
sms_semi_octets_to_bcd_string (char *dest, const guint8 *octets, int num_octets)
{
int i;
for (i = 0 ; i < num_octets; i++) {
*dest++ = sms_bcd_chars[octets[i] & 0xf];
*dest++ = sms_bcd_chars[(octets[i] >> 4) & 0xf];
}
*dest++ = '\0';
}
static gboolean
char_to_bcd (char in, guint8 *out)
{
guint32 z;
if (isdigit (in)) {
*out = in - 0x30;
return TRUE;
}
for (z = 10; z < 16; z++) {
if (in == sms_bcd_chars[z]) {
*out = z;
return TRUE;
}
}
return FALSE;
}
static gsize
sms_string_to_bcd_semi_octets (guint8 *buf, gsize buflen, const char *string)
{
guint i;
guint8 bcd;
gsize addrlen, slen;
addrlen = slen = strlen (string);
if (addrlen % 2)
addrlen++;
g_return_val_if_fail (buflen >= addrlen, 0);
for (i = 0; i < addrlen; i += 2) {
if (!char_to_bcd (string[i], &bcd))
return 0;
buf[i / 2] = bcd & 0xF;
if (i >= slen - 1) {
/* PDU address gets padded with 0xF if string is odd length */
bcd = 0xF;
} else if (!char_to_bcd (string[i + 1], &bcd))
return 0;
buf[i / 2] |= bcd << 4;
}
return addrlen / 2;
}
/**
* sms_encode_address:
*
* @address: the phone number to encode
* @buf: the buffer to encode @address in
* @buflen: the size of @buf
* @is_smsc: if %TRUE encode size as number of octets of address infromation,
* otherwise if %FALSE encode size as number of digits of @address
*
* Returns: the size in bytes of the data added to @buf
**/
guint
sms_encode_address (const char *address,
guint8 *buf,
size_t buflen,
gboolean is_smsc)
{
gsize len;
g_return_val_if_fail (address != NULL, 0);
g_return_val_if_fail (buf != NULL, 0);
g_return_val_if_fail (buflen >= 2, 0);
/* Handle number type & plan */
buf[1] = 0x80; /* Bit 7 always 1 */
if (address[0] == '+') {
buf[1] |= SMS_NUMBER_TYPE_INTL;
address++;
}
buf[1] |= SMS_NUMBER_PLAN_TELEPHONE;
len = sms_string_to_bcd_semi_octets (&buf[2], buflen, address);
if (is_smsc)
buf[0] = len + 1; /* addr length + size byte */
else
buf[0] = strlen (address); /* number of digits in address */
return len ? len + 2 : 0; /* addr length + size byte + number type/plan */
}
/* len is in semi-octets */
static char *
sms_decode_address (const guint8 *address, int len)
{
guint8 addrtype, addrplan;
char *utf8;
addrtype = address[0] & SMS_NUMBER_TYPE_MASK;
addrplan = address[0] & SMS_NUMBER_PLAN_MASK;
address++;
if (addrtype == SMS_NUMBER_TYPE_ALPHA) {
guint8 *unpacked;
guint32 unpacked_len;
unpacked = gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len);
utf8 = (char *)mm_charset_gsm_unpacked_to_utf8 (unpacked,
unpacked_len);
g_free(unpacked);
} else if (addrtype == SMS_NUMBER_TYPE_INTL &&
addrplan == SMS_NUMBER_PLAN_TELEPHONE) {
/* International telphone number, format as "+1234567890" */
utf8 = g_malloc (len + 3); /* '+' + digits + possible trailing 0xf + NUL */
utf8[0] = '+';
sms_semi_octets_to_bcd_string (utf8 + 1, address, (len + 1) / 2);
} else {
/*
* All non-alphanumeric types and plans are just digits, but
* don't apply any special formatting if we don't know the
* format.
*/
utf8 = g_malloc (len + 2); /* digits + possible trailing 0xf + NUL */
sms_semi_octets_to_bcd_string (utf8, address, (len + 1) / 2);
}
return utf8;
}
static char *
sms_decode_timestamp (const guint8 *timestamp)
{
/* YYMMDDHHMMSS+ZZ */
char *timestr;
int quarters, hours;
timestr = g_malloc0 (16);
sms_semi_octets_to_bcd_string (timestr, timestamp, 6);
quarters = ((timestamp[6] & 0x7) * 10) + ((timestamp[6] >> 4) & 0xf);
hours = quarters / 4;
if (timestamp[6] & 0x08)
timestr[12] = '-';
else
timestr[12] = '+';
timestr[13] = (hours / 10) + '0';
timestr[14] = (hours % 10) + '0';
/* TODO(njw): Change timestamp rep to something that includes quarter-hours */
return timestr;
}
static SmsEncoding
sms_encoding_type (int dcs)
{
SmsEncoding scheme = MM_SMS_ENCODING_UNKNOWN;
switch ((dcs >> 4) & 0xf) {
/* General data coding group */
case 0: case 1:
case 2: case 3:
switch (dcs & 0x0c) {
case 0x08:
scheme = MM_SMS_ENCODING_UCS2;
break;
case 0x00:
/* fallthrough */
/* reserved - spec says to treat it as default alphabet */
case 0x0c:
scheme = MM_SMS_ENCODING_GSM7;
break;
case 0x04:
scheme = MM_SMS_ENCODING_8BIT;
break;
}
break;
/* Message waiting group (default alphabet) */
case 0xc:
case 0xd:
scheme = MM_SMS_ENCODING_GSM7;
break;
/* Message waiting group (UCS2 alphabet) */
case 0xe:
scheme = MM_SMS_ENCODING_UCS2;
break;
/* Data coding/message class group */
case 0xf:
switch (dcs & 0x04) {
case 0x00:
scheme = MM_SMS_ENCODING_GSM7;
break;
case 0x04:
scheme = MM_SMS_ENCODING_8BIT;
break;
}
break;
/* Reserved coding group values - spec says to treat it as default alphabet */
default:
scheme = MM_SMS_ENCODING_GSM7;
break;
}
return scheme;
}
static char *
sms_decode_text (const guint8 *text, int len, SmsEncoding encoding, int bit_offset)
{
char *utf8;
guint8 *unpacked;
guint32 unpacked_len;
if (encoding == MM_SMS_ENCODING_GSM7) {
unpacked = gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len);
utf8 = (char *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len);
g_free (unpacked);
} else if (encoding == MM_SMS_ENCODING_UCS2)
utf8 = g_convert ((char *) text, len, "UTF8", "UCS-2BE", NULL, NULL, NULL);
else {
g_warn_if_reached ();
utf8 = g_strdup ("");
}
return utf8;
}
static void
simple_free_gvalue (gpointer data)
{
g_value_unset ((GValue *) data);
g_slice_free (GValue, data);
}
static GValue *
simple_uint_value (guint32 i)
{
GValue *val;
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, i);
return val;
}
static GValue *
simple_string_value (const char *str)
{
GValue *val;
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, str);
return val;
}
static GValue *
byte_array_value (const GByteArray *array)
{
GValue *val;
val = g_slice_new0 (GValue);
g_value_init (val, DBUS_TYPE_G_UCHAR_ARRAY);
g_value_set_boxed (val, array);
return val;
}
GHashTable *
sms_properties_hash_new (const char *smsc,
const char *number,
const char *timestamp,
const char *text,
const GByteArray *data,
guint data_coding_scheme,
guint *class)
{
GHashTable *properties;
g_return_val_if_fail (number != NULL, NULL);
g_return_val_if_fail (text != NULL, NULL);
g_return_val_if_fail (data != NULL, NULL);
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, simple_free_gvalue);
g_hash_table_insert (properties, "number", simple_string_value (number));
g_hash_table_insert (properties, "data", byte_array_value (data));
g_hash_table_insert (properties, "data-coding-scheme", simple_uint_value (data_coding_scheme));
g_hash_table_insert (properties, "text", simple_string_value (text));
if (smsc)
g_hash_table_insert (properties, "smsc", simple_string_value (smsc));
if (timestamp)
g_hash_table_insert (properties, "timestamp", simple_string_value (timestamp));
if (class)
g_hash_table_insert (properties, "class", simple_uint_value (*class));
return properties;
}
GHashTable *
sms_parse_pdu (const char *hexpdu, GError **error)
{
GHashTable *properties;
gsize pdu_len;
guint8 *pdu;
guint smsc_addr_num_octets, variable_length_items, msg_start_offset,
sender_addr_num_digits, sender_addr_num_octets,
tp_pid_offset, tp_dcs_offset, user_data_offset, user_data_len,
user_data_len_offset, bit_offset;
char *smsc_addr, *sender_addr, *sc_timestamp, *msg_text;
SmsEncoding user_data_encoding;
GByteArray *pdu_data;
guint concat_ref = 0, concat_max = 0, concat_seq = 0, msg_class = 0;
gboolean multipart = FALSE, class_valid = FALSE;
/* Convert PDU from hex to binary */
pdu = (guint8 *) utils_hexstr2bin (hexpdu, &pdu_len);
if (!pdu) {
g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Couldn't parse PDU of SMS GET response from hex");
return NULL;
}
/* SMSC, in address format, precedes the TPDU */
smsc_addr_num_octets = pdu[0];
variable_length_items = smsc_addr_num_octets;
if (pdu_len < variable_length_items + SMS_MIN_PDU_LEN) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"PDU too short (1): %zd vs %d",
pdu_len,
variable_length_items + SMS_MIN_PDU_LEN);
g_free (pdu);
return NULL;
}
/* where in the PDU the actual SMS protocol message begins */
msg_start_offset = 1 + smsc_addr_num_octets;
sender_addr_num_digits = pdu[msg_start_offset + 1];
/*
* round the sender address length up to an even number of
* semi-octets, and thus an integral number of octets
*/
sender_addr_num_octets = (sender_addr_num_digits + 1) >> 1;
variable_length_items += sender_addr_num_octets;
if (pdu_len < variable_length_items + SMS_MIN_PDU_LEN) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"PDU too short (2): %zd vs %d",
pdu_len,
variable_length_items + SMS_MIN_PDU_LEN);
g_free (pdu);
return NULL;
}
tp_pid_offset = msg_start_offset + 3 + sender_addr_num_octets;
tp_dcs_offset = tp_pid_offset + 1;
user_data_len_offset = tp_dcs_offset + 1 + SMS_TIMESTAMP_LEN;
user_data_offset = user_data_len_offset + 1;
user_data_len = pdu[user_data_len_offset];
user_data_encoding = sms_encoding_type(pdu[tp_dcs_offset]);
if (user_data_encoding == MM_SMS_ENCODING_GSM7)
variable_length_items += (7 * (user_data_len + 1 )) / 8;
else
variable_length_items += user_data_len;
if (pdu_len < variable_length_items + SMS_MIN_PDU_LEN) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"PDU too short (3): %zd vs %d",
pdu_len,
variable_length_items + SMS_MIN_PDU_LEN);
g_free (pdu);
return NULL;
}
/* Only handle SMS-DELIVER */
if ((pdu[msg_start_offset] & SMS_TP_MTI_MASK) != SMS_TP_MTI_SMS_DELIVER) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Unhandled message type: 0x%02x",
pdu[msg_start_offset]);
g_free (pdu);
return NULL;
}
bit_offset = 0;
if (pdu[msg_start_offset] & SMS_TP_UDHI) {
int udhl, end, offset;
udhl = pdu[user_data_offset] + 1;
end = user_data_offset + udhl;
for (offset = user_data_offset + 1; offset < end;) {
guint8 ie_id, ie_len;
ie_id = pdu[offset++];
ie_len = pdu[offset++];
switch (ie_id) {
case 0x00:
/*
* Ignore the IE if one of the following is true:
* - it claims to be part 0 of M
* - it claims to be part N of M, N > M
*/
if (pdu[offset + 2] == 0 ||
pdu[offset + 2] > pdu[offset + 1])
break;
concat_ref = pdu[offset];
concat_max = pdu[offset + 1];
concat_seq = pdu[offset + 2];
multipart = TRUE;
break;
case 0x08:
/* Concatenated short message, 16-bit reference */
if (pdu[offset + 3] == 0 ||
pdu[offset + 3] > pdu[offset + 2])
break;
concat_ref = (pdu[offset] << 8) | pdu[offset + 1];
concat_max = pdu[offset + 2];
concat_seq = pdu[offset + 3];
multipart = TRUE;
break;
}
offset += ie_len;
}
/*
* Move past the user data headers to prevent it from being
* decoded into garbage text.
*/
user_data_offset += udhl;
if (user_data_encoding == MM_SMS_ENCODING_GSM7) {
/*
* Find the number of bits we need to add to the length of the
* user data to get a multiple of 7 (the padding).
*/
bit_offset = (7 - udhl % 7) % 7;
user_data_len -= (udhl * 8 + bit_offset) / 7;
} else
user_data_len -= udhl;
}
if ( user_data_encoding == MM_SMS_ENCODING_8BIT
|| user_data_encoding == MM_SMS_ENCODING_UNKNOWN) {
/* 8-bit encoding is usually binary data, and we have no idea what
* actual encoding the data is in so we can't convert it.
*/
msg_text = g_strdup ("");
} else {
/* Otherwise if it's 7-bit or UCS2 we can decode it */
msg_text = sms_decode_text (&pdu[user_data_offset], user_data_len,
user_data_encoding, bit_offset);
g_warn_if_fail (msg_text != NULL);
}
/* Raw PDU data */
pdu_data = g_byte_array_sized_new (user_data_len);
g_byte_array_append (pdu_data, &pdu[user_data_offset], user_data_len);
if (pdu[tp_dcs_offset] & SMS_DCS_CLASS_VALID) {
msg_class = pdu[tp_dcs_offset] & SMS_DCS_CLASS_MASK;
class_valid = TRUE;
}
smsc_addr = sms_decode_address (&pdu[1], 2 * (pdu[0] - 1));
sender_addr = sms_decode_address (&pdu[msg_start_offset + 2], pdu[msg_start_offset + 1]);
sc_timestamp = sms_decode_timestamp (&pdu[tp_dcs_offset + 1]);
properties = sms_properties_hash_new (smsc_addr,
sender_addr,
sc_timestamp,
msg_text,
pdu_data,
pdu[tp_dcs_offset] & 0xFF,
class_valid ? &msg_class : NULL);
g_assert (properties);
if (multipart) {
g_hash_table_insert (properties, "concat-reference", simple_uint_value (concat_ref));
g_hash_table_insert (properties, "concat-max", simple_uint_value (concat_max));
g_hash_table_insert (properties, "concat-sequence", simple_uint_value (concat_seq));
}
g_free (smsc_addr);
g_free (sender_addr);
g_free (sc_timestamp);
g_free (msg_text);
g_byte_array_free (pdu_data, TRUE);
g_free (pdu);
return properties;
}
static guint8
validity_to_relative (guint validity)
{
if (validity == 0)
return 167; /* 24 hours */
if (validity <= 720) {
/* 5 minute units up to 12 hours */
if (validity % 5)
validity += 5;
return (validity / 5) - 1;
}
if (validity > 720 && validity <= 1440) {
/* 12 hours + 30 minute units up to 1 day */
if (validity % 30)
validity += 30; /* round up to next 30 minutes */
validity = MIN (validity, 1440);
return 143 + ((validity - 720) / 30);
}
if (validity > 1440 && validity <= 43200) {
/* 2 days up to 1 month */
if (validity % 1440)
validity += 1440; /* round up to next day */
validity = MIN (validity, 43200);
return 167 + ((validity - 1440) / 1440);
}
/* 43200 = 30 days in minutes
* 10080 = 7 days in minutes
* 635040 = 63 weeks in minutes
* 40320 = 4 weeks in minutes
*/
if (validity > 43200 && validity <= 635040) {
/* 5 weeks up to 63 weeks */
if (validity % 10080)
validity += 10080; /* round up to next week */
validity = MIN (validity, 635040);
return 196 + ((validity - 40320) / 10080);
}
return 255; /* 63 weeks */
}
#define PDU_SIZE 200
/**
* sms_create_submit_pdu:
*
* @number: the subscriber number to send this message to
* @text: the body of this SMS
* @smsc: if given, the SMSC address
* @validity: minutes until the SMS should expire in the SMSC, or 0 for a
* suitable default
* @class: unused
* @out_pdulen: on success, the size of the returned PDU in bytes
* @out_msgstart: on success, the byte index in the returned PDU where the
* message starts (ie, skipping the SMSC length byte and address, if present)
* @error: on error, filled with the error that occurred
*
* Constructs a single-part SMS message with the given details, preferring to
* use the UCS2 character set when the message will fit, otherwise falling back
* to the GSM character set.
*
* Returns: the constructed PDU data on success, or %NULL on error
**/
guint8 *
sms_create_submit_pdu (const char *number,
const char *text,
const char *smsc,
guint validity,
guint class,
guint *out_pdulen,
guint *out_msgstart,
GError **error)
{
guint8 *pdu;
guint len, offset = 0;
MMModemCharset best_cs = MM_MODEM_CHARSET_GSM;
guint ucs2len = 0, gsm_unsupported = 0;
guint textlen = 0;
g_return_val_if_fail (number != NULL, NULL);
g_return_val_if_fail (text != NULL, NULL);
/* FIXME: support multiple fragments */
textlen = mm_charset_get_encoded_len (text, MM_MODEM_CHARSET_GSM, &gsm_unsupported);
if (textlen > 160) {
g_set_error_literal (error,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot encode message to fit into an SMS.");
return NULL;
}
/* If there are characters that are unsupported in the GSM charset, try
* UCS2. If the UCS2 encoded string is too long to fit in an SMS, then
* just use GSM and suck up the unconverted chars.
*/
if (gsm_unsupported > 0) {
ucs2len = mm_charset_get_encoded_len (text, MM_MODEM_CHARSET_UCS2, NULL);
if (ucs2len <= 140) {
best_cs = MM_MODEM_CHARSET_UCS2;
textlen = ucs2len;
}
}
/* Build up the PDU */
pdu = g_malloc0 (PDU_SIZE);
g_return_val_if_fail (pdu != NULL, NULL);
if (smsc) {
len = sms_encode_address (smsc, pdu, PDU_SIZE, TRUE);
if (len == 0) {
g_set_error (error,
MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER,
"Invalid SMSC address '%s'", smsc);
goto error;
}
offset += len;
} else {
/* No SMSC, use default */
pdu[offset++] = 0x00;
}
if (out_msgstart)
*out_msgstart = offset;
if (validity > 0)
pdu[offset] = 1 << 4; /* TP-VP present; format RELATIVE */
else
pdu[offset] = 0; /* TP-VP not present */
pdu[offset++] |= 0x01; /* TP-MTI = SMS-SUBMIT */
pdu[offset++] = 0x00; /* TP-Message-Reference: filled by device */
len = sms_encode_address (number, &pdu[offset], PDU_SIZE - offset, FALSE);
if (len == 0) {
g_set_error (error,
MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER,
"Invalid send-to number '%s'", number);
goto error;
}
offset += len;
/* TP-PID */
pdu[offset++] = 0x00;
/* TP-DCS */
if (best_cs == MM_MODEM_CHARSET_UCS2)
pdu[offset++] = 0x08;
else
pdu[offset++] = 0x00; /* GSM */
/* TP-Validity-Period: 4 days */
if (validity > 0)
pdu[offset++] = validity_to_relative (validity);
/* TP-User-Data-Length */
pdu[offset++] = textlen;
if (best_cs == MM_MODEM_CHARSET_GSM) {
guint8 *unpacked, *packed;
guint32 unlen = 0, packlen = 0;
unpacked = mm_charset_utf8_to_unpacked_gsm (text, &unlen);
if (!unpacked || unlen == 0) {
g_free (unpacked);
g_set_error_literal (error,
MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER,
"Failed to convert message text to GSM.");
goto error;
}
packed = gsm_pack (unpacked, unlen, 0, &packlen);
g_free (unpacked);
if (!packed || packlen == 0) {
g_free (packed);
g_set_error_literal (error,
MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER,
"Failed to pack message text to GSM.");
goto error;
}
memcpy (&pdu[offset], packed, packlen);
g_free (packed);
offset += packlen;
} else if (best_cs == MM_MODEM_CHARSET_UCS2) {
GByteArray *array;
array = g_byte_array_sized_new (textlen / 2);
if (!mm_modem_charset_byte_array_append (array, text, FALSE, best_cs)) {
g_byte_array_free (array, TRUE);
g_set_error_literal (error,
MM_MESSAGE_ERROR,
MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER,
"Failed to convert message text to UCS2.");
goto error;
}
memcpy (&pdu[offset], array->data, array->len);
offset += array->len;
g_byte_array_free (array, TRUE);
} else
g_assert_not_reached ();
if (out_pdulen)
*out_pdulen = offset;
return pdu;
error:
g_free (pdu);
return NULL;
}

View File

@@ -1,49 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2010 Red Hat, Inc.
*/
#ifndef MM_SMS_UTILS_H
#define MM_SMS_UTILS_H
#include <glib.h>
#define SMS_MAX_PDU_LEN 344
GHashTable *sms_parse_pdu (const char *hexpdu, GError **error);
guint8 *sms_create_submit_pdu (const char *number,
const char *text,
const char *smsc,
guint validity,
guint class,
guint *out_pdulen,
guint *out_msgstart,
GError **error);
GHashTable *sms_properties_hash_new (const char *smsc,
const char *number,
const char *timestamp,
const char *text,
const GByteArray *data,
guint data_coding_scheme,
guint *class);
/* For testcases only */
guint sms_encode_address (const char *address,
guint8 *buf,
size_t buflen,
gboolean is_smsc);
#endif /* MM_SMS_UTILS_H */