Editing Documentation/Maemo 5 Developer Guide/Using Connectivity Components/Maemo Connectivity

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 69 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 505: Line 505:
==Bluetooth Libraries ==
==Bluetooth Libraries ==
 +
This section explains how maemo Bluetooth libraries work internally. The following subsections explain the behavior and the decomposition of the Bluetooth library components in detail.
-
This section explains how Maemo Bluetooth libraries work internally. The following subsections explain the behavior and the decomposition of the Bluetooth library components in detail.
 
=== Discovering devices ===
=== Discovering devices ===
Line 712: Line 712:
=== Libgwobex ===
=== Libgwobex ===
-
 
+
Libgwobex provides access to libopenobex functionality by providing a <br /> helper/wrapper interface. Libopenobex is explained in detail in the following section.
-
Libgwobex provides access to libopenobex functionality by providing a helper/wrapper interface. Libopenobex is explained in detail in the following section.
+
The interface to libgwobex is available at [http://maemo.org/api_refs/5.0/5.0-final/osso-gwobex/ GW OBEX Library Documentation].
The interface to libgwobex is available at [http://maemo.org/api_refs/5.0/5.0-final/osso-gwobex/ GW OBEX Library Documentation].
===Creating Connection ===
===Creating Connection ===
 +
The connection with libgwobex is established using the gw_obex_setup_dev function, setting up the connection. gw-obex.h
-
The connection with libgwobex is established using the <code>gw_obex_setup_dev</code> function, setting up the connection. gw-obex.h
+
<tt><span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> OBEX_FTP_UUID <span><font color="#990000">\</font></span>
 +
        <span><font color="#FF0000">"</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">F9</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">EC</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">7B</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">C4</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">95</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">3C</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">11</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">D2</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">98</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">4E</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">52</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">54</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">00</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">DC</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">9E</font></span><span><font color="#CC33CC">\x</font></span><span><font color="#FF0000">09"</font></span>
 +
<span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> OBEX_FTP_UUID_LEN <span><font color="#993399">16</font></span>
 +
 +
<span>''<span><font color="#9A1900">/* ... */</font></span>''</span>
 +
 +
GwObex<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">gw_obex_setup_dev</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> device<span><font color="#990000">,</font></span> <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> uuid<span><font color="#990000">,</font></span> gint uuid_len<span><font color="#990000">,</font></span>
 +
                            GMainContext <span><font color="#990000"><nowiki>*</nowiki></font></span> context<span><font color="#990000">,</font></span> gint <span><font color="#990000"><nowiki>*</nowiki></font></span> error <span><font color="#990000">)</font></span></tt>
-
<source lang="c">
+
The following code snippet illustrates how to open a handle using gw_obex_setup_dev.
-
#define OBEX_FTP_UUID \
+
-
        "\xF9\xEC\x7B\xC4\x95\x3C\x11\xD2\x98\x4E\x52\x54\x00\xDC\x9E\x09"
+
-
#define OBEX_FTP_UUID_LEN 16
+
-
/* ... */
+
<tt><span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>rfcomm_dev<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
 +
        <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>use_ftp<span><font color="#990000">)</font></span>
 +
                ctx<span><font color="#990000">-&gt;</font></span>obex <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gw_obex_setup_dev</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>rfcomm_dev<span><font color="#990000">,</font></span>
 +
                        OBEX_FTP_UUID<span><font color="#990000">,</font></span> OBEX_FTP_UUID_LEN<span><font color="#990000">,</font></span>
 +
                        NULL<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>err<span><font color="#990000">);</font></span>
 +
        <span>'''<span><font color="#0000FF">else</font></span>'''</span>
 +
                ctx<span><font color="#990000">-&gt;</font></span>obex <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gw_obex_setup_dev</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>rfcomm_dev<span><font color="#990000">,</font></span> NULL<span><font color="#990000">,</font></span>
 +
                        <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> NULL<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>err<span><font color="#990000">);</font></span>
 +
 +
        <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex <span><font color="#990000"><nowiki>==</nowiki></font></span> NULL<span><font color="#990000">)</font></span>
 +
                <span>'''<span><font color="#000000">printf</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"OBEX setup failed: %s</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">response_to_string</font></span>'''</span><span><font color="#990000">(</font></span>err<span><font color="#990000">));</font></span>
 +
<span><font color="#FF0000">}</font></span></tt>
-
GwObex* gw_obex_setup_dev (const gchar * device, const gchar * uuid, gint uuid_len,
+
In this example, ctx-&gt;rfcomm_dev points to a string containing the device node name (e.g. /dev/rfcomm0). ctx-&gt;use_ftp dictates whether to set up standard folder browsing services. If use_ftp is untrue, then INBOX is connected.
-
                          GMainContext * context, gint * error )
+
-
</source>
+
-
The following code snippet illustrates how to open a handle using <code>gw_obex_setup_dev</code>.
 
-
 
-
<source lang="c">
 
-
if (ctx->rfcomm_dev) {
 
-
        if (ctx->use_ftp)
 
-
                ctx->obex = gw_obex_setup_dev(ctx->rfcomm_dev,
 
-
                        OBEX_FTP_UUID, OBEX_FTP_UUID_LEN,
 
-
                        NULL, &err);
 
-
        else
 
-
                ctx->obex = gw_obex_setup_dev(ctx->rfcomm_dev, NULL,
 
-
                        0, NULL, &err);
 
-
 
-
        if (ctx->obex == NULL)
 
-
                printf("OBEX setup failed: %s\n", response_to_string(err));
 
-
}
 
-
</source>
 
-
 
-
In this example, <code>ctx-&gt;rfcomm_dev</code> points to a string containing the device node name (e.g. <code>/dev/rfcomm0</code>). <code>ctx-&gt;use_ftp</code> dictates whether to set up standard folder browsing services. If <code>use_ftp</code> is untrue, then INBOX is connected.
 
===Closing Connection ===
===Closing Connection ===
-
 
To close a gwobex connection, use the following function: gw-obex.h
To close a gwobex connection, use the following function: gw-obex.h
-
<source lang="c">
+
<tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">gw_obex_close</font></span>'''</span> <span><font color="#990000">(</font></span> GwObex <span><font color="#990000"><nowiki>*</nowiki></font></span> ctx <span><font color="#990000">);</font></span></tt>
-
void gw_obex_close ( GwObex * ctx );
+
-
</source>
+
The following code demonstrates this usage.
The following code demonstrates this usage.
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
if (ctx->obex) {
+
        <span>'''<span><font color="#000000">gw_obex_close</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex<span><font color="#990000">);</font></span>
-
        gw_obex_close(ctx->obex);
+
        ctx<span><font color="#990000">-&gt;</font></span>obex <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
        ctx->obex = NULL;
+
<span><font color="#FF0000">}</font></span></tt>
-
}
+
 
-
</source>
+
If ctx-&gt;obex is not NULL, it is simply passed as an argument to gw_obex_close().
-
If <code>ctx-&gt;obex</code> is not <code>NULL</code>, it is simply passed as an argument to <code>gw_obex_close()</code>.
 
===Using Connection ===
===Using Connection ===
-
 
The libgwobex library provides general file handling functionality, including reading directory structure, browsing in different folders and getting files.
The libgwobex library provides general file handling functionality, including reading directory structure, browsing in different folders and getting files.
To read entries from an opened directory, use the following function: gw-obex.h
To read entries from an opened directory, use the following function: gw-obex.h
-
<source lang="c">
+
<tt>gboolean <span>'''<span><font color="#000000">gw_obex_read_dir</font></span>'''</span> <span><font color="#990000">(</font></span>GwObex <span><font color="#990000"><nowiki>*</nowiki></font></span> ctx<span><font color="#990000">,</font></span>
-
gboolean gw_obex_read_dir (GwObex * ctx,
+
                            <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> dir<span><font color="#990000">,</font></span>
-
                          const gchar * dir,
+
                            gchar <span><font color="#990000"><nowiki>**</nowiki></font></span> buf<span><font color="#990000">,</font></span>
-
                          gchar ** buf,
+
                            gint <span><font color="#990000"><nowiki>*</nowiki></font></span> buf_size<span><font color="#990000">,</font></span>
-
                          gint * buf_size,
+
                            gint <span><font color="#990000"><nowiki>*</nowiki></font></span> error <span><font color="#990000">);</font></span></tt>
-
                          gint * error );
+
-
</source>
+
-
<code>gw_obex_read_dir</code> reads an entry from the selected folder and returns the result in the <code>buf</code> argument given to the function.
+
gw_obex_read_dir reads an entry from the selected folder and returns the result in the buf argument given to the function.
-
<source lang="c">
+
<tt>gboolean ret<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
gboolean ret;
+
<span>''<span><font color="#9A1900">/* ... */</font></span>''</span>
-
/* ... */
+
ret <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gw_obex_read_dir</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex<span><font color="#990000">,</font></span> dir<span><font color="#990000">,</font></span> buf<span><font color="#990000">,</font></span> buf_size<span><font color="#990000">,</font></span> err<span><font color="#990000">);</font></span></tt>
-
ret = gw_obex_read_dir(ctx->obex, dir, buf, buf_size, err);
+
-
</source>
+
This reads an entry from the directory <code>dir (char *)</code> and returns it in <code>buf (char **)</code>.
This reads an entry from the directory <code>dir (char *)</code> and returns it in <code>buf (char **)</code>.
Line 796: Line 782:
To change the current directory, use the following function: gw-obex.h
To change the current directory, use the following function: gw-obex.h
-
<source lang="c">
+
<tt>gboolean <span>'''<span><font color="#000000">gw_obex_chdir</font></span>'''</span> <span><font color="#990000">(</font></span>GwObex <span><font color="#990000"><nowiki>*</nowiki></font></span> ctx<span><font color="#990000">,</font></span> <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> dir<span><font color="#990000">,</font></span> gint <span><font color="#990000"><nowiki>*</nowiki></font></span> error <span><font color="#990000">);</font></span></tt>
-
gboolean gw_obex_chdir (GwObex * ctx, const gchar * dir, gint * error );
+
-
</source>
+
which changes the directory of the FTP connection. Below is a code example using this function.
which changes the directory of the FTP connection. Below is a code example using this function.
-
<source lang="c">
+
<tt><span>''<span><font color="#9A1900">/* Ignore parent dir pointers */</font></span>''</span>
-
/* Ignore parent dir pointers */
+
<span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">g_str_equal</font></span>'''</span><span><font color="#990000">(</font></span>name<span><font color="#990000">,</font></span> <span><font color="#FF0000">".."</font></span><span><font color="#990000">))</font></span>
-
if (g_str_equal(name, ".."))
+
        <span>'''<span><font color="#0000FF">return</font></span>'''</span> TRUE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
        return TRUE;
+
-
 
+
<span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(!</font></span><span>'''<span><font color="#000000">gw_obex_chdir</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex<span><font color="#990000">,</font></span> name<span><font color="#990000">,</font></span> err<span><font color="#990000">))</font></span> <span><font color="#FF0000">{</font></span>
-
if (!gw_obex_chdir(ctx->obex, name, err)) {
+
        <span>'''<span><font color="#000000">printf</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"Could not chdir to %s</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">,</font></span> name<span><font color="#990000">);</font></span>
-
        printf("Could not chdir to %s\n", name);
+
        <span>'''<span><font color="#0000FF">return</font></span>'''</span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
        return FALSE;
+
<span><font color="#FF0000">}</font></span></tt>
-
}
+
-
</source>
+
To retrieve files over the OBEX connection, use the <code>gw_obex_get_file</code> function: gw-obex.h
To retrieve files over the OBEX connection, use the <code>gw_obex_get_file</code> function: gw-obex.h
-
<source lang="c">
+
<tt>gboolean <span>'''<span><font color="#000000">gw_obex_get_file</font></span>'''</span> <span><font color="#990000">(</font></span>GwObex <span><font color="#990000"><nowiki>*</nowiki></font></span> ctx<span><font color="#990000">,</font></span>
-
gboolean gw_obex_get_file (GwObex * ctx,
+
                            <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> local<span><font color="#990000">,</font></span>
-
                          const gchar * local,
+
                            <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> remote<span><font color="#990000">,</font></span>
-
                          const gchar * remote,
+
                            <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span> type<span><font color="#990000">,</font></span>
-
                          const gchar * type,
+
                            gint <span><font color="#990000"><nowiki>*</nowiki></font></span> error<span><font color="#990000">);</font></span>
-
                          gint * error);
+
</tt>
-
</source>
+
-
<code>gw_obex_get_file</code> uses the <code>ctx</code> context for retrieving the remote file to local file.
+
gw_obex_get_file uses the ctx context for retrieving the remote file to local file.
-
<source lang="c">
+
<tt>gboolean ret<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
gboolean ret;
+
ret <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gw_obex_get_file</font></span>'''</span><span><font color="#990000">(</font></span>ctx<span><font color="#990000">-&gt;</font></span>obex<span><font color="#990000">,</font></span> name<span><font color="#990000">,</font></span> name<span><font color="#990000">,</font></span> err<span><font color="#990000">);</font></span></tt>
-
ret = gw_obex_get_file(ctx->obex, name, name, err);
+
-
</source>
+
Using the libwobex wrapper directly allows you to perform many more functions. For more information, see the [http://maemo.org/api_refs/5.0/5.0-final/osso-gwobex/ API document].
Using the libwobex wrapper directly allows you to perform many more functions. For more information, see the [http://maemo.org/api_refs/5.0/5.0-final/osso-gwobex/ API document].
===Libopenobex ===
===Libopenobex ===
-
 
+
The LibOpenOBEX library implements a generic OBEX Session Protocol, but not the OBEX Application Framework. OBEX is a protocol designed to allow data interchanging between different kinds of connections (e.g. Bluetooth, IrDA). For more information on the OBEX protocol, see [http://www.irda.org/ http://www.irda.org]<nowiki>; select the Developer-&gt;Specifications category. OBEX resembles the HTTP protocol, expect for a few differences: </nowiki>
-
The LibOpenOBEX library implements a generic OBEX Session Protocol, but not the OBEX Application Framework. OBEX is a protocol designed to allow data interchanging between different kinds of connections (e.g. Bluetooth, IrDA). For more information on the OBEX protocol, see [http://www.irda.org/ http://www.irda.org]; select the Developer-&gt;Specifications category. OBEX resembles the HTTP protocol, expect for a few differences:
+
* Transports: While HTTP is normally layered above a TCP/IP connection, OBEX is usually transported over IrLAP/IrLMP/Tiny TP (on IrDA) or over Baseband/Link Manager/L2CAP/RFCOMM (on Bluetooth).
* Transports: While HTTP is normally layered above a TCP/IP connection, OBEX is usually transported over IrLAP/IrLMP/Tiny TP (on IrDA) or over Baseband/Link Manager/L2CAP/RFCOMM (on Bluetooth).
Line 840: Line 818:
* Session support: HTTP is stateless, while OBEX maintains the connection.
* Session support: HTTP is stateless, while OBEX maintains the connection.
-
For more information on OBEX, see the summary available at the [[:wikipedia:OBject EXchange|Wikipedia article on OBEX]].
+
For more information on OBEX, see the summary available at <br />http://en.wikipedia.org/wiki/OBEX.
-
For libopenobex code samples, see http://openobex.triq.net/downloads the samples are in the example apps package.
+
For libopenobex code samples, see <br />http://openobex.triq.net/downloads<nowiki>; the samples are in the example apps package. </nowiki>
-
===Using BlueZ D-Bus API ===
 
 +
===Using BlueZ D-Bus API ===
The BlueZ system exports a D-Bus API that can be employed instead of OSSO Bluetooth tools. See the following documents:
The BlueZ system exports a D-Bus API that can be employed instead of OSSO Bluetooth tools. See the following documents:

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)