diff options
author | Wim Taymans <wtaymans@redhat.com> | 2014-07-30 16:15:56 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2014-07-30 16:15:56 +0200 |
commit | 854f4f6f507b224687b8800d284ce042a4625aba (patch) | |
tree | fe450631dfae3185cdaff02b2a3c0c1d3e228a4d | |
parent | fb560bdffc352640091e8f0c380aa6770dcbf2a8 (diff) |
.
-rw-r--r-- | make-hsp-ag.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/make-hsp-ag.c b/make-hsp-ag.c index 8bda5c9..f5f4c16 100644 --- a/make-hsp-ag.c +++ b/make-hsp-ag.c @@ -50,48 +50,6 @@ static const gchar introspection_xml[] = " </interface>" "</node>"; -static gboolean -rfcomm_io_cb (GIOChannel *source, GIOCondition condition, gpointer data) -{ - gchar buf[512]; - GIOStatus st; - - g_print ("condition %d\n", condition); - - if (condition & G_IO_IN) { - gint fd = g_io_channel_unix_get_fd (source); - gsize length; - - g_print ("we can read\n", condition); - - g_io_channel_read_chars (source, buf, 512, &length, NULL); - buf[length] = 0; - g_print ("%d %s\n", length, buf); - - if (g_str_has_prefix (buf, "AT+BRSF=")) { - write (fd, "+BRSF:254\r\n", 11); - write (fd, "OK\r\n", 3); - } - else if (g_str_has_prefix (buf, "AT+CIND=?")) { - write (fd, "+CIND:254\r\n", 11); - write (fd, "OK\r\n", 3); - } - else if (g_str_has_prefix (buf, "AT+CIND?")) { - write (fd, "+CIND:254\r\n", 11); - write (fd, "OK\r\n", 3); - } - else if (g_str_has_prefix (buf, "AT+CMER=")) { - write (fd, "+VGM:15\r\n", 9); - write (fd, "+VGS:15\r\n", 9); - write (fd, "OK\r\n", 3); - } - else { - write (fd, "OK\r\n", 3); - } - } - return TRUE; -} - static struct sco_options so; static gboolean @@ -175,6 +133,7 @@ start_codec_connection (gchar *src_addr, addr.sco_family = AF_BLUETOOTH; bacpy(&addr.sco_bdaddr, &dst); + g_printerr ("doing connect\n"); err = connect(sock, (struct sockaddr *) &addr, sizeof(addr)); if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS)) { perror("connect()"); @@ -187,7 +146,7 @@ start_codec_connection (gchar *src_addr, return -1; } - g_print ("MTU %d\n", so.mtu); + g_print ("connected: MTU %d\n", so.mtu); io = g_io_channel_unix_new (sock); g_io_channel_set_close_on_unref(io, TRUE); @@ -199,6 +158,52 @@ start_codec_connection (gchar *src_addr, return 0; } +static gboolean +rfcomm_io_cb (GIOChannel *source, GIOCondition condition, gpointer data) +{ + gchar buf[512]; + GIOStatus st; + + g_print ("condition %d\n", condition); + + if (condition & G_IO_IN) { + gint fd = g_io_channel_unix_get_fd (source); + gsize length; + + g_print ("we can read\n", condition); + + g_io_channel_read_chars (source, buf, 512, &length, NULL); + buf[length] = 0; + g_print ("%d %s\n", length, buf); + + if (g_str_has_prefix (buf, "AT+BRSF=")) { + write (fd, "\r\n+BRSF:254\r\n", 13); + write (fd, "\r\nOK\r\n", 5); + } + else if (g_str_has_prefix (buf, "AT+CIND=?")) { + write (fd, "\r\n+CIND:254\r\n", 13); + write (fd, "\r\nOK\r\n", 5); + } + else if (g_str_has_prefix (buf, "AT+CIND?")) { + write (fd, "\r\n+CIND:254\r\n", 13); + write (fd, "\r\nOK\r\n", 5); + } + else if (g_str_has_prefix (buf, "AT+CMER=")) { + write (fd, "\r\n+VGM:15\r\n", 11); + write (fd, "\r\n+VGS:15\r\n", 11); + write (fd, "\r\nOK\r\n", 5); + } + else if (g_str_has_prefix (buf, "AT+CMEE=")) { + write (fd, "\r\nOK\r\n", 5); + start_codec_connection ("FC:F8:AE:4A:3F:D4", "13:11:14:AA:00:B8"); + } + else { + write (fd, "\r\nOK\r\n", 5); + } + } + return TRUE; +} + static void profile_method_call (GDBusConnection *connection, const gchar *sender, @@ -236,7 +241,6 @@ profile_method_call (GDBusConnection *connection, channel = g_io_channel_unix_new (fd); g_io_add_watch (channel, G_IO_IN, rfcomm_io_cb, NULL); - start_codec_connection ("00:15:83:50:D1:E1", "13:11:14:AA:00:B8"); } else g_print ("Unhandled %s\n", method_name); |