I'm glad to announce that RFCOMM is now officially part of BTstack.
So what does this mean?
in the example folder, there are two RFCOMM examples: rfcomm-cat to connect to a remote RFCOMM port and listen for data, and rfcomm-echo, which sets up an SDP record for an SPP serial port and waits for incoming RFCOMM connections.
The API for RFCOMM is similar to the one for L2CAP. See include/hci_cmds.h with explanation in src/hci_cmds.h (I've pasted it at the end, too...)
Some notes:
* As BTstack API is rather minimal, in some cases, the HCI handle for an RFCOMM channel is required, e.g. to set up a new link key. Because of this, I plan to add this handle to the RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE event. The current code in SVN matches the latest BTstack-0.3-50x release in Cydia. I'll release the next update of BTstack when Celeste 1.0 is ready (to not break Celeste 0.9 yet).
* The RFCOMM engine provides flow control information via the RFCOMM_EVENT_CREDITS event. Please don't send more RFCOMM packets than you've got from BTstack.
* To set up an RFCOMM service for incoming connections, you use the rfcomm_register_service command. As BTstack must handle multiple clients, you have to specify a "registration id" instead of an actual RFCOMM service ID. In the RFCOMM_EVENT_SERVICE_REGISTERED, BTstack returns the assigned service ID which then can be used. See example/rfcomm-cat.c for an example on this
I just realized that the on-demand assignment (last note) will require another device to query SDP each time. Also this works fine for OBEX, it fails for other uses, so this will need some more thought. The problem is: "how can RFCOMM channels get assigned to independent entities without creating a collision?". The most obvious approach would probably be to add a "register RFCOMM channel for life" and/or have BTdaemon keep track of all assigned RFCOMM channels...
Anyway, please have a look at the current version and get started with the new RFCOMM!
Best
Matthias
------- API ------
/// COMMANDS
// create rfcomm channel: @param bd_addr(48), channel (8)
const hci_cmd_t rfcomm_create_channel = {
OPCODE(OGF_BTSTACK, RFCOMM_CREATE_CHANNEL), "B1"
};
// disconnect rfcomm disconnect, @param rfcomm_cid(8), reason(8)
const hci_cmd_t rfcomm_disconnect = {
OPCODE(OGF_BTSTACK, RFCOMM_DISCONNECT), "21"
};
// register rfcomm service: @param registration id(16), mtu (16)
const hci_cmd_t rfcomm_register_service = {
OPCODE(OGF_BTSTACK, RFCOMM_REGISTER_SERVICE), "22"
};
// unregister rfcomm service, @param service_channel(16)
const hci_cmd_t rfcomm_unregister_service = {
OPCODE(OGF_BTSTACK, RFCOMM_UNREGISTER_SERVICE), "2"
};
// accept connection @param bd_addr(48), rfcomm_cid (16)
const hci_cmd_t rfcomm_accept_connection = {
OPCODE(OGF_BTSTACK, RFCOMM_ACCEPT_CONNECTION), "2"
// @param source cid (16)
};
// decline rfcomm disconnect,@param bd_addr(48), rfcomm cid (16), reason(8)
const hci_cmd_t rfcomm_decline_connection = {
OPCODE(OGF_BTSTACK, RFCOMM_DECLINE_CONNECTION), "21"
// @param source cid (16), reason(8)
};
// RFCOMM EVENTS
// The current BTstack-0.3-50x in Cydia uses
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
// The SVN version and the next update will use
// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
// status: 0 = OK
#define RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE 0x80
// data: event(8), len(8), channelID(8)
// status: 0 = OK
#define RFCOMM_EVENT_CHANNEL_CLOSED 0x81
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
#define RFCOMM_EVENT_INCOMING_CONNECTION 0x82
// data: event (8), len(8), rfcommid (16), ...
#define RFCOMM_EVENT_REMOTE_LINE_STATUS 0x83
// data: event(8), len(8), local_cid(16), credits(8)
#define RFCOMM_EVENT_CREDITS 0x84
// data: event(8), len(8), status (8), registration id(16), rfcomm server channel id (8)
#define RFCOMM_EVENT_SERVICE_REGISTERED 0x85
best
Matthias
Begin forwarded message:
RFCOMM is the same as Serial port over bluetooth? Is btstack ready to
implement Serial por over bluetooth for cheap and simple embedded
systems as Arduino/AVR?
good point. I spent about 10 minutes preparing & testing rfcomm-echo... :)
You're right about the incorrect service name len, but why isn't it "browsable"? I tried once on the Mac: pairing, service discovery, setup virtual serial port, test with minicom. worked fine.
best
matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To post to this group, send email to btsta...@googlegroups.com.
> To unsubscribe from this group, send email to btstack-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/btstack-dev?hl=en.
>
no problem. I didn't forget that one though (but maybe in the first commit) ... -> http://code.google.com/p/btstack/source/browse/trunk/example/rfcomm-echo.c#168
Best,
Matthias
> Is the BTstack-0.3-50x releae already available in Cydia?
ah. my version numbers got mixed up. The latest version in Cydia is 0.3-434 (http://apt.thebigboss.org/onepackage.php?bundleid=ch.ringwald.btstack&db=) and I was actually referring to that one instead. So replace 50x with 434 in my mail. There won't be a 50x in Cydia ever as the btstack.org SVN revisions are > 1000 or so.
Best
Matthias
The mapping from service name to rfcomm channel is currently done by the remote_device_db - not very obvious, but it made sense to combine this functionality as both use persisten date, I just need to rename the remove_device_db into e.g. preferences or so.
If you already started with RFCOMM, please look at the changes for the RFCOMM examples. If not, please be aware that the current SVN version isn't compatible with the one in Cydia (for now - working on Celeste update).
Best
the Bluetooth module generates a lot of HCI_EVENT_PACKET and a bunch of them are handled by BTdaemon but also forwarded to the client app, that's fine so far.
the rfcomm-cat example gave me data from my GPS as RFCOMM_DATA_PACKETs the last time I tried. Does the other side send data? :)
please check out /tmp/hci_dump.pklg on your iPhone (copy to mac and use PacketLogger or Wireshark on all other platforms) and post it here.
Best
Matthias
in your log, this line isn't good:
[13:22:30.031] [RFCOMM RECEIVE] DM for channel 0
My guess is that the RFCOMM channel you've specified doesn't exist. channels are from 1-31.
I can have a quick look at packet log, but please provide them in PacketLogger or hcidump format, the textual representation like below lacks almost all information.
Best
Matthias
You basically do the same with the mbw-150 using BTstack as you would with another Bluetooth Stack. I actually would suggest to first play around on a desktop computer using the BlueCove JSR82 implementation in Java - there are some python bindings as well.
As people have been asking for RFCOMM server functionality for long, I suspect that the mbw-150 is the one to open an RFCOMM connection and not the other way round. I guess you should read the clock's manual. :)
Best
Matthias
--
You received this message because you are subscribed to the Google Groups "btstack-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
To post to this group, send email to btsta...@googlegroups.com.
Visit this group at http://groups.google.com/group/btstack-dev.
For more options, visit https://groups.google.com/d/optout.