From c61dc72f6c56b91f7d82838b85dc1c4debba202b Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Mon, 9 Jun 2008 18:51:04 +0000 Subject: [PATCH] - Add some traces - Register the protocol - Remove some AF_INET stuff Although step by step will become the L2CAP protocol implementation, for the moment is just a testing and learning code. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25884 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/network/protocols/l2cap/l2cap.cpp | 115 ++++++++++++++---- .../network/protocols/l2cap/l2cap_address.cpp | 15 +-- 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/l2cap/l2cap.cpp b/src/add-ons/kernel/network/protocols/l2cap/l2cap.cpp index c0caea3fff..096632aeb9 100644 --- a/src/add-ons/kernel/network/protocols/l2cap/l2cap.cpp +++ b/src/add-ons/kernel/network/protocols/l2cap/l2cap.cpp @@ -6,36 +6,38 @@ #include #include -#include #include #include #include #include + +#include "l2cap_address.h" + + +#define BT_DEBUG_THIS_MODULE #include -typedef NetBufferField ICMPChecksumField; +typedef NetBufferField AclLenField; -#define ICMP_TYPE_ECHO_REPLY 0 -#define ICMP_TYPE_UNREACH 3 -#define ICMP_TYPE_REDIRECT 5 -#define ICMP_TYPE_ECHO_REQUEST 8 - -// type unreach codes -#define ICMP_CODE_UNREACH_NEED_FRAGMENT 4 // this is used for path MTU discovery struct l2cap_protocol : net_protocol { }; +extern net_protocol_module_info gL2CAPModule; + net_buffer_module_info *gBufferModule; static net_stack_module_info *sStackModule; +static struct net_domain *sDomain; net_protocol * l2cap_init_protocol(net_socket *socket) { + flowf("\n"); + l2cap_protocol *protocol = new (std::nothrow) l2cap_protocol; if (protocol == NULL) return NULL; @@ -47,6 +49,8 @@ l2cap_init_protocol(net_socket *socket) status_t l2cap_uninit_protocol(net_protocol *protocol) { + flowf("\n"); + delete protocol; return B_OK; } @@ -55,6 +59,8 @@ l2cap_uninit_protocol(net_protocol *protocol) status_t l2cap_open(net_protocol *protocol) { + flowf("\n"); + return B_OK; } @@ -62,6 +68,8 @@ l2cap_open(net_protocol *protocol) status_t l2cap_close(net_protocol *protocol) { + flowf("\n"); + return B_OK; } @@ -69,6 +77,8 @@ l2cap_close(net_protocol *protocol) status_t l2cap_free(net_protocol *protocol) { + flowf("\n"); + return B_OK; } @@ -76,6 +86,8 @@ l2cap_free(net_protocol *protocol) status_t l2cap_connect(net_protocol *protocol, const struct sockaddr *address) { + flowf("\n"); + return B_ERROR; } @@ -83,6 +95,8 @@ l2cap_connect(net_protocol *protocol, const struct sockaddr *address) status_t l2cap_accept(net_protocol *protocol, struct net_socket **_acceptedSocket) { + flowf("\n"); + return EOPNOTSUPP; } @@ -91,8 +105,10 @@ status_t l2cap_control(net_protocol *protocol, int level, int option, void *value, size_t *_length) { - return protocol->next->module->control(protocol->next, level, option, - value, _length); + flowf("\n"); + +/* return protocol->next->module->control(protocol->next, level, option, value, _length); */ + return EOPNOTSUPP; } @@ -100,8 +116,10 @@ status_t l2cap_getsockopt(net_protocol *protocol, int level, int option, void *value, int *length) { - return protocol->next->module->getsockopt(protocol->next, level, option, - value, length); + flowf("\n"); + +/* return protocol->next->module->getsockopt(protocol->next, level, option, value, length); */ + return EOPNOTSUPP; } @@ -109,14 +127,18 @@ status_t l2cap_setsockopt(net_protocol *protocol, int level, int option, const void *value, int length) { - return protocol->next->module->setsockopt(protocol->next, level, option, - value, length); + flowf("\n"); + +/* return protocol->next->module->setsockopt(protocol->next, level, option, value, length); */ + return EOPNOTSUPP; } status_t l2cap_bind(net_protocol *protocol, const struct sockaddr *address) { + flowf("\n"); + return B_ERROR; } @@ -124,6 +146,8 @@ l2cap_bind(net_protocol *protocol, const struct sockaddr *address) status_t l2cap_unbind(net_protocol *protocol, struct sockaddr *address) { + flowf("\n"); + return B_ERROR; } @@ -131,6 +155,8 @@ l2cap_unbind(net_protocol *protocol, struct sockaddr *address) status_t l2cap_listen(net_protocol *protocol, int count) { + flowf("\n"); + return EOPNOTSUPP; } @@ -138,6 +164,8 @@ l2cap_listen(net_protocol *protocol, int count) status_t l2cap_shutdown(net_protocol *protocol, int direction) { + flowf("\n"); + return EOPNOTSUPP; } @@ -145,6 +173,8 @@ l2cap_shutdown(net_protocol *protocol, int direction) status_t l2cap_send_data(net_protocol *protocol, net_buffer *buffer) { + flowf("\n"); + return protocol->next->module->send_data(protocol->next, buffer); } @@ -153,6 +183,8 @@ status_t l2cap_send_routed_data(net_protocol *protocol, struct net_route *route, net_buffer *buffer) { + flowf("\n"); + return protocol->next->module->send_routed_data(protocol->next, route, buffer); } @@ -160,6 +192,8 @@ l2cap_send_routed_data(net_protocol *protocol, struct net_route *route, ssize_t l2cap_send_avail(net_protocol *protocol) { + flowf("\n"); + return B_ERROR; } @@ -168,6 +202,8 @@ status_t l2cap_read_data(net_protocol *protocol, size_t numBytes, uint32 flags, net_buffer **_buffer) { + flowf("\n"); + return B_ERROR; } @@ -175,6 +211,8 @@ l2cap_read_data(net_protocol *protocol, size_t numBytes, uint32 flags, ssize_t l2cap_read_avail(net_protocol *protocol) { + flowf("\n"); + return B_ERROR; } @@ -182,13 +220,17 @@ l2cap_read_avail(net_protocol *protocol) struct net_domain * l2cap_get_domain(net_protocol *protocol) { - return protocol->next->module->get_domain(protocol->next); + flowf("\n"); + + return sDomain; } size_t l2cap_get_mtu(net_protocol *protocol, const struct sockaddr *address) { + flowf("\n"); + return protocol->next->module->get_mtu(protocol->next, address); } @@ -196,7 +238,7 @@ l2cap_get_mtu(net_protocol *protocol, const struct sockaddr *address) status_t l2cap_receive_data(net_buffer *buffer) { - debugf("ICMP received some data, buffer length %lu\n", buffer->size); + debugf("received some data, buffer length %lu\n", buffer->size); NetBufferHeaderReader bufferHeader(buffer); if (bufferHeader.Status() < B_OK) @@ -204,7 +246,7 @@ l2cap_receive_data(net_buffer *buffer) hci_acl_header &header = bufferHeader.Data(); - debugf(" got type %u, code %u, checksum %u\n", header.type, header.code, ntohs(header.checksum)); + debugf(" got handle %u, len %u\n", header.handle, header.alen); debugf(" computed checksum: %ld\n", gBufferModule->checksum(buffer, 0, buffer->size, true)); if (gBufferModule->checksum(buffer, 0, buffer->size, true) != 0) @@ -218,6 +260,8 @@ l2cap_receive_data(net_buffer *buffer) status_t l2cap_error(uint32 code, net_buffer *data) { + flowf("\n"); + return B_ERROR; } @@ -226,29 +270,52 @@ status_t l2cap_error_reply(net_protocol *protocol, net_buffer *causedError, uint32 code, void *errorData) { + flowf("\n"); + return B_ERROR; } -// #pragma mark - - +#if 0 +#pragma mark - +#endif static status_t l2cap_std_ops(int32 op, ...) { + flowf("\n"); + switch (op) { case B_MODULE_INIT: { - sStackModule->register_domain_protocols(AF_INET, SOCK_DGRAM, IPPROTO_ICMP, + status_t error; + + error = sStackModule->register_domain_protocols(AF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_L2CAP, "network/protocols/l2cap/v1", NULL); + if (error != B_OK) { + return error; + } - sStackModule->register_domain_receiving_protocol(AF_INET, IPPROTO_ICMP, + error = sStackModule->register_domain_receiving_protocol(AF_BLUETOOTH, BLUETOOTH_PROTO_L2CAP, "network/protocols/l2cap/v1"); + if (error != B_OK) { + return error; + } + + error = sStackModule->register_domain(AF_BLUETOOTH, "l2cap", &gL2CAPModule, + &gL2cap4AddressModule, &sDomain); + if (error != B_OK) { + return error; + } + + return B_OK; } case B_MODULE_UNINIT: + + sStackModule->unregister_domain(sDomain); return B_OK; default: @@ -257,7 +324,7 @@ l2cap_std_ops(int32 op, ...) } -net_protocol_module_info sL2CAPModule = { +net_protocol_module_info gL2CAPModule = { { "network/protocols/l2cap/v1", 0, @@ -299,6 +366,6 @@ module_dependency module_dependencies[] = { }; module_info *modules[] = { - (module_info *)&sL2CAPModule, + (module_info *)&gL2CAPModule, NULL }; diff --git a/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp b/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp index a42db22022..58a5197068 100644 --- a/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp +++ b/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #define L2CAP_CHECKSUM(address) (address.b[0]+\ @@ -36,7 +37,7 @@ result of \a from & \a mask). \return B_OK if the address could be copied \return B_NO_MEMORY if the new address could not be allocated - \return B_MISMATCHED_VALUES if \a address does not match family AF_INET + \return B_MISMATCHED_VALUES if \a address does not match family AF_BLUETOOTH */ static status_t l2cap_copy_address(const sockaddr *from, sockaddr **to, @@ -47,13 +48,13 @@ l2cap_copy_address(const sockaddr *from, sockaddr **to, if (*to == NULL) return B_NO_MEMORY; - memset(*to, 0, sizeof(sockaddr_in)); - (*to)->sa_family = AF_INET; - (*to)->sa_len = sizeof(sockaddr_in); + memset(*to, 0, sizeof(sockaddr_l2cap)); + (*to)->sa_family = AF_BLUETOOTH; + (*to)->sa_len = sizeof(sockaddr_l2cap); } else { if (from == NULL) return B_OK; - if (from->sa_family != AF_INET) + if (from->sa_family != AF_BLUETOOTH) return B_MISMATCHED_VALUES; *to = (sockaddr *)malloc(sizeof(sockaddr_in)); @@ -285,7 +286,7 @@ l2cap_set_port(sockaddr *address, uint16 port) Sets \a address to \a from. \return B_OK if \a from has been copied into \a address \return B_BAD_VALUE if either \a address or \a from is NULL - \return B_MISMATCHED_VALUES if from is not of family AF_INET + \return B_MISMATCHED_VALUES if from is not of family AF_BLUETOOTH */ static status_t l2cap_set_to(sockaddr *address, const sockaddr *from) @@ -314,7 +315,7 @@ l2cap_update_to(sockaddr *_address, const sockaddr *_from) if (from->l2cap_family != AF_BLUETOOTH) return B_BAD_VALUE; - address->l2cap_family = AF_INET; + address->l2cap_family = AF_BLUETOOTH; address->l2cap_len = sizeof(sockaddr_l2cap); if (address->l2cap_psm == 0)