Receiving connection-less multi-hop data packets is the same as receiving point-to-point data packets: higher layer services have to register a service routine together with a PSM identifier at the protocol/service multiplexor (see bt_psm_service_register, l2cap_cl.h).
Routing is done by broadcasting packets: Each node receiving a broadcast packet stores the source node's address together with the connection handle the packet was received on in the forwarding table.
Incoming packets having a target address that matches one of the entries in the forwarding table are then forwarded directely over the corresponding connection handle.
|Forwarding table entry. More...|
|Packet shall be broadcasted. |
|infinite time to live |
|Packet shall be forwarded if possible. |
|Packet send error: no corresponding entry found in the forwarding table. |
|If amount of data to send is too big. |
Forwarding Table Events
|A new source has been added to the forwarding table. |
|A source has been deleted from the forwarding table. |
|#define||MHOP_CL_FWTABLE_CB void (*fwt_cb) (mhop_cl_fwt_entry* entry, u_char type, void* cb_arg)|
|Forwarding table changed callback. |
|Forwarding table entry. |
|void||mhop_cl_fwt_register_cb (MHOP_CL_FWTABLE_CB, void *cb_arg)|
|To register the forwarding table change callback. |
|u_char *||mhop_cl_get_my_addr (void)|
|Returns the bluetooth address of this device. |
|Returns the maximal amount of data that can be sent within a single multi-hop packet. |
|void||mhop_cl_register_con_table_cb (HCI_CON_TABLE_CB, void *cb_arg)|
Forwarding Table Accessors
|mhop_cl_fwt_entry *||mhop_cl_fwt_get_entry (bt_addr_t addr)|
|int||mhop_cl_fwt_update (bt_addr_t src_addr, bt_hci_con_handle_t src_handle, u_char src_seq, u_char distance)|
|Updates the forwarding table. |
|u_char *||mhop_cl_get_source_addr (struct bt_hci_pkt_acl *pkt)|
|Returns the source address of a received packet. |
|u_char *||mhop_cl_get_target_addr (struct bt_hci_pkt_acl *pkt)|
|Returns the target address of an received packet. |
|void||mhop_cl_init (struct btstack *bt_stack, bt_psm_t *psmux, u_short psm, u_short buf_size, HCI_CON_TABLE_CB_REGISTRATION)|
|Initializes the connection-less multi-hop layer. |
Sending multi-hop packets
|long||mhop_cl_send_pkt (u_char *data, u_short len, bt_addr_t dest, u_short psm, u_char bc_flag, u_char ttl)|
|Sends a multi-hop packet to a service on a remote device. |
|long||mhop_cl_send_src_del_pkt (bt_addr_t addr, u_char ttl)|
|broadcasts a source deletion packet |
Forwarding table entry.
When receiving a connectionless l2cap packet containing a multi-hop information trailer whos "source record" flag is set (see typedef mhop_cl_mhop_ctrl_info), the address of the sender will be stored in the forwarding table.
Essentially, an entry in the forwarding table consists of the address of the source node, and the connection handle over which the source node can be reached.
Returns the forwarding table entry associated with the passed device address.
Scans the forwarding table for an entry containing the destination address
dest and returns it.
|addr||Address of the desired destination node|
To register the forwarding table change callback.
This function registers the forwarding table change callback function which is called each time a source has been added to / removed from the forwarding table.
|MHOP_CL_FWTABLE_CB||Function-Pointer to the callback|
|cb_arg||Some callback argument which is passed to the registering layer each time the callback is called|
Updates the forwarding table.
|src_addr||Address of the source|
|src_handle||Handle pkt was received from|
|src_seq||Sequence number of the source broadcast|
|ttl||time to live of the source broadcast|
|distance||Distance to the source|
Returns the bluetooth address of this device.
TODO: move this function to bt_hci.c
|void mhop_cl_init||(||struct btstack *||bt_stack,|
Initializes the connection-less multi-hop layer.
|stack||Pointer to the bt stack to use|
|psmux||Pointer to the protocol/service multiplexor|
|mhop_psm||PSM the multi-hop layer should use|
|buf_size||Nr of buffers used for buffering packets that have to be forwarded|
|HCI_CON_TABLE_CB_REGISTRATION||defines where the mhop layer has to register its callback function that handles changes in the connection table.|
|long mhop_cl_send_pkt||(||u_char *||data,|
Sends a multi-hop packet to a service on a remote device.
This function sends a data packet to a service on a remote device - if necessary via several relay hops.
Set the broadcast flag
bc_flag to specify if the packet shall be broadcasted or not:
destdelivers the packet to the application layer.
destdelivers the packet to the application layer.
dest = bt_addr_null, _all_ devices receiving the packet do deliver the packet to the application layer.
|data||Pointer to the data to send|
|len||Amount of data to send|
|dest||BT address of the destination|
|psm||Identifies the service the data shall be delivered to on the receiving side|
|bc_flag||Determines if the packet should be broadcasted or not|
|ttl||Maximal time to live for the packet - pass TTL_INFINITE for inifinite time to live|
u_char data; strcpy(data, "hello world"); mhop_cl_send_pkt(data, 12, <target_addr>, <target_psm>, MHOP_CL_BROADCAST, 5);
u_char data; strcpy(data, "fifa world cup 2006"); mhop_cl_send_pkt(data, 20, <target_addr>, <target_psm>, MHOP_CL_UNICAST, MHOP_CL_TTL_INFINITE);
u_char data; strcpy(data, "hello world"); mhop_cl_send_pkt(data, 12, bt_addr_null, <target_psm>, MHOP_CL_BROADCAST, MHOP_CL_TTL_INFINITE);
broadcasts a source deletion packet
Sends an packet indicating that the device with addr
addr should be cleared from the forwarding table.
Note: the packet is broadcasted, that is every node in the network deletes the device with addr
addr from the forwarding table.
|addr||BT address of the device to be deleted|
|ttl||Maximal time to live for this source deletion packet|