Commit Graph

1242 Commits

Author SHA1 Message Date
Christian Fetzer
7a8aeaf09c obexd: Fix crash when retrieving multiple MAP event reports
The remote address used for dispatching the MAP notifications is
initialized when the MNS is connected. Therefore it needs to be freed
when the session is destroyed and not after receiving an event report.

Trace:

  0  0x00007ffff6a6a1c9 in raise () from /usr/lib/libc.so.6
  1  0x00007ffff6a6b5c8 in abort () from /usr/lib/libc.so.6
  2  0x00007ffff6aa8037 in __libc_message () from /usr/lib/libc.so.6
  3  0x00007ffff6aad8ae in malloc_printerr () from /usr/lib/libc.so.6
  4  0x00007ffff6aae587 in _int_free () from /usr/lib/libc.so.6
  5  0x00000000004273b0 in event_report_close (obj=0x69a5b0)
     at obexd/client/mns.c:295
  6  0x0000000000429549 in os_reset_session (os=0x69c210)
     at obexd/src/obex.c:199
  7  0x000000000041bec6 in transfer_complete (transfer=0x69a9d0, err=0x0)
     at gobex/gobex-transfer.c:103
  8  0x000000000041c20c in transfer_put_req (obex=0x69b470,
     req=<optimized out>, user_data=0x69a9d0) at
       gobex/gobex-transfer.c:407
  9  0x000000000041988d in handle_request (req=0x69f3d0, obex=0x69b470)
     at gobex/gobex.c:1022
  10 incoming_data (io=<optimized out>, cond=<optimized out>,
     user_data=0x69b470) at gobex/gobex.c:1194
  11 0x00007ffff702de46 in g_main_context_dispatch ()
     from /usr/lib/libglib-2.0.so.0
  12 0x00007ffff702e198 in ?? () from /usr/lib/libglib-2.0.so.0
  13 0x00007ffff702e59a in g_main_loop_run () from
       /usr/lib/libglib-2.0.so.0
  14 0x000000000040dead in main (argc=1, argv=0x7fffffffddc8)
     at obexd/src/main.c:319
2013-06-18 14:45:09 +03:00
Christian Fetzer
2237294c8d obexd: Use correct callback in obc_session_mkdir
The function obc_session_mkdir needs to use file_op_complete as
callback.

  0  0x00007ffff72f7553 in ?? () from /usr/lib/libdbus-1.so.3
  1  0x00007ffff72f7dff in ?? () from /usr/lib/libdbus-1.so.3
  2  0x00007ffff72fef9a in dbus_message_get_sender ()
     from /usr/lib/libdbus-1.so.3
  3  0x00007ffff72feff9 in dbus_message_new_method_return ()
     from /usr/lib/libdbus-1.so.3
  4  0x000000000043c93f in async_cb (session=0x6a9d30, transfer=0x0,
       err=0x0,
     user_data=0x675660) at obexd/client/ftp.c:65
  5  0x0000000000438c7c in async_cb (obex=0x6aa980, err=0x0,
       rsp=0x67a690,
     user_data=0x67ced0) at obexd/client/session.c:1035
  6  0x000000000041cbcc in handle_response (obex=0x6aa980, err=0x0,
     rsp=0x67a690) at gobex/gobex.c:949
  7  0x000000000041d49f in incoming_data (io=0x67d0f0, cond=G_IO_IN,
     user_data=0x6aa980) at gobex/gobex.c:1192
  8  0x00007ffff702de46 in g_main_context_dispatch ()
     from /usr/lib/libglib-2.0.so.0
  9  0x00007ffff702e198 in ?? () from /usr/lib/libglib-2.0.so.0
  10 0x00007ffff702e59a in g_main_loop_run () from
       /usr/lib/libglib-2.0.so.0
  11 0x0000000000430a09 in main (argc=1, argv=0x7fffffffddc8)
     at obexd/src/main.c:319
2013-06-18 13:43:01 +03:00
Christian Fetzer
b402f99241 obexd: Fix file_op_complete callback
The file_op_complete callback added for the OBEX session command queuing
is called with a file_data parameter and not with a pending_request.

This fixes a crash when calling one of the file commands (like delete).

  0  0x0000000000438cd6 in file_op_complete (session=0x6a9d30,
       transfer=0x0,
     err=0x0, user_data=0x6762e0) at obexd/client/session.c:1054
  1  0x0000000000438c64 in async_cb (obex=0x6aa980, err=0x0,
       rsp=0x67a710,
     user_data=0x6ac2c0) at obexd/client/session.c:1035
  2  0x000000000041cbcc in handle_response (obex=0x6aa980, err=0x0,
     rsp=0x67a710) at gobex/gobex.c:949
  3  0x000000000041d49f in incoming_data (io=0x67d0f0, cond=G_IO_IN,
     user_data=0x6aa980) at gobex/gobex.c:1192
  4  0x00007ffff702de46 in g_main_context_dispatch ()
     from /usr/lib/libglib-2.0.so.0
  5  0x00007ffff702e198 in ?? () from /usr/lib/libglib-2.0.so.0
  6  0x00007ffff702e59a in g_main_loop_run () from
       /usr/lib/libglib-2.0.so.0
  7  0x00000000004309f0 in main (argc=1, argv=0x7fffffffddc8)
     at obexd/src/main.c:319
2013-06-18 13:43:00 +03:00
Christian Fetzer
4e16c256ed obexd: Call setpath_complete with the correct parameter
The function setpath_complete has to be called with a pending_request as
user_data. In one possible error case, the current code calls it
incorrectly with setpath_data.
2013-06-18 13:43:00 +03:00
Christian Fetzer
8be70369bd obexd: Fix handling error cases in setpath
This adds a setpath_op_complete callback, that unpacks the user data and
finally calls the user callback. The callback is now used for success and error
cases.

The previous implementation was using setpath_complete which did not
work for error cases, because it was called with incorrect user data.
This was leading to a crash, that can be reproduced by disconnecting PBAP
after trying to select a non existing phone book.

  0  setpath_complete (session=0x66bd90, transfer=0x0, err=0x69b370,
     user_data=0x69a810) at obexd/client/session.c:912
  1  0x000000000042d100 in obc_session_shutdown (session=0x66bd90)
     at obexd/client/session.c:537
  2  0x000000000040f227 in service_filter (connection=0x664b20,
     message=<optimized out>, user_data=0x66bed0) at gdbus/watch.c:486
  3  0x000000000040f49b in message_filter (connection=0x664b20,
     message=0x66ba30, user_data=<optimized out>) at gdbus/watch.c:554
  4  0x00007ffff72f40a6 in dbus_connection_dispatch ()
     from /usr/lib/libdbus-1.so.3
  5  0x000000000040e148 in message_dispatch (data=0x664b20)
     at gdbus/mainloop.c:76
  6  0x00007ffff702e9a3 in ?? () from /usr/lib/libglib-2.0.so.0
  7  0x00007ffff702de46 in g_main_context_dispatch ()
     from /usr/lib/libglib-2.0.so.0
  8  0x00007ffff702e198 in ?? () from /usr/lib/libglib-2.0.so.0
  9  0x00007ffff702e59a in g_main_loop_run () from
     /usr/lib/libglib-2.0.so.0
  10 0x000000000040dd72 in main (argc=1, argv=0x7fffffffddc8)
     at obexd/src/main.c:319
2013-06-18 13:43:00 +03:00
Luiz Augusto von Dentz
9ee1038cff obexd: Fix not checking for valid fd on NewConnection
The fd needs to be checked as it may not be valid which cause the
following warnings:

==8162== Warning: invalid file descriptor 1031 in syscall fcntl(DUPFD_CLOEXEC)()

(obexd:8162): GLib-WARNING **: giounix.c:412Error while getting flags for FD: Bad file descriptor (9)
2013-06-12 00:12:33 +03:00
Luiz Augusto von Dentz
00622544dd obexd: Fix crash when resetting OPP session without a transfer
Invalid read of size 8
   at 0x42A570: manager_emit_transfer_completed (manager.c:863)
   by 0x42A76A: os_reset_session (obex.c:206)
   by 0x42A8BB: disconn_func (obex.c:1085)
   by 0x419C55: incoming_data (gobex.c:1224)
   by 0x3F31A47A54: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x3F31A47D87: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x3F31A48181: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x40DDB2: main (main.c:319)
 Address 0x10 is not stack'd, malloc'd or (recently) free'd

Invalid read of size 1
   at 0x42A231: manager_unregister_transfer (manager.c:672)
   by 0x420F8B: opp_disconnect (opp.c:158)
   by 0x42A8EC: disconn_func (obex.c:1088)
   by 0x419C55: incoming_data (gobex.c:1224)
   by 0x3F31A47A54: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x3F31A47D87: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x3F31A48181: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
   by 0x40DDB2: main (main.c:319)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd
2013-06-11 15:42:36 +03:00
Luiz Augusto von Dentz
7c535b1621 obexd: Fix coding style
Respect 80 column limit
2013-05-29 14:40:06 +03:00
Luiz Augusto von Dentz
1032b07a2b obexd: Simplify manager_register_session
There is no need for a goto as nothing else is done
2013-05-29 14:40:06 +03:00
Luiz Augusto von Dentz
624159e7dd obexd: Fix not unregistering interface when a session is detroyed
The path used for unregistering is wrong so the Session interface is
still reachable after the object is destroyed which can cause crashes
such as the following:

invalid read of size 8
    at 0x4297C4: get_destination (manager.c:286)
    by 0x41130B: properties_get (object.c:800)
    by 0x410710: process_message.isra.4 (object.c:258)
    by 0x3F3461D9C4: ??? (in /usr/lib64/libdbus-1.so.3.7.2)
    by 0x3F3460FC1F: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.2)
    by 0x40E207: message_dispatch (mainloop.c:76)
    by 0x3F31A485DA: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
    by 0x3F31A47A54: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
    by 0x3F31A47D87: ??? (in /usr/lib64/libglib-2.0.so.0.3400.2)
    by 0x3F31A48181: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
    by 0x40DDB2: main (main.c:319)
2013-05-29 14:40:06 +03:00
Gustavo Padovan
a0c7cfbcc1 manager: remove unused call to obex_getpeername() 2013-05-29 14:40:06 +03:00
Gustavo Padovan
2b7e5adeef session: add Source and Destination properties
This is useful when we want to know where a incoming OPP transfer, for
example, is from.
2013-05-29 14:40:06 +03:00
Gustavo Padovan
4d8c46d451 obex: get src and dst address and store it
This commit creates src and dst members in obex_session to later use them
to export via Session D-Bus API.
2013-05-29 14:40:05 +03:00
Gustavo Padovan
a8a9649850 obex: add obex_getsockname()
Allow obex users to get the source device address.
2013-05-29 14:40:05 +03:00
Gustavo Padovan
4e309bd193 bluetooth: add getsockname() entry in the bluetooth driver 2013-05-29 14:40:05 +03:00
Gustavo Padovan
d49c6a28ad transport: add getsockname to transport driver
Enable other pieces of obex to get the source Bluetooth address.
2013-05-29 14:40:05 +03:00
Christian Fetzer
65542c9018 obexd: Queue delete command 2013-05-29 13:24:19 +03:00
Christian Fetzer
041efe21b8 obexd: Queue move command 2013-05-29 13:24:19 +03:00
Christian Fetzer
dc208eb149 obexd: Queue copy command 2013-05-29 13:24:18 +03:00
Christian Fetzer
088f2b5b0e obexd: Queue mkdir command 2013-05-29 13:24:18 +03:00
Christian Fetzer
f68dc7bd5a obexd: Add file_data struct to session
This adds a common file_data struct and related free and complete callbacks
to the session. This will be used for queuing the file related commands
mkdir, copy, move and delete.
2013-05-29 13:24:18 +03:00
Christian Fetzer
0e85627119 obexd: Queue setpath command 2013-05-29 13:24:18 +03:00
Christian Fetzer
2883c4d173 obexd: Use process callback to queue transfers
This generalizes the existing queuing of transfers by using the
process callback of pending_request.
2013-05-29 13:24:18 +03:00
Christian Fetzer
e66eff4b46 obexd: Add session_queue
Add helper function session_queue that appends a pending_request to the
session's command queue.
2013-05-29 13:24:18 +03:00
Christian Fetzer
b79cd0b46c obexd: Add process callback to session's pending_request
This adds a process callback and a data destroy callback to the session's
pending_request structure.

This is needed as preparation of queuing all OBEX session commands.
2013-05-29 13:24:17 +03:00
Gustavo Padovan
232fa391e3 opp: Register Session interface for OPP transfers
The Session interface wasn't registered when a new transfer arrives.
2013-05-28 11:34:26 +03:00
Gustavo Padovan
4c437f5d6a session: only add Target if it exists 2013-05-28 11:34:26 +03:00
Christian Fetzer
5316ed07d5 obexd: Fix SetPath response
This fixes the issue, that failed attempts to the OBEX SetPath command
are not propagated through the D-Bus API.

Trace:

  method call sender=:1.942 -> dest=:1.934 serial=8
  path=/org/bluez/obex/client/session3;
  interface=org.bluez.obex.MessageAccess1; member=SetFolder
     string "test"
  method return sender=:1.934 -> dest=:1.942 reply_serial=8

  method call sender=:1.946 -> dest=:1.945 serial=8
  path=/org/bluez/obex/client/session0;
  interface=org.bluez.obex.MessageAccess1; member=SetFolder
     string "test"
  error sender=:1.945 -> dest=:1.946
  error_name=org.bluez.obex.Error.Failed reply_serial=8
     string "Not Found"
2013-05-23 14:34:31 -07:00
Luiz Augusto von Dentz
b5afba2181 obexd: Fix using the same prefix for client and server sessions
This avoids using the same path for different sessions which fail since
it cannot register a second time causing an unexpected error.
2013-05-10 14:56:25 +03:00
Lucas De Marchi
94862127b4 obexd: Get rid of gchar
Use plain char instead of gchar.
2013-05-02 09:03:48 +03:00
Lucas De Marchi
65878a7806 obexd: Get rid of gint
Use plain int instead of gint. In glib gint is always a typedef to int,
so it's safe to use it even for callbacks with glib.
2013-05-01 09:08:53 +03:00
Luiz Augusto von Dentz
8140306965 obexd: Fix make distcheck
../obexd/client/map.c:43:17: fatal error: sdp.h: No such file or directory
2013-04-17 17:46:55 +03:00
Christian Fetzer
4ee201a588 obexd: Read service attributes when instantiating MAP session
Parse the service attributes mas_instance_id and supported_message_types
from the transport's service attributes as soon as a connection is
established.
2013-04-17 13:43:45 +03:00
Christian Fetzer
f4bf087572 obexd: Add obc_session_get_attribute to session
This adds a obc_session_get_attribute function to the client session.
The function allows querying the session specific service attributes.
2013-04-17 13:43:45 +03:00
Christian Fetzer
cb59ec7853 obexd: Add bluetooth_getattribute to Bluetooth transport
This function makes the cached SDP attributes available for the profile
implementations.
2013-04-17 13:43:38 +03:00
Christian Fetzer
e0c744c9a8 obexd: Add getattribute to obc_transport
This adds a getattribute function pointer to obc_transport, which allows
transports to provide the session specific service attributes.
2013-04-17 13:31:05 +03:00
Christian Fetzer
e163a91514 obexd: Cache SDP record in bluetooth transport
This caches the SDP record of the active session in the Bluetooth
transport.
2013-04-17 13:31:05 +03:00
Christian Fetzer
518a51ad1d obexd: Automatically setup notification connection for MAP client
This automatically establishes the MNS connection when the MAS client
session is started and terminates the MNS connection when the MAS client
session is closed.

The MAP client controls the notification channel using the
SetNotificationRegistration function. The MSE will connect/disconnect
the MNS connection accordingly.
2013-04-10 14:56:46 +03:00
Christian Fetzer
eecf2d8c21 obexd: Enable MNS server 2013-04-10 14:51:09 +03:00
Christian Fetzer
ef4b34eb5e obexd: Add Message Notification Service (MNS) server
This implements the server role of the MAP Message Notification Service
(MNS) which is part of the MAP Client Equipment (MCE) device.

After successful registration, the MNS will receive event reports,
notifying about state changes on the server side.

Possible events are: NewMessages, DeliverySuccess, SendingSuccess,
DeliveryFailure, SendingFailure, MemoryFull, MemoryAvailable,
MessageDeleted, MessageShift
2013-04-10 14:51:09 +03:00
Lucas De Marchi
ee27640ef6 obexd: Use gcc builtin instead of g_atomic
g_atomic_* end up using G_STATIC_ASSERT, causing gcc 4.8 to yell due to
-Wunused-local-typedefs.

/usr/include/glib-2.0/glib/gmacros.h:162:53: error: typedef ‘_GStaticAssertCompileTimeAssertion_2’ locally defined but not used [-Werror=unused-local-typedefs]
 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]

Most of the uses of atomic operations were wrong. They were fixed as
well. If we are using atomic operations, reading the variable again
later for logging is not an option, we should use the return of the
atomic function used to fetch the variable.
2013-04-09 07:02:19 +09:00
Christian Fetzer
ed3b98a683 obexd: Handle absolute paths in obc_session_setpath
For absolute paths (that begin with '/'), obc_session_setpath gets called
twice to reset to the root folder.
This is caused by an empty first element in the folder list created by g_strsplit.

This solution sets the index to the folder array correctly and ignores
empty folder names. This fixes as well paths with double slashes.

Trace for 'SetFolder /telecom':

< ACL data: handle 21 flags 0x00 dlen 21
    L2CAP(d): cid 0x0040 len 17 [psm 3]
      RFCOMM(d): UIH: cr 1 dlci 32 pf 0 ilen 13 fcs 0xd8
        OBEX: SetPath cmd(f): len 13 flags 2 constants 0
        Connection ID (0xcb) = 17
        Name (0x01) = Unicode length 0
> HCI Event: Number of Completed Packets (0x13) plen 5
    handle 21 packets 1
> ACL data: handle 21 flags 0x02 dlen 11
    L2CAP(d): cid 0x0041 len 7 [psm 3]
      RFCOMM(d): UIH: cr 0 dlci 32 pf 0 ilen 3 fcs 0x2
        OBEX: SetPath rsp(f): status 200 len 3
< ACL data: handle 21 flags 0x00 dlen 21
    L2CAP(d): cid 0x0040 len 17 [psm 3]
      RFCOMM(d): UIH: cr 1 dlci 32 pf 0 ilen 13 fcs 0xd8
        OBEX: SetPath cmd(f): len 13 flags 2 constants 0
        Connection ID (0xcb) = 17
        Name (0x01) = Unicode length 0
> HCI Event: Number of Completed Packets (0x13) plen 5
    handle 21 packets 1
> ACL data: handle 21 flags 0x02 dlen 11
    L2CAP(d): cid 0x0041 len 7 [psm 3]
      RFCOMM(d): UIH: cr 0 dlci 32 pf 0 ilen 3 fcs 0x2
        OBEX: SetPath rsp(f): status 200 len 3
< ACL data: handle 21 flags 0x00 dlen 37
    L2CAP(d): cid 0x0040 len 33 [psm 3]
      RFCOMM(d): UIH: cr 1 dlci 32 pf 0 ilen 29 fcs 0xd8
        OBEX: SetPath cmd(f): len 29 flags 2 constants 0
        Connection ID (0xcb) = 17
        Name (0x01) = Unicode length 16
        0000: 00 74 00 65 00 6c 00 65  00 63 00 6f 00 6d 00 00  .t.e.l.e.c.o.m..
> HCI Event: Number of Completed Packets (0x13) plen 5
    handle 21 packets 1
> ACL data: handle 21 flags 0x02 dlen 11
    L2CAP(d): cid 0x0041 len 7 [psm 3]
      RFCOMM(d): UIH: cr 0 dlci 32 pf 0 ilen 3 fcs 0x2
        OBEX: SetPath rsp(f): status 200 len 3
2013-02-22 10:41:52 +02:00
Christian Fetzer
7f80320654 obexd: Remove obc_session_setpath limit
obc_session_setpath is able to handle multiple folder changes at once.
This removes the limit, that was introduced because of PBAP's limitation
to 3 levels (75d32c6b3a).

Other profiles like MAP might have deeper folder hierarchies.
2013-02-22 10:41:52 +02:00
Christian Fetzer
e859c03231 obexd: Add PushMessage
Push message has been implemented similar to send file (OPP),
the message to send (in bMessage format) is read from a file.
2013-02-07 13:49:00 +02:00
Christian Fetzer
970333272c obexd: Add parameter Status to GetMessageListing response
The parameter Status indicates the status of reception of the message.
It can be used to differentiate between messages with a reception status
of "completed", "fractioned" and "notification".

This parameter got lost when obexd was refactored to use of D-Bus properties.
The documentation and the parsing code for it was still there.
2013-01-18 13:58:50 +02:00
Christian Fetzer
41d1d89cf5 obexd: Add parameter AttachmentSize to GetMessageListing response
The parameter AttachmentSize indicates if the message contains
any attachment and their overall size (in bytes).
2013-01-18 13:58:50 +02:00
Christian Fetzer
ff52e50288 obexd: Add parameter Text to GetMessageListing response
The Text flag indicates if the message contains any textual content
or has binary content only.
2013-01-18 13:58:49 +02:00
Christian Fetzer
cb4a4de99c obexd: Move parse_size function in map.c
This reorders msg_parsers and moves the function parse_size
to match the order in the MAP specification.
2013-01-18 13:58:49 +02:00
Christian Fetzer
f9998e750f obexd: Add parameter SubjectLength to map_list_messages
This parameter allows the client to request a maximum length of the
parameter "subject" in the messages listing.
2013-01-18 13:58:42 +02:00
Christian Fetzer
363e55779d obexd: Remove transferred file only if the GET operation failed
Since 9606375649 xfer_complete() sets the
transfer status rather than the size. Adapt obc_transfer_free to check
for the completed status to avoid deletion of completed transfers.
2013-01-14 17:42:06 +02:00