Commit Graph

226 Commits

Author SHA1 Message Date
Peter Hurley
5d88d8d690 avdtp: fix race condition when starting a stream
The AVDTP spec allows for a race condition between remote and local
device when issuing an AVDTP_START cmd on a stream in the OPEN state.

However, the internal state must continue to be consistent. For example,
suppose that avdtp_start() has been called while in the OPEN state and
a AVDTP_START cmd is sent.  Now before we have received a response (and
thus entered the STREAMING state), we *receive* a START cmd. Prior to
this fix, since the sep is still in the OPEN state, we would accept
the new START cmd. This will leads us to send both a Start_Ind and
Start_Cfm - not good.

Now, we track this transitional state (starting == TRUE).

NB - 'starting' is only in a valid state while the sep is in the
OPEN state. 'starting' is reset when we return to the OPEN state.
2011-07-10 10:55:19 +03:00
Lucas De Marchi
fcb426c76a Fix common misspelled words
Accounting of misspelled words, as detected by codespell:

acording      2
ancilliary    1
appropiate    1
atribute      1
cant          1
comming       2
gracefull     1
lenght        1
mispelled     1
occured       1
occurences    1
ocurred       3
prefered      1
presense      1
reponse       1
seperate      1
succesful     1
successully   1
sucessfull    1
sucessfully   1
2011-07-03 14:36:14 +03:00
Luiz Augusto von Dentz
8306448148 Make use of g_slist_free_full on audio plugin 2011-06-30 14:38:59 +03:00
Peter Hurley
9a653953dc Fix finalize discovery if all stream end points are In Use
When handling the discover response, if all stream end points are
in use, then we must finalize discovery, as no GET_CAPABILITIES
command will be issued.
2011-06-28 11:05:04 +03:00
Rafal Michalski
b70fae3807 Fix invalid memory access issues in AVDTP module
Changing stream state from STREAMING to IDLE can be associated with side
effects under some circumstances (such as terminating bluetoothd during
music is streamed). In this case, after connection is lost, stream state
changes from STREAMING to IDLE - "avdtp_sep_set_state" is triggered which
invokes callback called "stream_state_changed" which internally invokes
"avdtp_sep_set_state" (state of stream doesn't change and stays as IDLE)
second time and then stream object is freed by "stream_free"
at the end of "avdtp_sep_set_state". After returning from callback,
first triggered "avdtp_sep_set_state" attempts to free stream object
again ("if (state == AVDTP_STATE_IDLE)" condition is still satisfied)
and it leads to invalid read/write/free issues (reported by valgrind)
in "stream free" body, since "stream" is "alias" pointer to stream object
which is already out of date (memory for stream object has been already
freed).

This patch prevents from this special case by freeing stream object only
when it is present on streams list and removing from this list when
stream object would be freed.
2011-06-14 12:07:56 +03:00
Rafal Michalski
d9b27da3cc Fix invalid read from memory issue in AVDTP module
Changing stream state from STREAMING to IDLE can be associated with side
effects under some circumstances (such as terminating bluetoothd during
music is streamed). In this case, after connection is lost, stream state
changes from STREAMING to IDLE - "avdtp_sep_set_state" is triggered which
invokes callback called "stream_state_changed" which internally invokes
"avdtp_sep_set_state" (state of stream doesn't change and stays as IDLE)
second time and then stream callbacks list is discarded by "stream_free"
("g_slist_free(stream->callbacks)"). After returning from callback,
"stream->callbacks" list (and "l" pointer as well) is already out of date,
so attempting to fetch "l->next" pointer (returned by "g_slist_next(l)"
to be prepared to next iteration of "for" loop) from node on discarded
list leads to invalid read issue (reported by valgrind).

This patch prevents from this issue by moving "l = g_slist_next(l)"
instruction just before invoking callback - loop has been modified and
"while" used instead of "for" loop variant.
2011-06-14 12:07:35 +03:00
Slawomir Bochenski
f8e0916e2d Remove unnecessary jumps 2011-06-01 14:41:01 +03:00
Rafal Michalski
09b6fbef70 Fix invalid read of memory in avdtp module
Fixed incorrect update of server->sessions GSlist in avdtp_exit.
Previosly it was leading to invalid read of memory (l = l->next)
(and possible memory leaks) since after invoking avdtp_unref in
connection_lost, l pointer was not valid anymore (previously assignment
l = l->next was used after invoking connection_lost in for loop).
2011-05-29 22:08:30 +03:00
Luiz Augusto von Dentz
27a52a9ccb Fix possible buffer overflow when sending avdtp commands
Buffer size should be as big as the maximum of imtu and omtu, otherwise
it may overflow when sending messages which are bigger then imtu.
2011-05-29 22:05:08 +03:00
Szymon Janc
906879b788 Fix garbage return value in send_req 2011-05-15 01:47:07 +03:00
Szymon Janc
24c6dee3b3 Remove redundant local copy of GSlist* from functions
Those functions already get copy of pointer to list so local copy is
not needed.
2011-05-15 01:47:05 +03:00
Johan Hedberg
44b7bcd6c1 Use flushable packets for A2DP media data 2011-04-21 10:33:31 +03:00
Johan Hedberg
fd0e49cb23 Clean up handle_transport_connect code flow 2011-04-21 10:31:45 +03:00
Luiz Augusto von Dentz
36ce04d51d Fix crash when acquiring A2DP stream
Disconnecting L2CAP before getting a response for AVDTP start cause a
crash while we try to abort it:

avdtp_sep_set_state (session=0x9c210, sep=0x9ada0, state=AVDTP_STATE_IDLE)
0x000256dc in connection_lost (session=0x9c210, err=-5)
0x00025d44 in cancel_request (session=0x9c210, err=-5)
0x00026a98 in avdtp_abort (session=0x9c210, stream=0x9bee8)
0x00020e74 in a2dp_cancel (dev=<value optimized out>, id=<value optimized out>)
0x0002d5b4 in acquire_request_free (req=0x9b1a0)
0x0002d638 in media_owner_remove (owner=0x9a4a0)
0x0002da94 in media_transport_free (data=<value optimized out>)
0x000115a0 in remove_interface (data=0xa1f88, name=<value optimized out>)
0x0002e2a0 in media_transport_remove (transport=0x8fad8)
0x0002c624 in media_endpoint_clear_configuration (endpoint=0x9b098)
0x000260c8 in avdtp_sep_set_state (session=0x9c210, sep=0x9ada0, state=AVDTP_STATE_IDLE)

To fix this callbacks are called after handling the state change, so
any pending request are properly removed before state is set to idle.
2011-03-30 19:43:07 +03:00
Daniel Orstadius
8c0b3c9c8e Increase AVDTP request timeout
At least one headset with both A2DP and PBAP sends delayed responses
to AVDTP requests when it is doing PBAP queries (typically at the
beginning of the connection).

Increasing the timer by two seconds to give the headset more time to
reply, to avoid aborting the AVDTP connection.
2011-03-10 11:06:16 +02:00
Johan Hedberg
de96fcd899 Reuse same SEP when reconfiguring A2DP streams
It makes sense to try to reuse the same SEP whenever possible when
reconfiguring streams. In fact this is even necessary with a particular
BMW car kit which doesn't allow a new stream to be set up to any other
SEP.
2011-02-08 11:04:39 -08:00
Dmitriy Paliy
ed8bfe8b81 Code cleanup: unnesessary line removed in avdtp.c 2011-02-02 12:10:27 +02:00
Luiz Augusto von Dentz
4aecf0a27c Fix use of deprecated glib on audio plugin 2011-01-19 13:52:53 +02:00
Luiz Augusto von Dentz
4171193496 Fix possible memory leak when handling avdtp transport connection
When acting as initiator stream io already has a reference to io channel
to be able to cancel if necessary.
2011-01-11 14:33:53 +02:00
Johan Hedberg
4efb97bdae Add manager_foreach_adapter()
Ultimately manager_get_adapters shouldn't be needed at all. By
introducing manager_foreach_adapter most instances can be removed.
2010-12-19 13:25:51 +02:00
Dmitriy Paliy
fa2a8b9000 Add AVDTP SRC stream send buffer size verification
Functions get_send_buffer_size and set_send_buffer_size are added to
avdpt.c.

get_send_buffer_size returns size of send buffer for a given socket
on success or error code on failure. set_send_buffer_size sets size
of send buffer for a given socket, and returns 0 on success or error
code on failure.

Size of send buffer for L2CAP socket for SRC AVDTP stream is verified
during establishment of a new transport channel. If the size is less
than twice of outgoing L2CAP MTU, then it is considered as being
insufficient to handle streaming data reliably.

In this case buffer size is increased to be twice of MTU size. Such
fixes some IOP problems with car-kits that use large MTU for music
playback.
2010-12-16 21:46:04 +02:00
Johan Hedberg
20ccc578c8 Remove unused includes 2010-11-28 13:41:35 +02:00
Luiz Augusto von Dentz
a26ae500a9 Fix not indicating disconnected state when connecting to avdtp
This cause parts of code such as audio/sink.c to keeps its internal state
as connecting and thus prevent any other connection attempt to succeed.
2010-11-19 18:19:28 +02:00
Luiz Augusto von Dentz
18e6c24989 Fix possible crashes when attempting to connect avdtp
Since the connections can be cancelled while still not complete the
GIOChannel must be stored in order to be properly closed when freeing
avdtp session or stream and thus avoid any callbacks to be called after
that.
2010-11-19 18:19:27 +02:00
Luiz Augusto von Dentz
6ecff04e0a Fix abort not being send when the state is idle
The spec clearly suggested that abort can be send while on idle state:

"AVDTP_ABORT_CMD can be sent or received in IDLE state. In the event that
an AVDTP_ABORT_CMD is received in IDLE state, ACP or INT shall reply with
an AVDTP_ABORT_RSP, no state change is required."

In fact abort is the only way to cancel set_configuration and open
commands.
2010-11-19 18:19:27 +02:00
Daniel Orstadius
88ee4ce65f Fix avoid starting AVDTP disconnect timer twice
Remove starting the timer when setting the AVDTP state to idle. If
needed, the timer should probably already have been started in
avdtp_unref when the reference count goes to one.

Since reference counting is handled in avdtp_ref and avdtp_unref, it
seems reasonable that not to inspect the count outside of those
functions.

The issue was found when using Device.Disconnect to disconnect a
headset. It was revealed by commit
c72ce0f12a.

Before the commit, the timer was removed and then started again.
After applying it, the idle callback (disconnect_timeout) is called
twice, causing a crash.
2010-11-01 11:41:51 -03:00
Johan Hedberg
c72ce0f12a Don't use AVDTP timer when the device is being disconnected
When the user has requested a disconnection it doesn't make sense to
have the AVDTP state machine waiting before closing the signalling
channel. This is particularly important for Device.Disconnect since only
two seconds are available for a clean disconnect before a forced
HCI_Disconnect command is sent.
2010-10-29 11:09:31 -04:00
Luiz Augusto von Dentz
928b5dcda6 Fix blocking on setconf indication callback
Use callback when calling Endpoint.SetConfiguration and only respond the
command request once the endpoint replies.
2010-10-11 12:27:01 +03:00
Luiz Augusto von Dentz
01d29e5903 Make use of avdtp category when setting errors
In order to forward and create avdtp error properly for setconf command
we need to have the category, to fix this avdtp_error_t now carries the
category as define in avdtp and a new category is used for errno
(AVDTP_ERRNO).
2010-10-11 12:27:01 +03:00
Luiz Augusto von Dentz
c6ed0d5e06 Add source if the device attempt to configure a stream with a local sink
This is similar to a sink attempt to configure a stream with a local
source, so in case of devices hiding their records for some reason with
this we can sill register a proper interface to handle the profile.
2010-10-11 12:27:01 +03:00
Luiz Augusto von Dentz
f87e1bed13 Add initial implementation of org.bluez.Media spec 2010-09-15 15:21:53 +03:00
Luiz Augusto von Dentz
368b35aaee Fix crash when there is no enough space to fragment avdtp packet
This was catch when running codenomicon tests when the output mtu is not
big enough to stuff fragmented packets.
2010-08-19 14:06:51 +03:00
Luiz Augusto von Dentz
0f775bfff6 Remove redundant information that is already present in DBG 2010-06-29 10:29:10 +03:00
Johan Hedberg
331c7dfa40 Add an error log when avdtp_close fails in stream_timeout 2010-06-17 12:26:31 +03:00
Johan Hedberg
bac81ba536 Coding style cleanup 2010-05-26 13:14:25 +03:00
Gustavo F. Padovan
8e58667ef0 Move debug() to DBG()
Use the new dynamic debug feature
2010-05-21 18:21:48 +02:00
Gustavo F. Padovan
e891f7df62 Move logging.{c,h} to log.{c,h}
Try to make log stuff more similar to ConnMan and oFono.
2010-05-21 14:40:36 +02:00
Luiz Augusto Von Dentz
ab816e6549 Add immediate parameter to avdtp_close
When TRUE if there is an outstanding command in the sending queue it will
cause abort which cancel any pending command.
2010-03-24 23:32:24 +02:00
Luiz Augusto Von Dentz
f8d790861c Send abort on while cancelling a2dp setup
This should guarantee that any outstanding command in the queue is
cancelled, accourding to the avdtp spec:

"6.16 Abort
Because AVDTP is typically used on unreliable channels, signaling messages
can be lost due to L2CAP Flush Timeouts. To react to inconsistencies
between the INT and ACP states, the Abort Command may be used."

It also says abort can be send regardless of the state even in case of
packet fragmantation:

"Note that it is permitted to breakdown a packet sequence (command or
response message) to send an Abort command message in the same direction.
The remaining packets consecutive to an aborted message shall be flushed by
the sender."
2010-03-24 23:32:24 +02:00
Luiz Augusto Von Dentz
abe8bb2d3b Make abort requests to have a shorter timeout
Regular request takes 4 secs to timeout, but this may be too long to wait
for abort command so it is now reduced to 2 secs.
2010-03-24 23:32:24 +02:00
Luiz Augusto Von Dentz
43830baea4 Fix avdtp_abort not canceling pending requests 2010-03-24 23:32:24 +02:00
Luiz Augusto Von Dentz
0085717ed4 Drop connection if abort is rejected
Make it consistent with the logic when abort timeout since the original
intent is to cancel a pending request there is no point in keeping the
connection if it is in an unrecoverable state.
2010-03-24 23:23:37 +02:00
Daniel Orstadius
c63916361c Fix double free on AVDTP Abort response
The pending request might be freed twice when receiving an Abort
response, in handle_unanswered_req and session_cb. Avoid freeing
it in handle_unanswered_req.
2010-02-21 10:44:08 -03:00
Luiz Augusto Von Dentz
3a16e6d242 Mark inuse flag whenever a stream is configured
Currently it was only marked when acting as the initiator.
2010-02-18 14:08:17 -03:00
Luiz Augusto Von Dentz
28d337cd21 Fix possible crash while verifying avdtp version
Reproducible with Codenomicon A2DP testsuite 1.4.2.
2010-02-17 02:01:07 -08:00
Daniel Orstadius
e9b1a8f726 Handle unanswered AVDTP request on disconnect
If the connection is lost when there is an AVDTP request the remote has
not replied to and which has not timed out, then at least in some cases
the callback for the request is not called leading to no Error response
being sent on the Audio API.

This patch checks if there is an outstanding request when the stream
state goes to idle and in that case triggers the corresponding callback
with an error.
2010-02-10 05:29:40 -05:00
Johan Hedberg
5592142cb9 Update Nokia copyrights 2010-01-07 01:11:05 -08:00
Marcel Holtmann
9184e2eeb7 Update copyright information 2010-01-01 17:08:17 -08:00
Johan Hedberg
45442bb290 Fix sending incorrect AVDTP commands after a timeout occurs
Since request_timeout() does callbacks into a2dp.c before sending the
ABORT command we need to make sure that none of the callbacks can
trigger sending any further AVDTP commands. This is easiest done by
setting the stream->abort_int flag early in the request_timeout function
and then checking for it in the send_request function.
2009-11-20 14:25:01 +02:00
Johan Hedberg
5f8a274881 Add support for AVDTP 1.3 Delay Reporting
This patch adds support for the new Delay Report command in AVDTP 1.3.
2009-10-06 19:18:53 +02:00