void g_at_ppp_unref(GAtPPP *ppp) { gboolean is_zero; if (ppp == NULL) return; is_zero = g_atomic_int_dec_and_test(&ppp->ref_count); if (is_zero == FALSE) return; g_at_io_set_disconnect_function(g_at_hdlc_get_io(ppp->hdlc), NULL, NULL); if (ppp->net) ppp_net_free(ppp->net); if (ppp->chap) ppp_chap_free(ppp->chap); lcp_free(ppp->lcp); ipcp_free(ppp->ipcp); g_at_hdlc_unref(ppp->hdlc); g_free(ppp); }
GAtPPP *g_at_ppp_new_from_io(GAtIO *io) { GAtHDLC *hdlc; GAtPPP *ppp; hdlc = g_at_hdlc_new_from_io(io); if (hdlc == NULL) return NULL; ppp = ppp_init_common(hdlc, FALSE, 0); g_at_hdlc_unref(hdlc); return ppp; }
GAtPPP *g_at_ppp_new(GIOChannel *modem) { GAtHDLC *hdlc; GAtPPP *ppp; hdlc = g_at_hdlc_new(modem); if (hdlc == NULL) return NULL; ppp = ppp_init_common(hdlc, FALSE, 0); g_at_hdlc_unref(hdlc); return ppp; }
GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local) { GAtHDLC *hdlc; GAtPPP *ppp; guint32 ip; if (local == NULL) ip = 0; else if (inet_pton(AF_INET, local, &ip) != 1) return NULL; hdlc = g_at_hdlc_new_from_io(io); if (hdlc == NULL) return NULL; ppp = ppp_init_common(hdlc, TRUE, ip); g_at_hdlc_unref(hdlc); 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; }