static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data) { g_print("PPP Link down: %d\n", reason); g_at_ppp_unref(ppp); ppp = NULL; if (option_modem == NULL) g_at_chat_set_debug(modem, gsmdial_debug, ""); else g_at_chat_set_debug(modem, gsmdial_debug, "Modem"); g_at_chat_register(modem, "NO CARRIER", no_carrier_notify, FALSE, NULL, NULL); g_at_chat_resume(modem); }
/* either oFono or Phone could request SLC connection */ static int service_level_connection(struct ofono_modem *modem, int fd) { struct hfp_data *data = ofono_modem_get_data(modem); GIOChannel *io; GAtSyntax *syntax; GAtChat *chat; io = g_io_channel_unix_new(fd); if (io == NULL) { ofono_error("Service level connection failed: %s (%d)", strerror(errno), errno); return -EIO; } syntax = g_at_syntax_new_gsm_permissive(); chat = g_at_chat_new(io, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(io); if (chat == NULL) return -ENOMEM; g_at_chat_set_disconnect_function(chat, hfp_disconnected_cb, modem); if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, hfp_debug, ""); data->info.chat = chat; hfp_slc_establish(&data->info, slc_established, slc_failed, modem); return -EINPROGRESS; }
static int service_level_connection(struct ofono_modem *modem, int fd, guint16 version) { struct hfp *hfp = ofono_modem_get_data(modem); struct hfp_slc_info *info = &hfp->info; GIOChannel *io; GAtSyntax *syntax; GAtChat *chat; io = g_io_channel_unix_new(fd); syntax = g_at_syntax_new_gsm_permissive(); chat = g_at_chat_new(io, syntax); g_at_syntax_unref(syntax); g_io_channel_set_close_on_unref(io, TRUE); g_io_channel_unref(io); if (chat == NULL) return -ENOMEM; g_at_chat_set_disconnect_function(chat, hfp_disconnected_cb, modem); if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, hfp_debug, ""); hfp_slc_info_init(info, version); info->chat = chat; hfp_slc_establish(info, slc_established, slc_failed, modem); return -EINPROGRESS; }
static GAtChat *open_device(struct ofono_modem *modem, const char *key, char *debug) { const char *device; GAtSyntax *syntax; GIOChannel *channel; GAtChat *chat; device = ofono_modem_get_string(modem, key); if (device == NULL) return NULL; DBG("%s %s", key, device); channel = g_at_tty_open(device, NULL); if (channel == NULL) return NULL; syntax = g_at_syntax_new_gsmv1(); chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(channel); if (chat == NULL) return NULL; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, telit_debug, debug); return chat; }
static int cinterion_enable(struct ofono_modem *modem) { GAtChat *chat; GIOChannel *channel; GAtSyntax *syntax; GHashTable *options; const char *device; DBG("%p", modem); options = g_hash_table_new(g_str_hash, g_str_equal); if (options == NULL) return -ENOMEM; device = ofono_modem_get_string(modem, "Device"); if (device == NULL) return -EINVAL; g_hash_table_insert(options, "Baud", "115200"); g_hash_table_insert(options, "StopBits", "1"); g_hash_table_insert(options, "DataBits", "8"); g_hash_table_insert(options, "Parity", "none"); g_hash_table_insert(options, "XonXoff", "off"); g_hash_table_insert(options, "RtsCts", "on"); g_hash_table_insert(options, "Local", "on"); g_hash_table_insert(options, "Read", "on"); channel = g_at_tty_open(device, options); g_hash_table_destroy(options); if (channel == NULL) return -EIO; /* * (Cinterion plugin is based on tc65 plugin. Comment left in but may * not be applicable in the general case) * * TC65 works almost as the 27.007 says. But for example after * AT+CRSM the modem replies with the data in the queried EF and * writes three pairs of <CR><LF> after the data and before OK. */ syntax = g_at_syntax_new_gsm_permissive(); chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(channel); if (chat == NULL) return -ENOMEM; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, cinterion_debug, ""); ofono_modem_set_data(modem, chat); return 0; }
static int ifx_enable(struct ofono_modem *modem) { struct ifx_data *data = ofono_modem_get_data(modem); const char *device, *ldisc; GAtSyntax *syntax; GAtChat *chat; DBG("%p", modem); device = ofono_modem_get_string(modem, "Device"); if (device == NULL) return -EINVAL; DBG("%s", device); ldisc = ofono_modem_get_string(modem, "LineDiscipline"); if (ldisc != NULL) { data->mux_ldisc = atoi(ldisc); ofono_info("Using multiplexer line discipline %d", data->mux_ldisc); } data->device = g_at_tty_open(device, NULL); if (data->device == NULL) return -EIO; syntax = g_at_syntax_new_gsmv1(); chat = g_at_chat_new(data->device, syntax); g_at_syntax_unref(syntax); if (chat == NULL) { g_io_channel_unref(data->device); return -EIO; } if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, ifx_debug, "Master: "); g_at_chat_send(chat, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL); /* Enable multiplexer */ data->frame_size = 1509; g_at_chat_send(chat, "AT+CMUX=0,0,,1509,10,3,30,,", NULL, mux_setup_cb, modem, NULL); data->mux_init_timeout = g_timeout_add_seconds(5, mux_timeout_cb, modem); data->dlcs[AUX_DLC] = chat; return -EINPROGRESS; }
static int open_serial(void) { GAtSyntax *syntax; GIOChannel *channel; channel = g_at_tty_open(option_control, NULL); if (channel == NULL) return -EIO; syntax = g_at_syntax_new_gsm_permissive(); control = g_at_chat_new(channel, syntax); g_io_channel_unref(channel); g_at_syntax_unref(syntax); if (control == NULL) return -EIO; if (option_modem == NULL) { g_at_chat_ref(control); modem = control; g_at_chat_set_debug(control, gsmdial_debug, ""); } else { g_at_chat_set_debug(control, gsmdial_debug, "Control"); channel = g_at_tty_open(option_modem, NULL); if (channel == NULL) return -EIO; syntax = g_at_syntax_new_gsm_permissive(); modem = g_at_chat_new(channel, syntax); g_io_channel_unref(channel); g_at_syntax_unref(syntax); if (modem == NULL) return -EIO; g_at_chat_set_debug(modem, gsmdial_debug, "Modem"); } return 0; }
static int localhfp_enable(struct ofono_modem *modem) { struct hfp_slc_info *info = ofono_modem_get_data(modem); GIOChannel *io; GAtSyntax *syntax; GAtChat *chat; const char *address; int sk, port; address = ofono_modem_get_string(modem, "Address"); if (address == NULL) return -EINVAL; port = ofono_modem_get_integer(modem, "Port"); if (port < 0) return -EINVAL; sk = connect_socket(address, port); if (sk < 0) return sk; io = g_io_channel_unix_new(sk); if (io == NULL) { close(sk); return -ENOMEM; } syntax = g_at_syntax_new_gsmv1(); chat = g_at_chat_new(io, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(io); if (chat == NULL) return -ENOMEM; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, phonesim_debug, "LocalHfp: "); g_at_chat_set_disconnect_function(chat, slc_failed, modem); hfp_slc_info_init(info, HFP_VERSION_LATEST); info->chat = chat; hfp_slc_establish(info, slc_established, slc_failed, modem); return -EINPROGRESS; }
static int open_ip(void) { int sk, err; struct sockaddr_in addr; GAtSyntax *syntax; GIOChannel *channel; sk = socket(PF_INET, SOCK_STREAM, 0); if (sk < 0) return -EINVAL; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(option_ip); addr.sin_port = htons(option_port); err = connect(sk, (struct sockaddr *) &addr, sizeof(addr)); if (err < 0) { close(sk); return err; } channel = g_io_channel_unix_new(sk); if (channel == NULL) { close(sk); return -ENOMEM; } syntax = g_at_syntax_new_gsmv1(); control = g_at_chat_new(channel, syntax); g_io_channel_unref(channel); g_at_syntax_unref(syntax); if (control == NULL) return -ENOMEM; g_at_chat_ref(control); modem = control; g_at_chat_set_debug(control, gsmdial_debug, ""); return 0; }
static void mux_setup(GAtMux *mux, gpointer user_data) { struct ofono_modem *modem = user_data; struct phonesim_data *data = ofono_modem_get_data(modem); GIOChannel *io; GAtSyntax *syntax; DBG("%p", mux); if (mux == NULL) { ofono_modem_set_powered(modem, FALSE); return; } data->mux = mux; if (getenv("OFONO_AT_DEBUG")) g_at_mux_set_debug(data->mux, phonesim_debug, ""); g_at_mux_start(mux); io = g_at_mux_create_channel(mux); if (data->calypso) syntax = g_at_syntax_new_gsm_permissive(); else syntax = g_at_syntax_new_gsmv1(); data->chat = g_at_chat_new(io, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(io); if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(data->chat, phonesim_debug, ""); if (data->calypso) g_at_chat_set_wakeup_command(data->chat, "AT\r", 500, 5000); g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL); g_at_chat_send(data->chat, "AT+CFUN=1", none_prefix, cfun_set_on_cb, modem, NULL); }
static GAtChat *open_device(struct ofono_modem *modem, const char *key, char *debug) { const char *device; GAtSyntax *syntax; GIOChannel *channel; GAtChat *chat; GHashTable *options; device = ofono_modem_get_string(modem, key); if (device == NULL) return NULL; DBG("%s %s", key, device); options = g_hash_table_new(g_str_hash, g_str_equal); if (options == NULL) return NULL; g_hash_table_insert(options, "Baud", "115200"); channel = g_at_tty_open(device, options); g_hash_table_destroy(options); if (channel == NULL) return NULL; syntax = g_at_syntax_new_gsmv1(); chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(channel); if (chat == NULL) return NULL; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, telit_debug, debug); return chat; }
static void test_connect(gboolean use_socket) { GIOChannel *io; GAtChat *chat; GAtSyntax *syntax; int fd; if (use_socket == TRUE) fd = do_connect(); else fd = do_open(); if (fd < 0) return; io = g_io_channel_unix_new(fd); g_io_channel_set_close_on_unref(io, TRUE); syntax = g_at_syntax_new_gsm_permissive(); chat = g_at_chat_new_blocking(io, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(io); if (chat == NULL) { g_printerr("Chat creation failed\n"); return; } g_at_chat_set_debug(chat, caif_debug, NULL); g_at_chat_send(chat, "ATE0 +CMEE=1", NULL, caif_init, chat, NULL); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_main_loop_unref(mainloop); }
static int device_dial_setup(struct dundee_device *device, int fd) { GAtSyntax *syntax; GIOChannel *io; io = g_io_channel_unix_new(fd); if (io == NULL) return -EIO; syntax = g_at_syntax_new_gsm_permissive(); device->chat = g_at_chat_new(io, syntax); g_io_channel_unref(io); g_at_syntax_unref(syntax); if (device->chat == NULL) return -EIO; g_at_chat_set_debug(device->chat, debug, "Control"); g_at_chat_send(device->chat, "ATD*99#", none_prefix, dial_cb, device, NULL); return 0; }
static GAtChat *create_chat(GIOChannel *channel, struct ofono_modem *modem, char *debug) { GAtSyntax *syntax; GAtChat *chat; if (channel == NULL) return NULL; syntax = g_at_syntax_new_gsmv1(); chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(channel); if (chat == NULL) return NULL; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, ifx_debug, debug); g_at_chat_set_disconnect_function(chat, dlc_disconnect, modem); return chat; }
static int atgen_enable(struct ofono_modem *modem) { GAtChat *chat; GIOChannel *channel; GAtSyntax *syntax; const char *device; const char *value; GHashTable *options; int i; DBG("%p", modem); device = ofono_modem_get_string(modem, "Device"); if (!device) return -EINVAL; options = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); if (!options) return -ENOMEM; for (i = 0; tty_opts[i]; i++) { value = ofono_modem_get_string(modem, tty_opts[i]); if (value == NULL) continue; g_hash_table_insert(options, g_strdup(tty_opts[i]), g_strdup(value)); } channel = g_at_tty_open(device, options); g_hash_table_destroy(options); if (!channel) { return -EIO; } value = ofono_modem_get_string(modem, "GsmSyntax"); if (value) { if (g_str_equal(value, "V1")) syntax = g_at_syntax_new_gsmv1(); else if (g_str_equal(value, "Permissive")) syntax = g_at_syntax_new_gsm_permissive(); else return -EINVAL; } else { syntax = g_at_syntax_new_gsmv1(); } chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(channel); if (!chat) return -ENOMEM; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(chat, atgen_debug, NULL); ofono_modem_set_data(modem, chat); return 0; }
static int phonesim_enable(struct ofono_modem *modem) { struct phonesim_data *data = ofono_modem_get_data(modem); GIOChannel *io; GAtSyntax *syntax; const char *address, *value; int sk, port; DBG("%p", modem); address = ofono_modem_get_string(modem, "Address"); if (address == NULL) return -EINVAL; port = ofono_modem_get_integer(modem, "Port"); if (port < 0) return -EINVAL; value = ofono_modem_get_string(modem, "Modem"); if (!g_strcmp0(value, "calypso")) data->calypso = TRUE; value = ofono_modem_get_string(modem, "Multiplexer"); if (!g_strcmp0(value, "internal")) data->use_mux = TRUE; sk = connect_socket(address, port); if (sk < 0) return sk; io = g_io_channel_unix_new(sk); if (io == NULL) { close(sk); return -ENOMEM; } if (data->calypso) syntax = g_at_syntax_new_gsm_permissive(); else syntax = g_at_syntax_new_gsmv1(); data->chat = g_at_chat_new(io, syntax); g_at_syntax_unref(syntax); g_io_channel_unref(io); if (data->chat == NULL) return -ENOMEM; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(data->chat, phonesim_debug, ""); g_at_chat_set_disconnect_function(data->chat, phonesim_disconnected, modem); if (data->calypso) { g_at_chat_set_wakeup_command(data->chat, "AT\r", 500, 5000); g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL); g_at_chat_send(data->chat, "AT%CUNS=0", NULL, NULL, NULL, NULL); } if (data->use_mux) { g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL); g_at_mux_setup_gsm0710(data->chat, mux_setup, modem, NULL); g_at_chat_unref(data->chat); data->chat = NULL; return -EINPROGRESS; } g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix, NULL, NULL, NULL); g_at_chat_register(data->chat, "+CRST:", crst_notify, FALSE, modem, NULL); g_at_chat_register(data->chat, "+CBC:", cbc_notify, FALSE, modem, NULL); g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL); data->hfp_watch = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, emulator_hfp_watch, data, NULL); return 0; }