2 * gsm - gsm resource for zavai
4 * Copyright (C) 2009--2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 [DBus (name = "org.freesmartphone.GSM.Device")]
27 public interface FSO_GSM_Device : Object {
28 public abstract async int test_int (int i, out int j) throws DBus.Error;
29 public abstract async string test_string (string s, out string t) throws DBus.Error;
30 public abstract async void set_sim_buffers_sms(bool sim_buffers_sms) throws DBus.Error;
31 public abstract async void set_r_t_c() throws DBus.Error;
32 public abstract async void cancel_command() throws DBus.Error;
33 public abstract async void set_antenna_power(bool power) throws DBus.Error;
34 public abstract async GLib.HashTable<string, GLib.Value?> get_info() throws DBus.Error;
35 public abstract async void set_microphone_muted(bool muted) throws DBus.Error;
36 public signal void keypad_event(string name, bool pressed);
37 public abstract async int get_speaker_volume() throws DBus.Error;
38 public abstract async int get_r_t_c() throws DBus.Error;
39 public abstract async void set_speaker_volume(int modem_volume) throws DBus.Error;
40 public abstract async GLib.HashTable<string, GLib.Value?> get_features() throws DBus.Error;
41 public abstract async bool get_microphone_muted() throws DBus.Error;
42 public abstract async bool get_antenna_power() throws DBus.Error;
43 public abstract async void get_power_status(out string param0, out int param1) throws DBus.Error;
44 public abstract async bool get_sim_buffers_sms() throws DBus.Error;
47 [DBus (name = "org.freesmartphone.GSM.SIM")]
48 public interface FSO_GSM_SIM : GLib.Object {
49 //public abstract async SIMParam0Struct[] retrieve_phonebook(string category) throws DBus.Error;
50 public abstract async void send_auth_code(string code) throws DBus.Error;
51 public abstract async string get_issuer() throws DBus.Error;
52 public abstract async void change_auth_code(string old_pin, string new_pin) throws DBus.Error;
53 public signal void auth_status(string status);
54 public abstract async string send_generic_sim_command(string command) throws DBus.Error;
55 public abstract async string[] list_phonebooks() throws DBus.Error;
56 public abstract async void set_service_center_number(string number) throws DBus.Error;
57 public abstract async GLib.HashTable<string, string> get_provider_list() throws DBus.Error;
58 //public abstract async SIMParam0Struct2[] get_home_zones() throws DBus.Error;
59 public signal void ready_status(bool status);
60 public abstract async void retrieve_entry(string category, int index, out string param0, out string param1) throws DBus.Error;
61 public abstract async void delete_message(int index) throws DBus.Error;
62 public abstract async void send_restricted_sim_command(int command, int fileid, int p1, int p2, int p3, string data, out int param0, out int param1, out string param2) throws DBus.Error;
63 public abstract async GLib.HashTable<string, GLib.Value?> get_messagebook_info() throws DBus.Error;
64 public abstract async bool get_sim_ready() throws DBus.Error;
65 public abstract async GLib.HashTable<string, GLib.Value?> get_phonebook_info(string category) throws DBus.Error;
66 public signal void memory_full();
67 public abstract async GLib.HashTable<string, GLib.Value?> get_sim_info() throws DBus.Error;
68 public abstract async void set_auth_code_required(bool required, string pin) throws DBus.Error;
69 public abstract async string get_auth_status() throws DBus.Error;
70 public abstract async void send_stored_message(int index, out int param0, out string param1) throws DBus.Error;
71 public abstract async int store_message(string number, string contents, GLib.HashTable<string, GLib.Value?> properties) throws DBus.Error;
72 public abstract async bool get_auth_code_required() throws DBus.Error;
73 public signal void incoming_stored_message(int index);
74 public abstract async void retrieve_message(int index, out string param0, out string param1, out string param2, out GLib.HashTable<string, GLib.Value?> param3) throws DBus.Error;
75 public abstract async void store_entry(string category, int index, string name, string number) throws DBus.Error;
76 public abstract async void unlock(string puk, string new_pin) throws DBus.Error;
77 public abstract async string get_service_center_number() throws DBus.Error;
78 //public abstract async SIMParam0Struct23[] retrieve_messagebook(string category) throws DBus.Error;
79 public abstract async void delete_entry(string category, int index) throws DBus.Error;
82 [DBus (name = "org.freesmartphone.GSM.Network")]
83 public interface FSO_GSM_Network : GLib.Object {
84 public signal void status(GLib.HashTable<string, GLib.Value?> status);
85 public signal void signal_strength(int strength);
86 //public abstract async NetworkParam0Struct[] list_providers() throws DBus.Error;
87 public abstract async GLib.HashTable<string, GLib.Value?> get_call_forwarding(string reason) throws DBus.Error;
88 public signal void time_zone_report(int timezone);
89 public abstract async void unregister() throws DBus.Error;
90 public abstract async void set_calling_identification(string status) throws DBus.Error;
91 public abstract async void register_() throws DBus.Error;
92 public abstract async void send_ussd_request(string request) throws DBus.Error;
93 public abstract async void disable_call_forwarding(string reason, string class_) throws DBus.Error;
94 public signal void incoming_ussd(string mode, string message_);
95 public abstract async int get_signal_strength() throws DBus.Error;
96 public abstract async void enable_call_forwarding(string reason, string class_, string number, int timeout) throws DBus.Error;
97 public abstract async string get_calling_identification() throws DBus.Error;
98 public abstract async void register_with_provider(string operator_code) throws DBus.Error;
99 public signal void cipher_status(string gsm, string gprs);
100 public abstract async GLib.HashTable<string, GLib.Value?> get_status() throws DBus.Error;
101 public abstract async void get_country_code(out string param0, out string param1) throws DBus.Error;
104 // Isolate here the insane loops we need to go through to turn on the bloody
106 protected class GSMActivator : Object
108 public FSO_GSM_Device device;
109 public FSO_GSM_Network network;
110 public FSO_GSM_SIM sim;
112 public signal void status_changed(string message);
114 public GSMActivator()
121 public async void start()
125 device = (FSO_GSM_Device)zavai.registry.sbus.get_object(
126 "org.freesmartphone.ogsmd",
127 "/org/freesmartphone/GSM/Device",
128 "org.freesmartphone.GSM.Device");
129 network = (FSO_GSM_Network)zavai.registry.sbus.get_object(
130 "org.freesmartphone.ogsmd",
131 "/org/freesmartphone/GSM/Device",
132 "org.freesmartphone.GSM.Network");
133 sim = (FSO_GSM_SIM)zavai.registry.sbus.get_object(
134 "org.freesmartphone.ogsmd",
135 "/org/freesmartphone/GSM/Device",
136 "org.freesmartphone.GSM.SIM");
139 status_changed("Turning on antenna");
143 yield device.set_antenna_power(true);
146 zavai.log.warning("SetAntennaPower: " + e.message);
147 if (e.message.str("current status is 'enabling'") != null
148 || e.message.str("current status is 'unknown'") != null)
150 status_changed("Waiting for ogsmd to settle");
151 zavai.log.info("trying again after 2 seconds");
152 Timeout.add(2 * 1000, () => {
158 status_changed("Checking if PIN is required");
159 string status = yield sim.get_auth_status();
160 zavai.log.info("on_auth_status: " + status);
161 if (status == "READY")
162 status_changed("PIN ok");
163 else if (status == "SIM PIN")
165 status_changed("Sending PIN");
166 yield sim.send_auth_code(zavai.config.sim_pin);
167 status_changed("PIN OK");
170 zavai.log.debug("Unknown status: " + status);
174 zavai.log.warning("on_antenna_power ok");
175 status_changed("Registering with network");
176 yield network.register_();
177 status_changed("Registered with network");
181 public class GSM: zavai.ScriptMonitorService
183 protected dynamic DBus.Object dbus;
184 public dynamic DBus.Object call;
185 protected GSMActivator activator;
187 public signal void status_changed(string message);
193 activator = new GSMActivator();
194 activator.status_changed += (msg) => { status_changed(msg); };
198 dbus = zavai.registry.sbus.get_object(
199 "org.freedesktop.DBus",
200 "/org/freedesktop/DBus",
201 "org.freedesktop.DBus");
202 dbus.NameOwnerChanged += on_name_owner_changed;
205 /// Request GPS resource
206 public override void start()
210 status_changed("Starting");
214 call = zavai.registry.sbus.get_object(
215 "org.freesmartphone.ogsmd",
216 "/org/freesmartphone/GSM/Device",
217 "org.freesmartphone.GSM.Call");
222 protected void on_name_owner_changed(DBus.Object sender, string name, string oldOwner, string newOwner)
224 zavai.log.debug("NOC " + name + " from " + oldOwner + " to " + newOwner);
225 if (name == "org.freesmartphone.ogsmd" && newOwner != "")
227 status_changed("ogpsd came online");
228 activator.start.begin();
232 // Release usage of GPS
233 public override void stop()
235 if (!started) return;
240 protected override void cleanup_after_script_stop()
246 public class GPRS: zavai.Service
248 public dynamic DBus.Object device;
252 Object(name: "gsm.gprs");
254 device = zavai.registry.sbus.get_object(
255 "org.freesmartphone.ogsmd",
256 "/org/freesmartphone/GSM/Device",
257 "org.freesmartphone.GSM.PDP");
260 /// Request GPS resource
261 public override void start()
266 device.ActivateContext(
267 zavai.config.gprs_apn,
268 zavai.config.gprs_user,
269 zavai.config.gprs_pass);
270 zavai.log.info("Started GPRS");
272 } catch (GLib.Error e) {
273 zavai.log.error(e.message);
278 // Release usage of GPS
279 public override void stop()
281 if (!started) return;
284 device.DeactivateContext();
285 zavai.log.info("Stopped GPRS");
287 } catch (GLib.Error e) {
288 zavai.log.error(e.message);
294 public zavai.gsm.GSM gsm = null;
295 public zavai.gsm.GPRS gprs = null;