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; }
/* 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 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 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 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; }