btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / add-ons / kernel / bluetooth / btCoreData / FrameInterface.cpp
blob343952cf167fe48115cc84df6db982d0dc26d4d1
1 /*
2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "FrameInterface.h"
8 #include <btDebug.h>
10 #include <lock.h>
13 L2capFrame*
14 SignalByIdent(HciConnection* conn, uint8 ident)
16 L2capFrame* frame;
18 mutex_lock(&conn->fLockExpected);
19 DoublyLinkedList<L2capFrame>::Iterator iterator
20 = conn->ExpectedResponses.GetIterator();
22 while (iterator.HasNext()) {
24 frame = iterator.Next();
25 if (frame->type == L2CAP_C_FRAME && frame->ident == ident) {
26 mutex_unlock(&frame->conn->fLockExpected);
27 return frame;
31 mutex_unlock(&conn->fLockExpected);
33 return NULL;
37 status_t
38 TimeoutSignal(L2capFrame* frame, uint32 timeo)
40 if (frame != NULL)
41 return B_OK;
43 return B_ERROR;
47 status_t
48 unTimeoutSignal(L2capFrame* frame)
50 if (frame != NULL)
51 return B_OK;
53 return B_ERROR;
57 L2capFrame*
58 SpawmFrame(HciConnection* conn, L2capChannel* channel, net_buffer* buffer,
59 frame_type type)
61 if (buffer == NULL)
62 panic("Null Buffer to outgoing queue");
64 L2capFrame* frame = new (std::nothrow) L2capFrame;
66 frame->conn = conn;
67 frame->channel = channel; // TODO: maybe only scid needed
69 frame->buffer = buffer;
70 frame->type = type;
72 mutex_lock(&conn->fLock);
74 conn->OutGoingFrames.Add(frame, true);
76 mutex_unlock(&conn->fLock);
78 return frame;
82 L2capFrame*
83 SpawmSignal(HciConnection* conn, L2capChannel* channel, net_buffer* buffer,
84 uint8 ident, uint8 code)
86 if (buffer == NULL)
87 panic("Null Buffer to outgoing queue");
89 L2capFrame* frame = new (std::nothrow) L2capFrame;
91 frame->conn = conn;
92 frame->channel = channel; // TODO: not specific descriptor should be required
94 frame->buffer = buffer;
95 frame->type = L2CAP_C_FRAME;
96 frame->ident = ident;
97 frame->code = code;
99 mutex_lock(&conn->fLock);
101 conn->OutGoingFrames.Add(frame, true);
103 mutex_unlock(&conn->fLock);
105 return frame;
109 status_t
110 AcknowledgeSignal(L2capFrame* frame)
113 if (frame != NULL) {
115 if (frame->type == L2CAP_C_FRAME) {
116 HciConnection* connection = frame->conn;
118 unTimeoutSignal(frame);
119 mutex_lock(&connection->fLockExpected);
120 connection->ExpectedResponses.Remove(frame);
121 mutex_unlock(&connection->fLockExpected);
124 // NO! This will be deleted by lower layers while being sent!
125 // gBufferModule->free(frame->buffer);
126 delete frame;
128 return B_OK;
131 return B_ERROR;
135 status_t
136 QueueSignal(L2capFrame* frame)
138 if (frame != NULL) {
140 if (frame->type == L2CAP_C_FRAME) {
141 mutex_lock(&frame->conn->fLockExpected);
142 frame->conn->ExpectedResponses.Add(frame);
143 mutex_unlock(&frame->conn->fLockExpected);
144 return B_OK;
148 return B_ERROR;