Hiya, Nokia, being the Kings of Open Source that they are, won't release the headers for libconnui - the library used by the Phone Control Panel applet to perform this stuff.
However, libconnui is a wrapper around DBus-GLib/Mission Control etc. Graham Cobb produced a brilliant Wiki page on working out the D-Bus method calls: https://garage.maemo.org/plugins/wiki/index.php?Tools&id=1106&type=g I've attached three DBus-GLib examples which I believe should be enough for you to perform what you asked for. I'm not sure what all the values represent so... maybe looking at www.bleb.org/software/maemo/telephony-maemo.c and http://repository.maemo.org/extras-devel/pool/fremantle/free/source/n/netmon/ will help. One will print a list of the available networks around you; this is done in the way the CPA does it. One will tell you the current Network Selection mode (Manual/Automatic); the current cell information; and operator name. The other will set the mode into automatic or manual (hardcoded for my provider, T-Mobile UK). Best regards, Faheem On 24 May 2010 12:20, Filip-Martin Brinkmann <filip.brinkm...@gmail.com> wrote: > Hi guys, > > I'm trying to write a small widget that allows to switch back to a > defined GSM provider. Point is, I'm commuting everyday to switzerland > and back to germany the same day. When I reach covering area of my > german provider, the N900 won't switch back unless I go to > settings->phone->search and switch to "manual search" etc... > I therefore wanted to shortcut this. However, after browser all possible > documentation, I still have no clue where to search - what API can I > use? Or is there no such possibility at all? > > I'd be very grateful for someone pointing me in the right direction. > > best, > > filip > > _______________________________________________ > maemo-developers mailing list > maemo-developers@maemo.org > https://lists.maemo.org/mailman/listinfo/maemo-developers > >
/* gcc get_networks.c -Wall `pkg-config --cflags --libs dbus-glib-1 gthread-2.0` */ #include <stdlib.h> #include <glib.h> #include <glib/gprintf.h> #include <dbus/dbus-glib.h> #define PHONE_SERVICE "com.nokia.phone.net" #define PHONE_PATH "/com/nokia/phone/net" #define PHONE_IFACE "Phone.Net" #define GET_NETWORK_SEL_MODE "get_network_selection_mode" #define GET_AVAILABLE_NETWORK "get_available_network" #define CANCEL_GET_AVAILABLE_NETWORK "cancel_get_available_network" #define TIMEOUT 666666 /* Beelzebub sends his regards. Twice. */ static GMainLoop *loop = NULL; static DBusGProxy *PhoneNet_proxy = NULL; static DBusGProxyCall *get_networks = NULL; static gboolean scan_in_progress = FALSE; static void sig_handler (int sig G_GNUC_UNUSED) { if (scan_in_progress) { dbus_g_proxy_cancel_call (PhoneNet_proxy, get_networks); dbus_g_proxy_call_no_reply (PhoneNet_proxy, CANCEL_GET_AVAILABLE_NETWORK, G_TYPE_INVALID); } if (g_main_loop_is_running (loop)) g_main_loop_quit (loop); } static void on_list_recieved (DBusGProxy *proxy G_GNUC_UNUSED, DBusGProxyCall *call G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED) { GArray *unk_value1; gchar **MNCs, **MNCs_ptr; gchar **MCCs, **MCCs_ptr; gchar **operators, **operators_ptr; GArray *unk_value3; GArray *unk_value4; gint32 network_error; register guint i; scan_in_progress = FALSE; gboolean ret = dbus_g_proxy_end_call (PhoneNet_proxy, get_networks, NULL, DBUS_TYPE_G_UCHAR_ARRAY, &unk_value1, G_TYPE_STRV, &MNCs, G_TYPE_STRV, &MCCs, G_TYPE_STRV, &operators, DBUS_TYPE_G_UCHAR_ARRAY, &unk_value3, DBUS_TYPE_G_UCHAR_ARRAY, &unk_value4, G_TYPE_INT, &network_error, G_TYPE_INVALID); g_assert (ret); g_assert (network_error == 0); for (i = 0; i < unk_value1->len; i++) (void) g_printf ("%u\n", g_array_index (unk_value1, guchar, i)); (void) g_printf ("\n"); for (MNCs_ptr = MNCs; *MNCs_ptr; MNCs_ptr++) (void) g_printf ("%s\n", *MNCs_ptr); (void) g_printf ("\n"); for (MCCs_ptr = MCCs; *MCCs_ptr; MCCs_ptr++) (void) g_printf ("%s\n", *MCCs_ptr); (void) g_printf ("\n"); for (operators_ptr = MCCs; *operators_ptr; operators_ptr++) (void) g_printf ("%s\n", *operators_ptr); (void) g_printf ("\n"); for (i = 0; i < unk_value3->len; i++) (void) g_printf ("%u\n", g_array_index (unk_value3, guchar, i)); (void) g_printf ("\n"); for (i = 0; i < unk_value4->len; i++) (void) g_printf ("%u\n", g_array_index (unk_value4, guchar, i)); sig_handler (EXIT_SUCCESS); /* Lazy-ass way of exiting */ } static void start_network_scan (void) { get_networks = dbus_g_proxy_begin_call_with_timeout (PhoneNet_proxy, GET_AVAILABLE_NETWORK, (DBusGProxyCallNotify) on_list_recieved, NULL, NULL, TIMEOUT, G_TYPE_INVALID); g_assert (get_networks); scan_in_progress = TRUE; } int main (void) { GError *error = NULL; DBusGConnection *sys_conn = NULL; if (!g_thread_supported ()) { g_thread_init (NULL); dbus_g_thread_init (); } g_type_init (); loop = g_main_loop_new (NULL, FALSE); sys_conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!sys_conn) { g_printerr ("Failed to open connection to system bus: %s\n", error->message); g_clear_error (&error); return EXIT_FAILURE; } PhoneNet_proxy = dbus_g_proxy_new_for_name (sys_conn, PHONE_SERVICE, PHONE_PATH, PHONE_IFACE); if (!PhoneNet_proxy) { g_printerr ("%s\n", "Failed to create "PHONE_SERVICE" proxy"); return EXIT_FAILURE; } signal (SIGINT, sig_handler); signal (SIGQUIT, sig_handler); signal (SIGTERM, sig_handler); /* The motherfucking saga continues... */ start_network_scan (); GMainContext *ctx = g_main_loop_get_context (loop); while (g_main_context_pending (ctx)) g_main_context_iteration (ctx, FALSE); dbus_g_connection_flush (sys_conn); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (PhoneNet_proxy); dbus_g_connection_unref (sys_conn); return EXIT_SUCCESS; }
/* gcc set_network.c -Wall `pkg-config --cflags --libs dbus-glib-1` */ #include <stdlib.h> #include <glib.h> #include <dbus/dbus-glib.h> #define PHONE_SERVICE "com.nokia.phone.net" #define PHONE_PATH "/com/nokia/phone/net" #define PHONE_IFACE "Phone.Net" #define SEL_NETWORK_MODE "select_network_mode" #define SEL_NETWORK "select_network" static void set_automatic (DBusGProxy *PhoneNet_proxy) { const guchar automatic = 2; dbus_g_proxy_call_no_reply (PhoneNet_proxy, SEL_NETWORK_MODE, G_TYPE_UCHAR, automatic, G_TYPE_INVALID); /* Probably does send a reply */ } static void set_manual (DBusGProxy *PhoneNet_proxy) { const guchar unk_val1 = 1; const guchar unk_val2 = 0; const gchar *MNC = "30"; const gchar *MCC = "234"; dbus_g_proxy_call_no_reply (PhoneNet_proxy, SEL_NETWORK, G_TYPE_UCHAR, unk_val1, G_TYPE_UCHAR, unk_val2, G_TYPE_STRING, MNC, G_TYPE_STRING, MCC, G_TYPE_INVALID); /* Probably does send a reply */ } int main (int argc, char *argv[]) { GError *error = NULL; DBusGConnection *sys_conn = NULL; DBusGProxy *PhoneNet_proxy = NULL; g_type_init (); sys_conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!sys_conn) { g_printerr ("Failed to open connection to system bus: %s\n", error->message); g_clear_error (&error); return EXIT_FAILURE; } PhoneNet_proxy = dbus_g_proxy_new_for_name (sys_conn, PHONE_SERVICE, PHONE_PATH, PHONE_IFACE); if (!PhoneNet_proxy) { g_printerr ("%s\n", "Failed to create "PHONE_SERVICE" proxy"); return EXIT_FAILURE; } if (argc > 1) set_manual (PhoneNet_proxy); else set_automatic (PhoneNet_proxy); g_object_unref (PhoneNet_proxy); dbus_g_connection_unref (sys_conn); return EXIT_SUCCESS; }
/* gcc cur_network_mode.c -Wall `pkg-config --cflags --libs dbus-glib-1` */ #include <stdlib.h> #include <glib.h> #include <glib/gprintf.h> #include <dbus/dbus-glib.h> #define PHONE_SERVICE "com.nokia.phone.net" #define PHONE_PATH "/com/nokia/phone/net" #define PHONE_IFACE "Phone.Net" #define GET_NETWORK_SEL_MODE "get_network_selection_mode" #define NETWORK_GET_REG_STATUS "get_registration_status" #define NETWORK_GET_OP_NAME "get_operator_name" void get_operator_name (DBusGProxy *PhoneNetProxy) { guchar status; guint16 lac, network_type, supported_services; guint32 cell_id, operator_code, country_code; gint32 net_err = -1; gchar *operator_name = NULL; if (dbus_g_proxy_call (PhoneNetProxy, NETWORK_GET_REG_STATUS, NULL, G_TYPE_INVALID, G_TYPE_UCHAR, &status, G_TYPE_UINT, &lac, G_TYPE_UINT, &cell_id, G_TYPE_UINT, &operator_code, G_TYPE_UINT, &country_code, G_TYPE_UCHAR, &network_type, G_TYPE_UCHAR, &supported_services, G_TYPE_INT, &net_err, G_TYPE_INVALID) && net_err == 0) (void) dbus_g_proxy_call (PhoneNetProxy, NETWORK_GET_OP_NAME, NULL, G_TYPE_UCHAR, 0, /* NETWORK_HARDCODED_LATIN_OPER_NAME */ G_TYPE_UINT, operator_code, G_TYPE_UINT, country_code, G_TYPE_INVALID, G_TYPE_STRING, &operator_name, G_TYPE_INT, &net_err, G_TYPE_INVALID); if (net_err != 0) return; (void) g_printf ("LAC: %"G_GUINT16_FORMAT"\n", lac); (void) g_printf ("Network type: %"G_GUINT16_FORMAT"\n", network_type); (void) g_printf ("Supp. services: %"G_GUINT16_FORMAT"\n", supported_services); (void) g_printf ("Cell ID: %"G_GUINT32_FORMAT"\n", cell_id); (void) g_printf ("Op. code: %"G_GUINT32_FORMAT"\n", network_type); (void) g_printf ("Country code: %"G_GUINT32_FORMAT"\n", country_code); (void) g_printf ("Operator name: %s\n", operator_name); g_free (operator_name); } int main (void) { GError *error = NULL; DBusGConnection *sys_conn = NULL; DBusGProxy *PhoneNet_proxy = NULL; guchar mode = 0; gint32 network_error = -1; g_type_init (); sys_conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!sys_conn) { g_printerr ("Failed to open connection to system bus: %s\n", error->message); g_clear_error (&error); return EXIT_FAILURE; } PhoneNet_proxy = dbus_g_proxy_new_for_name (sys_conn, PHONE_SERVICE, PHONE_PATH, PHONE_IFACE); if (!PhoneNet_proxy) { g_printerr ("%s\n", "Failed to create "PHONE_SERVICE" proxy"); return EXIT_FAILURE; } /* Get current network mode */ if (!dbus_g_proxy_call (PhoneNet_proxy, GET_NETWORK_SEL_MODE, &error, G_TYPE_INVALID, G_TYPE_UCHAR, &mode, G_TYPE_INT, &network_error, G_TYPE_INVALID)) { if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) g_printerr ("Caught remote method exception %s: %s", dbus_g_error_get_name (error), error->message); else g_printerr ("Failed to call method: %s\n", error->message); g_clear_error (&error); return EXIT_FAILURE; } if (network_error != 0) return EXIT_FAILURE; switch (mode) { case 2: (void) g_printf ("Mode: Automatic\n"); break; case 1: (void) g_printf ("Mode: Manual\n"); break; default: (void) g_printf ("Unknown mode: %u\n", mode); } get_operator_name (PhoneNet_proxy); g_object_unref (PhoneNet_proxy); dbus_g_connection_unref (sys_conn); return EXIT_SUCCESS; }
_______________________________________________ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers