102 lines
2.4 KiB
C
Raw Permalink Normal View History

/*
* Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _BTCOREDATA_H
#define _BTCOREDATA_H
#include <module.h>
#include <lock.h>
#include <util/DoublyLinkedList.h>
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
#include <util/VectorMap.h>
#include <net_datalink.h>
#include <net/if_dl.h>
#include <net_buffer.h>
#include <net_device.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/HCI/btHCI.h>
#include <bluetooth/HCI/btHCI_transport.h>
#include <l2cap.h>
#define BT_CORE_DATA_MODULE_NAME "bluetooth/btCoreData/v1"
typedef enum _connection_status {
HCI_CONN_CLOSED,
HCI_CONN_OPEN,
} connection_status;
#ifdef __cplusplus
struct HciConnection : DoublyLinkedListLinkImpl<HciConnection> {
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
HciConnection(hci_id hid);
virtual ~HciConnection();
hci_id Hid;
bluetooth_device* ndevice;
bdaddr_t destination;
uint16 handle;
int type;
uint16 mtu;
connection_status status;
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
net_buffer* currentRxPacket;
ssize_t currentRxExpectedLength;
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
struct net_interface_address interface_address;
struct sockaddr_dl address_dl;
struct sockaddr_storage address_dest;
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
void (*disconnect_hook)(HciConnection*);
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
public:
mutex fLock;
uint8 fNextIdent;
VectorMap<uint8, void*> fInUseIdents;
};
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
#else
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
struct HciConnection;
#endif
struct bluetooth_core_data_module_info {
module_info info;
status_t (*PostEvent)(bluetooth_device* ndev, void* event,
size_t size);
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
// FIXME: We really shouldn't be passing out connection pointers at all...
struct HciConnection* (*AddConnection)(uint16 handle, int type,
const bdaddr_t& dst, hci_id hid);
// status_t (*RemoveConnection)(bdaddr_t destination, hci_id hid);
status_t (*RemoveConnection)(uint16 handle, hci_id hid);
hci_id (*RouteConnection)(const bdaddr_t& destination);
struct HciConnection* (*ConnectionByHandle)(uint16 handle, hci_id hid);
struct HciConnection* (*ConnectionByDestination)(
const bdaddr_t& destination, hci_id hid);
L2CAP: Major refactor of the whole component. (And surrounding portions of the "btCoreData" module.) * Rewrote the main "l2cap.h" header representing protocol constants and structures. Now conforms to general Haiku naming conventions rather than BSD ones. Some more constants added/removed based on the most recent Bluetooth specification. * Rewrote all code derived from the BSDs to match Haiku conventions and structures in the driver. * Dropped the "channel" and "frame" structures from "btCoreData". Channels are now managed by L2capEndpoints, and "frames" are now just plain net_buffers without surrounding structures. This also makes state management much simpler. * Made it so that actual net_buffers are passed through to the l2cap_receive function rather than another data structure. A fake interface address is used to communicate connection information. (This probably ought to be changed, though.) * Get rid of l2cap_lower and l2cap_upper abstractions. Everything related to channel/endpoint management is now done in L2capEndpoint, while buffer reception is handled directly in l2cap_receive and elsewhere, same as other drivers. * Wire up more hooks and fix module flags (needed to be able to get the module loaded and opening sockets at all.) * Implement an actual locking strategy in L2capEndpoint and HciConnection. There's still problems with lifetime management, but at least thread-safety is mostly handled. * Create an L2capEndpointManager and use it to manage the endpoints, rather than having a single (unsafe) linked-list. And plenty of other refactorings and cleanups besides. There's still more to be done for Bluetooth overall, though: * The "btCoreData" and "hci" modules also badly need a major overhaul, and should be merged into a single "bluetooth" bus_manager. They also shouldn't be passing around pointers to other modules like this. * There's a number of TODOs/FIXMEs in the L2CAP module, most notably around timeouts (especially command timeouts) and parameter validation/specification. Tested by myself with kallisti5's help. Incoming connections (on the PSM for SDP) get all the way to the latter half of the Configuration step before hanging.
2024-04-26 16:22:39 -04:00
uint8 (*allocate_command_ident)(struct HciConnection* conn, void* associated);
void* (*lookup_command_ident)(struct HciConnection* conn, uint8 ident);
void (*free_command_ident)(struct HciConnection* conn, uint8 ident);
};
inline bool ExistConnectionByDestination(const bdaddr_t& destination,
hci_id hid);
inline bool ExistConnectionByHandle(uint16 handle, hci_id hid);
#endif // _BTCOREDATA_H