static GAtPPP *ppp_init_common(GAtHDLC *hdlc, gboolean is_server, guint32 ip) { GAtPPP *ppp; ppp = g_try_malloc0(sizeof(GAtPPP)); if (ppp == NULL) return NULL; ppp->hdlc = g_at_hdlc_ref(hdlc); ppp->ref_count = 1; /* set options to defaults */ ppp->mru = DEFAULT_MRU; ppp->mtu = DEFAULT_MTU; /* initialize the lcp state */ ppp->lcp = lcp_new(ppp, is_server); /* initialize IPCP state */ ppp->ipcp = ipcp_new(ppp, is_server, ip); g_at_hdlc_set_receive(ppp->hdlc, ppp_receive, ppp); g_at_io_set_disconnect_function(g_at_hdlc_get_io(ppp->hdlc), io_disconnect, ppp); if (is_server) ppp_enter_phase(ppp, PPP_PHASE_ESTABLISHMENT); return ppp; }
int main(int argc, char **argv) { GOptionContext *context; GError *err = NULL; GIOChannel *channel; GAtHDLC *hdlc; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) { if (err != NULL) { g_printerr("%s\n", err->message); g_error_free(err); return 1; } g_printerr("An unknown error occurred\n"); return 1; } g_option_context_free(context); if (option_device == NULL) option_device = g_strdup("/dev/ttyUSB1"); g_print("Device: %s\n", option_device); channel = g_at_tty_open_qcdm(option_device); if (channel == NULL) { g_printerr("Failed to open QCDM device\n"); return 1; } event_loop = g_main_loop_new(NULL, FALSE); hdlc = g_at_hdlc_new(channel); g_io_channel_unref(channel); if (hdlc == NULL) return 1; if (option_debug == TRUE) g_at_hdlc_set_debug(hdlc, hdlc_debug, "HDLC"); g_at_hdlc_set_xmit_accm(hdlc, 0); g_at_hdlc_set_recv_accm(hdlc, 0); g_at_hdlc_set_receive(hdlc, hdlc_receive, NULL); send_command(hdlc, 0x00); /* Version info */ send_command(hdlc, 0x51); /* Features query */ send_subsys_command(hdlc, 250, 7); /* Novatel modem status */ g_main_loop_run(event_loop); g_at_hdlc_unref(hdlc); g_main_loop_unref(event_loop); g_free(option_device); return 0; }