-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
FrameInterface.cpp
149 lines (103 loc) · 2.63 KB
/
FrameInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "FrameInterface.h"
#include <btDebug.h>
#include <lock.h>
L2capFrame*
SignalByIdent(HciConnection* conn, uint8 ident)
{
L2capFrame* frame;
mutex_lock(&conn->fLockExpected);
DoublyLinkedList<L2capFrame>::Iterator iterator
= conn->ExpectedResponses.GetIterator();
while (iterator.HasNext()) {
frame = iterator.Next();
if (frame->type == L2CAP_C_FRAME && frame->ident == ident) {
mutex_unlock(&frame->conn->fLockExpected);
return frame;
}
}
mutex_unlock(&conn->fLockExpected);
return NULL;
}
status_t
TimeoutSignal(L2capFrame* frame, uint32 timeo)
{
if (frame != NULL)
return B_OK;
return B_ERROR;
}
status_t
unTimeoutSignal(L2capFrame* frame)
{
if (frame != NULL)
return B_OK;
return B_ERROR;
}
L2capFrame*
SpawmFrame(HciConnection* conn, L2capChannel* channel, net_buffer* buffer,
frame_type type)
{
if (buffer == NULL)
panic("Null Buffer to outgoing queue");
L2capFrame* frame = new (std::nothrow) L2capFrame;
frame->conn = conn;
frame->channel = channel; // TODO: maybe only scid needed
frame->buffer = buffer;
frame->type = type;
mutex_lock(&conn->fLock);
conn->OutGoingFrames.Add(frame, true);
mutex_unlock(&conn->fLock);
return frame;
}
L2capFrame*
SpawmSignal(HciConnection* conn, L2capChannel* channel, net_buffer* buffer,
uint8 ident, uint8 code)
{
if (buffer == NULL)
panic("Null Buffer to outgoing queue");
L2capFrame* frame = new (std::nothrow) L2capFrame;
frame->conn = conn;
frame->channel = channel; // TODO: not specific descriptor should be required
frame->buffer = buffer;
frame->type = L2CAP_C_FRAME;
frame->ident = ident;
frame->code = code;
mutex_lock(&conn->fLock);
conn->OutGoingFrames.Add(frame, true);
mutex_unlock(&conn->fLock);
return frame;
}
status_t
AcknowledgeSignal(L2capFrame* frame)
{
if (frame != NULL) {
if (frame->type == L2CAP_C_FRAME) {
HciConnection* connection = frame->conn;
unTimeoutSignal(frame);
mutex_lock(&connection->fLockExpected);
connection->ExpectedResponses.Remove(frame);
mutex_unlock(&connection->fLockExpected);
}
// NO! This will be deleted by lower layers while being sent!
// gBufferModule->free(frame->buffer);
delete frame;
return B_OK;
}
return B_ERROR;
}
status_t
QueueSignal(L2capFrame* frame)
{
if (frame != NULL) {
if (frame->type == L2CAP_C_FRAME) {
mutex_lock(&frame->conn->fLockExpected);
frame->conn->ExpectedResponses.Add(frame);
mutex_unlock(&frame->conn->fLockExpected);
return B_OK;
}
}
return B_ERROR;
}