From: lkslawek@gmail.com
To: linux-bluetooth@vger.kernel.org
Cc: Slawomir Bochenski <lkslawek@gmail.com>
Subject: [PATCH 2/4] Add actual service for Message Access Profile
Date: Wed, 2 Mar 2011 10:36:52 +0100 [thread overview]
Message-ID: <1299058614-8904-3-git-send-email-lkslawek@gmail.com> (raw)
In-Reply-To: <1299058614-8904-1-git-send-email-lkslawek@gmail.com>
From: Slawomir Bochenski <lkslawek@gmail.com>
This adds basic service functionality in MAP code, accompanied by proper
record for SDP.
RFCOMM channel of choice is 16 which is in accordance with
doc/assigned-numbers.txt.
---
plugins/mas.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 186 insertions(+), 0 deletions(-)
diff --git a/plugins/mas.c b/plugins/mas.c
index cb6dda0..2d061a1 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -25,18 +25,204 @@
#include <config.h>
#endif
+#include <errno.h>
+#include <glib.h>
+#include <openobex/obex.h>
+
#include "plugin.h"
#include "log.h"
+#include "obex.h"
+#include "service.h"
+#include "dbus.h"
#include "messages.h"
+/* Channel number according to bluez doc/assigned-numbers.txt */
+#define MAS_CHANNEL 16
+
+#define MAS_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
+<record> \
+ <attribute id=\"0x0001\"> \
+ <sequence> \
+ <uuid value=\"0x1132\"/> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0004\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x0100\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0003\"/> \
+ <uint8 value=\"%u\" name=\"channel\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0008\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0009\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x1134\"/> \
+ <uint16 value=\"0x0100\" name=\"version\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0100\"> \
+ <text value=\"%s\" name=\"name\"/> \
+ </attribute> \
+ \
+ <attribute id=\"0x0315\"> \
+ <uint8 value=\"0x00\"/> \
+ </attribute> \
+ \
+ <attribute id=\"0x0316\"> \
+ <uint8 value=\"0x0F\"/> \
+ </attribute> \
+</record>"
+
+struct mas_session {
+ struct mas_request *request;
+};
+
+static const uint8_t MAS_TARGET[TARGET_SIZE] = {
+ 0xbb, 0x58, 0x2b, 0x40, 0x42, 0x0c, 0x11, 0xdb,
+ 0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 };
+
+static void mas_clean(struct mas_session *mas)
+{
+ g_free(mas);
+}
+
+static void *mas_connect(struct obex_session *os, int *err)
+{
+ struct mas_session *mas;
+
+ DBG("");
+
+ *err = 0;
+
+ mas = g_new0(struct mas_session, 1);
+
+ manager_register_session(os);
+
+ return mas;
+}
+
+static void mas_disconnect(struct obex_session *os, void *user_data)
+{
+ struct mas_session *mas = user_data;
+
+ DBG("");
+
+ manager_unregister_session(os);
+
+ mas_clean(mas);
+}
+
+static int mas_get(struct obex_session *os, obex_object_t *obj,
+ gboolean *stream, void *user_data)
+{
+ struct mas_session *mas = user_data;
+ const char *type = obex_get_type(os);
+ const char *name = obex_get_name(os);
+ int ret;
+
+ DBG("GET: name %s type %s mas %p",
+ name, type, mas);
+
+ if (type == NULL)
+ return -EBADR;
+
+ *stream = FALSE;
+
+ ret = obex_get_stream_start(os, name);
+ if (ret < 0)
+ goto fail;
+
+ return 0;
+fail:
+ return ret;
+}
+
+static int mas_put(struct obex_session *os, obex_object_t *obj, void *user_data)
+{
+ struct mas_session *mas = user_data;
+ const char *type = obex_get_type(os);
+ const char *name = obex_get_name(os);
+ int ret;
+
+ DBG("PUT: name %s type %s mas %p", name, type, mas);
+
+ if (type == NULL)
+ return -EBADR;
+
+ ret = obex_put_stream_start(os, name);
+ if (ret < 0)
+ goto fail;
+
+ return 0;
+fail:
+ return ret;
+}
+
+static int mas_setpath(struct obex_session *os, obex_object_t *obj,
+ void *user_data)
+{
+ const char *name;
+ uint8_t *nonhdr;
+
+ if (OBEX_ObjectGetNonHdrData(obj, &nonhdr) != 2) {
+ error("Set path failed: flag and constants not found!");
+ return -EBADR;
+ }
+
+ name = obex_get_name(os);
+
+ DBG("SETPATH: name %s nonhdr 0x%x%x", name, nonhdr[0], nonhdr[1]);
+
+ if ((nonhdr[0] & 0x02) != 0x02) {
+ DBG("Error: requested directory creation");
+ return -EBADR;
+ }
+
+ return 0;
+}
+static struct obex_service_driver mas = {
+ .name = "Message Access server",
+ .service = OBEX_MAS,
+ .channel = MAS_CHANNEL,
+ .record = MAS_RECORD,
+ .target = MAS_TARGET,
+ .target_size = TARGET_SIZE,
+ .connect = mas_connect,
+ .get = mas_get,
+ .put = mas_put,
+ .setpath = mas_setpath,
+ .disconnect = mas_disconnect,
+};
+
static int mas_init(void)
{
+ int err;
+
+ err = obex_service_driver_register(&mas);
+ if (err < 0)
+ goto fail_mas_reg;
+
return 0;
+
+fail_mas_reg:
+ return err;
}
static void mas_exit(void)
{
+ obex_service_driver_unregister(&mas);
}
OBEX_PLUGIN_DEFINE(mas, mas_init, mas_exit)
--
1.7.1
next prev parent reply other threads:[~2011-03-02 9:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-02 9:36 [PATCH 0/4] Message Access Profile plugin lkslawek
2011-03-02 9:36 ` [PATCH 1/4] Add skeleton for " lkslawek
2011-03-02 9:36 ` lkslawek [this message]
2011-03-10 11:14 ` [PATCH 2/4] Add actual service for Message Access Profile Johan Hedberg
2011-03-10 11:28 ` Slawomir Bochenski
2011-03-02 9:36 ` [PATCH 3/4] Add MIME driver to MAP plugin lkslawek
2011-03-02 9:36 ` [PATCH 4/4] Add detecting of MAP function in OBEX request lkslawek
2011-03-02 21:12 ` [PATCH 0/4] Message Access Profile plugin Luiz Augusto von Dentz
2011-03-03 9:58 ` Slawomir Bochenski
2011-03-03 11:25 ` Luiz Augusto von Dentz
2011-03-03 14:09 ` Slawomir Bochenski
2011-03-03 15:08 ` Luiz Augusto von Dentz
2011-03-03 15:20 ` Slawomir Bochenski
2011-03-03 19:54 ` Luiz Augusto von Dentz
2011-03-04 8:50 ` Slawomir Bochenski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299058614-8904-3-git-send-email-lkslawek@gmail.com \
--to=lkslawek@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox