Desktop
/* $Id: gsm.c,v 1.173.2.2 2011/01/20 01:37:58 khorben Exp $ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Phone */
/* 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, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#ifdef DEBUG
# include <stdio.h>
#endif
#include <string.h>
#include <System.h>
#include "gsm.h"
/* GSM */
/* private */
/* types */
typedef int (*GSMTriggerCallback)(GSM * gsm, char const * result,
gboolean * answered);
typedef struct _GSMTrigger
{
char const * trigger;
size_t trigger_cnt;
GSMTriggerCallback callback;
} GSMTrigger;
struct _GSM
{
Modem * modem;
};
/* functions */
/* gsm_new */
GSM * gsm_new(char const * device, unsigned int baudrate, unsigned int hwflow)
{
GSM * gsm;
if((gsm = object_new(sizeof(*gsm))) == NULL)
return NULL;
gsm->modem = modem_new("hayes", NULL, NULL); /* XXX user-defined */
if(gsm->modem == NULL)
{
gsm_delete(gsm);
return NULL;
}
return gsm;
}
/* gsm_delete */
void gsm_delete(GSM * gsm)
{
if(gsm->modem != NULL)
modem_delete(gsm->modem);
object_delete(gsm);
}
/* accessors */
/* gsm_set_callback */
void gsm_set_callback(GSM * gsm, ModemEventCallback callback, void * priv)
{
modem_set_callback(gsm->modem, callback, priv);
}
/* gsm_set_call_presentation */
int gsm_set_call_presentation(GSM * gsm, int set)
{
return modem_set(gsm->modem, MODEM_REQUEST_CALL_PRESENTATION,
(set != 0) ? TRUE : FALSE);
}
/* gsm_set_call_waiting_control */
int gsm_set_call_waiting_control(GSM * gsm, int unsollicited)
{
return modem_set(gsm->modem, MODEM_REQUEST_CALL_WAITING_CONTROL,
(unsollicited != 0) ? TRUE : FALSE);
}
/* gsm_set_line_presentation */
int gsm_set_line_presentation(GSM * gsm, int set)
{
return modem_set(gsm->modem, MODEM_REQUEST_LINE_PRESENTATION,
(set != 0) ? TRUE : FALSE);
}
/* gsm_set_message_indications */
int gsm_set_message_indications(GSM * gsm, GSMMessageMode mode,
int unsollicited)
{
return modem_set(gsm->modem, MODEM_REQUEST_MESSAGE_INDICATIONS, mode,
(unsollicited != 0) ? TRUE : FALSE);
}
/* gsm_set_operator_format */
int gsm_set_operator_format(GSM * gsm, GSMOperatorFormat format)
{
return modem_set(gsm->modem, MODEM_REQUEST_OPERATOR_FORMAT, format);
}
/* gsm_set_operator_mode */
int gsm_set_operator_mode(GSM * gsm, GSMOperatorMode mode)
{
return modem_set(gsm->modem, MODEM_REQUEST_OPERATOR_MODE, mode);
}
/* gsm_set_registration_report */
int gsm_set_registration_report(GSM * gsm, GSMRegistrationReport report)
{
return modem_set(gsm->modem, MODEM_REQUEST_REGISTRATION_REPORT, report);
}
/* gsm_set_retry */
int gsm_set_retry(GSM * gsm, unsigned int retry)
{
/* FIXME implement */
return -1;
}
/* gsm_set_supplementary_service_notifications */
int gsm_set_supplementary_service_notifications(GSM * gsm, int intermediate,
int unsollicited)
{
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%s, %s)\n", __func__, (intermediate != 0)
? "TRUE" : "FALSE", (unsollicited != 0) ? "TRUE"
: "FALSE");
#endif
return modem_set(gsm->modem,
MODEM_REQUEST_SUPPLEMENTARY_SERVICE_NOTIFICATIONS,
(intermediate != 0) ? TRUE : FALSE,
(unsollicited != 0) ? TRUE : FALSE);
}
/* useful */
/* gsm_call */
int gsm_call(GSM * gsm, GSMCallType calltype, char const * number)
{
if(number == NULL)
return modem_set(gsm->modem, MODEM_REQUEST_CALL_LAST, calltype);
/* FIXME if the number is not valid try from the address book */
return modem_set(gsm->modem, MODEM_REQUEST_CALL, calltype, number);
}
/* gsm_call_answer */
int gsm_call_answer(GSM * gsm)
{
return modem_set(gsm->modem, MODEM_REQUEST_CALL_ANSWER);
}
/* gsm_call_contact */
int gsm_call_contact(GSM * gsm, GSMCallType calltype, unsigned int index)
{
return modem_set(gsm->modem, MODEM_REQUEST_CALL_CONTACT, calltype,
index);
}
/* gsm_call_hangup */
int gsm_call_hangup(GSM * gsm)
{
return modem_set(gsm->modem, MODEM_REQUEST_CALL_HANGUP);
}
/* gsm_contact_delete */
int gsm_contact_delete(GSM * gsm, unsigned int index)
{
return modem_set(gsm->modem, MODEM_REQUEST_CONTACT_DELETE, index);
}
/* gsm_contact_edit */
int gsm_contact_edit(GSM * gsm, unsigned int index, char const * name,
char const * number)
{
return modem_set(gsm->modem, MODEM_REQUEST_CONTACT_EDIT, index, name,
number);
}
/* gsm_contact_new */
int gsm_contact_new(GSM * gsm, char const * name, char const * number)
{
return modem_set(gsm->modem, MODEM_REQUEST_CONTACT_NEW, name, number);
}
/* gsm_enter_sim_pin */
int gsm_enter_sim_pin(GSM * gsm, char const * code)
{
if(code == NULL)
return modem_get(gsm->modem, MODEM_REQUEST_PIN_VALID);
return modem_set(gsm->modem, MODEM_REQUEST_ENTER_SIM_PIN, code);
}
/* gsm_fetch_battery_charge */
int gsm_fetch_battery_charge(GSM * gsm)
{
return modem_trigger(gsm->modem, MODEM_EVENT_TYPE_BATTERY_LEVEL);
}
/* gsm_fetch_contact_list */
int gsm_fetch_contact_list(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_CONTACT_LIST);
}
/* gsm_fetch_contacts */
int gsm_fetch_contacts(GSM * gsm, unsigned int start, unsigned int end)
{
return modem_set(gsm->modem, MODEM_REQUEST_GET_CONTACTS, start, end);
}
/* gsm_fetch_message_list */
int gsm_fetch_message_list(GSM * gsm, GSMMessageList list)
{
return modem_set(gsm->modem, MODEM_REQUEST_GET_MESSAGE_LIST, list);
}
/* gsm_fetch_message */
int gsm_fetch_message(GSM * gsm, unsigned int index)
{
return modem_set(gsm->modem, MODEM_REQUEST_GET_MESSAGE, index);
}
/* gsm_fetch_operator */
int gsm_fetch_operator(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_OPERATOR);
}
/* gsm_fetch_registration */
int gsm_fetch_registration(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_REGISTRATION);
}
/* gsm_fetch_signal_level */
int gsm_fetch_signal_level(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_SIGNAL_LEVEL);
}
/* queries */
/* gsm_is_call_waiting_control */
int gsm_is_call_waiting_control(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_CALL_WAITING_CONTROL);
}
/* gsm_is_gprs_attached */
/* FIXME this call is useless (cf registration media) */
int gsm_is_gprs_attached(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_GPRS_ATTACHED);
}
/* gsm_is_pin_needed */
int gsm_is_pin_needed(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_ENTER_SIM_PIN);
}
/* gsm_is_pin_valid */
int gsm_is_pin_valid(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_PIN_VALID);
}
/* gsm_is_registered */
int gsm_is_registered(GSM * gsm)
{
return modem_get(gsm->modem, MODEM_REQUEST_REGISTRATION);
}
/* messaging */
/* gsm_message_delete */
int gsm_message_delete(GSM * gsm, unsigned int index)
{
return modem_set(gsm->modem, MODEM_REQUEST_MESSAGE_DELETE, index);
}
/* gsm_message_send */
int gsm_message_send(GSM * gsm, char const * number, GSMEncoding encoding,
char const * text, size_t length)
{
return 1; /* should not be reached */
}
/* queue management */
/* gsm_queue */
GSMCommand * gsm_queue(GSM * gsm, char const * command)
{
return NULL;
}
/* gsm_start */
int gsm_start(GSM * gsm, unsigned int delay)
{
return modem_start(gsm->modem);
}
/* gsm_stop */
int gsm_stop(GSM * gsm)
{
return modem_stop(gsm->modem);
}
/* gsm_trigger */
int gsm_trigger(GSM * gsm, ModemEventType event)
{
return modem_trigger(gsm->modem, event);
}
/* private */
/* functions */