2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
5 #ifndef L2CAP_ENDPOINT_H
6 #define L2CAP_ENDPOINT_H
11 #include <util/DoublyLinkedList.h>
12 #include <util/OpenHashTable.h>
14 #include <net_protocol.h>
15 #include <net_socket.h>
16 #include <ProtocolUtilities.h>
18 #include "l2cap_internal.h"
20 extern net_stack_module_info
* gStackModule
;
22 class L2capEndpoint
: public net_protocol
,
23 public ProtocolSocket
,
24 public DoublyLinkedListLinkImpl
<L2capEndpoint
> {
27 L2capEndpoint(net_socket
* socket
);
28 virtual ~L2capEndpoint();
39 return mutex_lock(&fLock
) == B_OK
;
47 status_t
Bind(const struct sockaddr
* _address
);
49 status_t
Listen(int backlog
);
50 status_t
Connect(const struct sockaddr
* address
);
51 status_t
Accept(net_socket
** _acceptedSocket
);
53 ssize_t
Send(const iovec
* vecs
, size_t vecCount
,
54 ancillary_data_container
* ancillaryData
);
55 ssize_t
Receive(const iovec
* vecs
, size_t vecCount
,
56 ancillary_data_container
** _ancillaryData
,
57 struct sockaddr
* _address
, socklen_t
* _addressLength
);
59 ssize_t
ReadData(size_t numBytes
, uint32 flags
, net_buffer
** _buffer
);
60 ssize_t
SendData(net_buffer
* buffer
);
64 status_t
SetReceiveBufferSize(size_t size
);
65 status_t
GetPeerCredentials(ucred
* credentials
);
67 status_t
Shutdown(int direction
);
69 void BindNewEnpointToChannel(L2capChannel
* channel
);
70 void BindToChannel(L2capChannel
* channel
);
71 status_t
MarkEstablished();
72 status_t
MarkClosed();
74 static L2capEndpoint
* ForPsm(uint16 psm
);
76 bool RequiresConfiguration()
78 return fConfigurationSet
;
81 ChannelConfiguration fConfiguration
;
82 bool fConfigurationSet
;
83 net_fifo fReceivingFifo
;
87 // establishing a connection
94 // peer closes the connection
96 WAIT_FOR_FINISH_ACKNOWLEDGE
,
98 // we close the connection
107 sem_id fEstablishSemaphore
;
108 L2capEndpoint
* fPeerEndpoint
;
109 L2capChannel
* fChannel
;
114 extern DoublyLinkedList
<L2capEndpoint
> EndpointList
;
116 #endif // L2CAP_ENDPOINT_H