platform/upstream/neard.git
11 years agogdbus: Fix not freeing list node by using g_slist_delete_link
Luiz Augusto von Dentz [Wed, 3 Oct 2012 11:57:06 +0000 (14:57 +0300)]
gdbus: Fix not freeing list node by using g_slist_delete_link

g_slist_remove_link does not free the node which can cause leaks so
replace that with g_slist_delete_link which does free memory properly.

11 years agogdbus: Refactor filter_data_find()
Lucas De Marchi [Thu, 27 Sep 2012 11:58:59 +0000 (08:58 -0300)]
gdbus: Refactor filter_data_find()

Now this function is only used for searching the listeners of a
connection and the other parameters are not needed anymore.

11 years agogdbus: Fix wrong signal handler match
Lucas De Marchi [Thu, 27 Sep 2012 11:58:58 +0000 (08:58 -0300)]
gdbus: Fix wrong signal handler match

When we add a signal handler with g_dbus_add_signal_watch(), this
function tries to multiplex the matches added in libdbus by checking
if there's a previous filter_data with the same fields. However, if the
field is NULL it accepts as being the same. The result is that the
following watches will use the same filter data:

watch1 = g_dbus_add_signal_watch(conn, BUS_NAME, NULL, iface, member,
cb1, data1, NULL);
watch2 = g_dbus_add_signal_watch(conn, BUS_NAME, "/path2", iface, member,
cb2, data2, NULL);
watch3 = g_dbus_add_signal_watch(conn, BUS_NAME, "/path3", iface, member,
cb3, data3, NULL);

The result is that when a signal arrives with path == "/path2", all 3
callbacks above will be called, with the same signal delivered to all of
them.

Another problem is that, if we invert the calls like below, only signals
to cb1 will never be trigerred, nonetheless it used path == NULL.

watch2 = g_dbus_add_signal_watch(conn, BUS_NAME, "/path2", iface, member,
cb2, data2, NULL);
watch1 = g_dbus_add_signal_watch(conn, BUS_NAME, NULL, iface, member,
cb1, data1, NULL);
watch3 = g_dbus_add_signal_watch(conn, BUS_NAME, "/path3", iface, member,
cb3, data3, NULL);

This is fixed by not multiplexing the matchs with filter data if any of
the fields are different, including being NULL. When a signal arrives,
if a field is NULL we accept it as a match, but not when adding the
signal handler.

11 years agogdbus: Fix crash when getting disconnected from the bus
Johan Hedberg [Thu, 27 Sep 2012 11:58:57 +0000 (08:58 -0300)]
gdbus: Fix crash when getting disconnected from the bus

When getting disconnected from the bus sometimes (maybe always?)
dbus_watch_handle() can cause the "info" context to be free'd meaning
that we should not try to access it after the call. The only member we
need access to is the connection pointer and as the code already has a
ref() call for it it's only natural to solve the issue by adding a local
variable not dependent on "info".

The backtrace of the crash fixed looks as follows:

 Invalid read of size 8
   at 0x121085: watch_func (mainloop.c:105)
   by 0x4C72694: g_main_context_dispatch (gmain.c:2539)
   by 0x4C729C7: g_main_context_iterate.isra.23 (gmain.c:3146)
   by 0x4C72DC1: g_main_loop_run (gmain.c:3340)
   by 0x120541: main (main.c:551)
 Address 0x5bbcd90 is 16 bytes inside a block of size 24 free'd
   at 0x4A079AE: free (vg_replace_malloc.c:427)
   by 0x4C7837E: g_free (gmem.c:252)
   by 0x4F708BF: dbus_watch_set_data (dbus-watch.c:614)
   by 0x4F70938: _dbus_watch_unref (dbus-watch.c:132)
   by 0x4F6E9A7: _dbus_transport_handle_watch (dbus-transport.c:884)
   by 0x4F59AFB: _dbus_connection_handle_watch (dbus-connection.c:1497)
   by 0x4F70AF9: dbus_watch_handle (dbus-watch.c:683)
   by 0x121084: watch_func (mainloop.c:103)
   by 0x4C72694: g_main_context_dispatch (gmain.c:2539)
   by 0x4C729C7: g_main_context_iterate.isra.23 (gmain.c:3146)
   by 0x4C72DC1: g_main_loop_run (gmain.c:3340)
   by 0x120541: main (main.c:551)

11 years agoadapter: Update the RF mode D-Bus property
Samuel Ortiz [Mon, 26 Nov 2012 10:41:57 +0000 (11:41 +0100)]
adapter: Update the RF mode D-Bus property

When detecting a tag, or a device, the RF mode changes.
When the link is down, RF mode goes to Idle.

11 years agoadapter: Expose the adapter radio mode through D-Bus
Samuel Ortiz [Mon, 26 Nov 2012 10:12:12 +0000 (11:12 +0100)]
adapter: Expose the adapter radio mode through D-Bus

11 years agodoc: Some small issues cleanup
Szymon Janc [Mon, 12 Nov 2012 13:33:11 +0000 (14:33 +0100)]
doc: Some small issues cleanup

Fix some whitespace, line-over-80 and typos issues.

11 years agodoc: Clarify EIR blob format in handover agent API
Szymon Janc [Mon, 12 Nov 2012 13:33:09 +0000 (14:33 +0100)]
doc: Clarify EIR blob format in handover agent API

Clarify what EIR blob is and where to find how it is specified.

11 years agonfctype3: Sending the POLL command should be the default behaviour
Samuel Ortiz [Mon, 19 Nov 2012 23:24:07 +0000 (00:24 +0100)]
nfctype3: Sending the POLL command should be the default behaviour

commit bd285ab6 changed the default case to be the one for only a
couple of Felica tags.

11 years agoagent: Don't look for NULL record type on the NDEF agent hash
Samuel Ortiz [Wed, 31 Oct 2012 09:39:18 +0000 (10:39 +0100)]
agent: Don't look for NULL record type on the NDEF agent hash

11 years agondef: Cosmetic fix for action check in parse_mime_type
Szymon Janc [Thu, 15 Nov 2012 08:15:44 +0000 (09:15 +0100)]
ndef: Cosmetic fix for action check in parse_mime_type

Match action check with neard code style.

11 years agobluetooth: Always enable legacy BT when no HO agent is registered
Szymon Janc [Thu, 15 Nov 2012 08:15:43 +0000 (09:15 +0100)]
bluetooth: Always enable legacy BT when no HO agent is registered

If the timer expired, that basically means no agent got registered,
regardless of BlueZ being version 5 or 4. In such situation just go
with legacy implementation as there is nothing better that could be
done anyway.

11 years agondef: Select HO agent based on agent presence check
Szymon Janc [Thu, 15 Nov 2012 08:15:42 +0000 (09:15 +0100)]
ndef: Select HO agent based on agent presence check

Choose between HO Agent or legacy bluetooth implementation based on
HO agent presence and not on detected BlueZ version.

11 years agobluetooth: Cosmetic fix for handover registration check
Samuel Ortiz [Wed, 14 Nov 2012 11:25:07 +0000 (12:25 +0100)]
bluetooth: Cosmetic fix for handover registration check

11 years agoSupport only static handover with Nokia proprietary mime type
Szymon Janc [Wed, 31 Oct 2012 11:22:24 +0000 (12:22 +0100)]
Support only static handover with Nokia proprietary mime type

Parse nokia.com:bt mime type only if received in Handover Select
message.

11 years agondef: Workaround buggy Nokia BH-505 handover implementation
Szymon Janc [Wed, 31 Oct 2012 11:22:23 +0000 (12:22 +0100)]
ndef: Workaround buggy Nokia BH-505 handover implementation

According to BT Core Specification 4.0 length field in OOB EIR contains
the length of the entire OOB data block including the length field
itself.

Some Nokia BH-505 devices reports OOB EIR length without length field
size. Correct size before sending EIR to agent.

11 years agondef: Workaround buggy Android 4.1 BT handover implementation
Szymon Janc [Wed, 31 Oct 2012 11:22:22 +0000 (12:22 +0100)]
ndef: Workaround buggy Android 4.1 BT handover implementation

Some implementations (e.g. Android 4.1) stores the data_size in big
endian but NDEF forum spec (BT Secure Simple Pairing) requires a little
endian. At the same time, the NDEF forum NDEF spec define a payload
length as single byte (and the payload size IS the oob data size).
So we check the first byte to determine if we have a big or little
endian size.

11 years agoUse handover agent for Bluetooth data
Szymon Janc [Wed, 31 Oct 2012 11:22:21 +0000 (12:22 +0100)]
Use handover agent for Bluetooth data

If detected BlueZ is not version 4 handover agent is used for bluetooth
data handling.

11 years agobluetooth: Use bluetooth implementation only for BlueZ 4
Szymon Janc [Wed, 31 Oct 2012 11:22:20 +0000 (12:22 +0100)]
bluetooth: Use bluetooth implementation only for BlueZ 4

BlueZ 5 will break DBus API and will be able to act as Handover Agent.
If handover agent is not registered while initializing/starting legacy
bluetooth implementation delay setting up watchers to give handover
agent time to register. This reduces D-Bus calls in case when BlueZ
registers itself as handover agent.

If handover agent is registered legacy bluetooth is stopped. When agent
unregisters or vanishes legacy bluetooth is reinitialized.

11 years agobluetooth: Use struct bt_data in near_ndef_prepare_handover_record
Szymon Janc [Wed, 31 Oct 2012 11:22:19 +0000 (12:22 +0100)]
bluetooth: Use struct bt_data in near_ndef_prepare_handover_record

This also fix creating EIR with length field in host order instead of
little endian.

11 years agobluetooth: Move name at the end of EIR
Szymon Janc [Wed, 31 Oct 2012 11:22:18 +0000 (12:22 +0100)]
bluetooth: Move name at the end of EIR

This will make sure that hash and randomizer are send even when name is
long. Also limit name to not exceed maximum sensible EIR length of 255
bytes. If name would not fit use EIR_NAME_SHORT data type for it.

11 years agobluetooth: Make __near_bluetooth_parse_oob_record use struct bt_data
Szymon Janc [Wed, 31 Oct 2012 11:22:17 +0000 (12:22 +0100)]
bluetooth: Make __near_bluetooth_parse_oob_record use struct bt_data

This will make it similar to handover agent api and thus make switching
between those two interfaces easier.

11 years agoAdd __near_agent_handover_registered function
Szymon Janc [Wed, 31 Oct 2012 11:22:16 +0000 (12:22 +0100)]
Add __near_agent_handover_registered function

It will be used to check if handover agent is registered.

11 years agoagent: Add __near_agent_handover_request_data function
Szymon Janc [Wed, 31 Oct 2012 11:22:15 +0000 (12:22 +0100)]
agent: Add __near_agent_handover_request_data function

11 years agoagent: Add __near_agent_handover_push_data function
Szymon Janc [Wed, 31 Oct 2012 11:22:14 +0000 (12:22 +0100)]
agent: Add __near_agent_handover_push_data function

11 years agoRelease 0.8 0.8
Samuel Ortiz [Tue, 30 Oct 2012 17:22:08 +0000 (18:22 +0100)]
Release 0.8

11 years agonetlink: Add netlink event socket
Samuel Ortiz [Tue, 30 Oct 2012 15:48:40 +0000 (16:48 +0100)]
netlink: Add netlink event socket

Some netlink command can send multicast event before they're done.
To receive them the netlink_event function should be listening on
an event dedicated socket.

11 years agondef: Remove the cr record from Hs message
Olivier Guiter [Mon, 29 Oct 2012 10:30:50 +0000 (11:30 +0100)]
ndef: Remove the cr record from Hs message

NFC forum specs says that cr record should not be found on Hs messages.

As near_ndef_prepare_handover_record() is used to build Hs and Hr,
we have to remove the cr record only for Hs. To handle this case (and also
other cases where e.g. there's no ac record), the message begin/end flags
routines must be more granular (separate MB and ME setting routines).

11 years agondef: Fix handover version check
Olivier Guiter [Fri, 26 Oct 2012 10:14:55 +0000 (12:14 +0200)]
ndef: Fix handover version check

In Connection Handover, Version check should return an empty Hs (with
the supported version) when major part is different from the local
major version.

11 years agohandover: Fix to allow two handover requests
Olivier Guiter [Mon, 22 Oct 2012 13:52:57 +0000 (15:52 +0200)]
handover: Fix to allow two handover requests

Test case 7 verifies that the remote handover server does not close the data
link connection after the first handover request message.

11 years agohandover: Handle Handover frames without ac records
Olivier Guiter [Mon, 22 Oct 2012 13:52:55 +0000 (15:52 +0200)]
handover: Handle Handover frames without ac records

11 years agobluetooth: Extend mime_type with bluetooth properties
Olivier Guiter [Mon, 22 Oct 2012 13:52:54 +0000 (15:52 +0200)]
bluetooth: Extend mime_type with bluetooth properties

To comply with handover specs, if the incoming Hr OOB doesn't include
SP hash/randomizer keys, the reply (Hs) should not include such
information. So we store it to the cfg mime_type.

11 years agohandover: Change carriers type to bitfield
Olivier Guiter [Mon, 22 Oct 2012 13:52:53 +0000 (15:52 +0200)]
handover: Change carriers type to bitfield

This would allow multiple carriers at the same time (e.g. Bluetooth
and Wifi)

11 years agohandover: Change behavior for empty (no ac) frames
Olivier Guiter [Mon, 22 Oct 2012 13:52:52 +0000 (15:52 +0200)]
handover: Change behavior for empty (no ac) frames

Some frame may not have ac records, so we have to jump to the parsing code
right after checking the frame header.

11 years agondef: Skip record header when parsing handover records
Samuel Ortiz [Wed, 24 Oct 2012 15:42:20 +0000 (17:42 +0200)]
ndef: Skip record header when parsing handover records

11 years agondef: Fix offset check when parsing NDEF records
Olivier Guiter [Mon, 22 Oct 2012 13:52:50 +0000 (15:52 +0200)]
ndef: Fix offset check when parsing NDEF records

For each record header entry we need to check that the offest and the
payload length is not longer than the total record length.

11 years agoagent: Push raw NDEF along with the matching record
Samuel Ortiz [Tue, 23 Oct 2012 21:50:29 +0000 (23:50 +0200)]
agent: Push raw NDEF along with the matching record

11 years agondef: Add records raw data to a D-Bus iterator
Samuel Ortiz [Tue, 23 Oct 2012 17:53:18 +0000 (19:53 +0200)]
ndef: Add records raw data to a D-Bus iterator

This will be needed by the NDEF agent raw data export routines.

11 years agondef: Export record's raw data
Samuel Ortiz [Tue, 23 Oct 2012 17:33:25 +0000 (19:33 +0200)]
ndef: Export record's raw data

11 years agoAUTHORS: Mention Krzysztof's contributions
Samuel Ortiz [Mon, 22 Oct 2012 09:03:06 +0000 (11:03 +0200)]
AUTHORS: Mention Krzysztof's contributions

11 years agondef: Change near_ndef_parse function name
Krzysztof Lyczkowski [Wed, 26 Sep 2012 13:04:53 +0000 (15:04 +0200)]
ndef: Change near_ndef_parse function name

Add suffix "_msg" to function near_ndef_parse for
name consistency and to stress out its role.

11 years agondef: Use appropriate naming for record payload structures
Krzysztof Lyczkowski [Wed, 26 Sep 2012 13:04:52 +0000 (15:04 +0200)]
ndef: Use appropriate naming for record payload structures

Word "record" was used not only for records but also
for "payloads" wchich was unclear. Now record
contains general header and specyfic payload.

11 years agondef: Add randomizing function for Collision-RR
Krzysztof Lyczkowski [Wed, 26 Sep 2012 13:04:51 +0000 (15:04 +0200)]
ndef: Add randomizing function for Collision-RR

11 years agop2p: Close a created socket if it's already bound
Samuel Ortiz [Mon, 15 Oct 2012 10:17:03 +0000 (12:17 +0200)]
p2p: Close a created socket if it's already bound

11 years agohandover: No need to explicitely close the server socket
Samuel Ortiz [Fri, 12 Oct 2012 12:51:37 +0000 (14:51 +0200)]
handover: No need to explicitely close the server socket

gio will do that when the channel refcount drops to 0.

11 years agohandover: Unref client push channel after adding the watch
Samuel Ortiz [Fri, 12 Oct 2012 10:41:25 +0000 (12:41 +0200)]
handover: Unref client push channel after adding the watch

g_io_add_watch() bumps the channel refcount to 2, so it can be unreferenced
after that.
Also, since it is set to close on unref there is no need to explicitely
close it when removing the source.

11 years agobluetooth: Do not use near_info for displaying successful pairing string
Samuel Ortiz [Fri, 12 Oct 2012 08:20:11 +0000 (10:20 +0200)]
bluetooth: Do not use near_info for displaying successful pairing string

11 years agondef: Use DBG instead of near_info for Hs preparation succes path
Samuel Ortiz [Fri, 12 Oct 2012 08:19:35 +0000 (10:19 +0200)]
ndef: Use DBG instead of near_info for Hs preparation succes path

11 years agondef: Parsing complete is not an error
Samuel Ortiz [Thu, 11 Oct 2012 21:52:07 +0000 (23:52 +0200)]
ndef: Parsing complete is not an error

Use DBG instead of near_error.

11 years agoRelease 0.7 0.7
Samuel Ortiz [Wed, 10 Oct 2012 08:30:27 +0000 (10:30 +0200)]
Release 0.7

11 years agotag: Correct NDEF header for tag type 1 and 2
Dorota Moskal [Fri, 28 Sep 2012 09:07:30 +0000 (11:07 +0200)]
tag: Correct NDEF header for tag type 1 and 2

If NDEF size is larger than 0xfe, length field inside TLV block
should be 3 bytes long.

11 years agonfctype4: Call write callback when writing failed
Dorota Moskal [Thu, 27 Sep 2012 11:22:23 +0000 (13:22 +0200)]
nfctype4: Call write callback when writing failed

In some cases when writing was broken, e.g. when there was
not enough space on tag, tag write callback wasn't called
and writing was left 'in progress'.

11 years agonfctype3: Call write callback when writing failed
Dorota Moskal [Thu, 27 Sep 2012 11:22:22 +0000 (13:22 +0200)]
nfctype3: Call write callback when writing failed

In some cases when writing was broken before allocating
the cookie (e.g. when there was not enough space on tag)
tag write callback wasn't called and writing was left 'in progress'.

11 years agonfctype3: Call callback function while freeing cookie
Dorota Moskal [Thu, 27 Sep 2012 11:22:21 +0000 (13:22 +0200)]
nfctype3: Call callback function while freeing cookie

When each operation is finished (no matter if succeeded or not),
callback has to be called before returning. In some places it was,
but in other - not. Moving calling callback to cookie release
makes sure it is always called and shortens the source code.

11 years agonfctype2: Call write callback when writing failed
Dorota Moskal [Thu, 27 Sep 2012 11:22:20 +0000 (13:22 +0200)]
nfctype2: Call write callback when writing failed

In some cases when writing was broken before allocating
the cookie (e.g. when there was not enough space on tag)
tag write callback wasn't called and writing was left 'in progress'.

11 years agonfctype2: Call callback function while freeing cookie
Dorota Moskal [Thu, 27 Sep 2012 11:22:19 +0000 (13:22 +0200)]
nfctype2: Call callback function while freeing cookie

When each operation is finished (no matter if succeeded or not),
callback has to be called before returning. In some places it was,
but in other - not. Moving calling callback to cookie release
makes sure it is always called and shortens the source code.

11 years agonfctype1: Call write callback when writing failed
Dorota Moskal [Thu, 27 Sep 2012 11:22:18 +0000 (13:22 +0200)]
nfctype1: Call write callback when writing failed

In some cases when writing was broken before allocating
the cookie (e.g. when there was not enough space on tag)
tag write callback wasn't called and writing was left 'in progress'.

11 years agonfctype1: Call callback function while freeing cookie
Dorota Moskal [Thu, 27 Sep 2012 11:22:17 +0000 (13:22 +0200)]
nfctype1: Call callback function while freeing cookie

When each operation is finished (no matter if succeeded or not),
callback has to be called before returning. In some places it was,
but in other - not. Moving calling callback to cookie release
makes sure it is always called and shortens the source code.

11 years agomifare: Correct memory leaks
Dorota Moskal [Thu, 27 Sep 2012 11:22:24 +0000 (13:22 +0200)]
mifare: Correct memory leaks

There were some memory leaks:
* in some reading and writing callback functions,
  in case sending command failed (e.g. after
  failed authorisation), cookie wasn't released,
* after checking presence global cookie wasn't released,
* while processing MADs before writing, new data was
          allocated (although there was no need for this) and so
          the old one was lost.

11 years agomifare: Check access rights while writing
Dorota Moskal [Thu, 27 Sep 2012 11:22:15 +0000 (13:22 +0200)]
mifare: Check access rights while writing

As access rights can vary for each sector, some sectors may be
writable but the next one can be read only. If so, new tag size
(valid only for writing) is calculated. Then check for enough space
on tag is done.

11 years agomifare: Add Readonly flag support
Dorota Moskal [Thu, 27 Sep 2012 11:22:14 +0000 (13:22 +0200)]
mifare: Add Readonly flag support

Readonly flag is set if first NFC sector isn't writable
with key A (as key B is not supported).

11 years agomifare: Correct processing MADs
Dorota Moskal [Thu, 27 Sep 2012 11:22:13 +0000 (13:22 +0200)]
mifare: Correct processing MADs

NFC sectors have to be continuous, so only some sectors
at the beginning and at the end of tag can be non-NFC.
First non-NFC sector after NFC sectors should end
MAD processing and than resulting tag size and sector list
should be saved.

11 years agomifare: Fix possible NULL pointer dereference in reading loop
Dorota Moskal [Thu, 27 Sep 2012 11:22:12 +0000 (13:22 +0200)]
mifare: Fix possible NULL pointer dereference in reading loop

After reading first sector, reading loop should check if sector list
is NULL in case only one valid NFC sector is present.

11 years agonfctypes: Reduce amount of goto statements
Wiktor Lawski [Thu, 27 Sep 2012 08:31:28 +0000 (10:31 +0200)]
nfctypes: Reduce amount of goto statements

goto statements were removed for functions that on error only release cookies.

11 years agonfctypes: Simplify returning error codes
Wiktor Lawski [Thu, 27 Sep 2012 08:31:27 +0000 (10:31 +0200)]
nfctypes: Simplify returning error codes

After refactoring near_adapter_send and its calls it is possible now to
simplify returning error codes. Also removed a couple of local variables
from functions where it is safe to return error code directly.

11 years agoadapter: Refactor function near_adapter_send
Wiktor Lawski [Thu, 27 Sep 2012 08:31:26 +0000 (10:31 +0200)]
adapter: Refactor function near_adapter_send

Now this function will release allocated data using callback, so it will
be unnecessary to check its returned error code (if callback was passed).
Main reasons to prepare this change were improvement of code readability
and removing error prone code paths.

11 years agotag: Fix a possible double free
Thierry Escande [Mon, 8 Oct 2012 14:30:28 +0000 (16:30 +0200)]
tag: Fix a possible double free

On a successful write tag operation, tag->data is freed by write_cb, then it
gets re-allocated through __near_tag_read. At last tag->data is freed by
free_tag when the tag is removed from its hash table.
But if the write operation failed, tag->data is freed by write_cb but
__near_tag_read is not called (status != 0) and thus is not re-allocated.
The double free occurs when the tag is removed and free_tag is called.

This fix simply set tag->data to NULL in write_cb.

11 years agotag: Add near_tag_get_blank function
Dorota Moskal [Thu, 27 Sep 2012 08:31:22 +0000 (10:31 +0200)]
tag: Add near_tag_get_blank function

This is needed by the MIFARE plugin.

11 years agotag: Dereference writing after reading new data
Dorota Moskal [Mon, 8 Oct 2012 14:13:24 +0000 (16:13 +0200)]
tag: Dereference writing after reading new data

tag->write_msg was dereference just after writing was finished.
Therefore, new writing command might start before reading new data
has been finished.

Preventing write to start before read is completed is especially
important for Mifare Classic as it prevents authorisation failure.

11 years agotag: Don't check presence while busy
Dorota Moskal [Mon, 8 Oct 2012 19:52:11 +0000 (21:52 +0200)]
tag: Don't check presence while busy

When reading, writing or formating is in progress, no check presence
should be done.

11 years agondef: Set proper URI identifier when writing URI NDEF
Samuel Ortiz [Fri, 5 Oct 2012 10:37:02 +0000 (12:37 +0200)]
ndef: Set proper URI identifier when writing URI NDEF

When the URI doesn't have any know prefix (e.g. google.com, without the
http://) we should set the URI identifier to 0, not 0x24 (RFU).

11 years agoagent: Release handover agent on exit
Szymon Janc [Fri, 21 Sep 2012 14:48:32 +0000 (16:48 +0200)]
agent: Release handover agent on exit

If handover agent is registered release it on exit.

11 years agoagent: Check if adding disconnect watch succeed
Szymon Janc [Fri, 21 Sep 2012 14:48:31 +0000 (16:48 +0200)]
agent: Check if adding disconnect watch succeed

Return error if call to g_dbus_add_disconnect_watch failed when
registering handover agent.

This could lead to situation when agent was registered without watch.
If agent exited without unregistering (e.g. due to crash) further
register attempts would be rejected by neard.

11 years agohandover: Try to send HS only if message preparation succeed
Szymon Janc [Fri, 21 Sep 2012 14:48:30 +0000 (16:48 +0200)]
handover: Try to send HS only if message preparation succeed

near_ndef_prepare_handover_record can return NULL in message
preparation failed e.g. due to failure in requesting data from handover
agent. This could result in crash due to NULL pointer dereference.

11 years agohandover: Correct FRAME_TYPE_OFFSET value
Szymon Janc [Fri, 21 Sep 2012 14:48:29 +0000 (16:48 +0200)]
handover: Correct FRAME_TYPE_OFFSET value

FRAME_TYPE_OFFSET is 3 bytes. This fix not sending HS due to invalid
string compare.

11 years agoplugins: Refactor functions for releasing cookies
Wiktor Lawski [Wed, 19 Sep 2012 13:20:48 +0000 (15:20 +0200)]
plugins: Refactor functions for releasing cookies

Now all plugins will release their cookies in an analogous manner. This
approach will simplify and reduce the amount of code because those functions
will be called by refactored version of near_adapter_send.

11 years agonfctypes: Improve consequence of goto labels
Wiktor Lawski [Wed, 19 Sep 2012 13:20:47 +0000 (15:20 +0200)]
nfctypes: Improve consequence of goto labels

Now all goto labels in files plugins/nfctype[1-4].c are named 'out_err'
instead of 'out'.

11 years agoplugins: Standardize function signatures
Wiktor Lawski [Wed, 19 Sep 2012 13:20:46 +0000 (15:20 +0200)]
plugins: Standardize function signatures

Now nfctypes have more similar interface (both inside and outside).

11 years agonfctype1: Refactor nfctype1_read
Wiktor Lawski [Wed, 19 Sep 2012 13:20:45 +0000 (15:20 +0200)]
nfctype1: Refactor nfctype1_read

Created helper function nfctype1_read_meta to improve readability, avoid code
duplication and memory leaks in case of errors.

11 years agonfctype1: Improve nfctype1_read readability
Wiktor Lawski [Wed, 19 Sep 2012 13:20:44 +0000 (15:20 +0200)]
nfctype1: Improve nfctype1_read readability

WHEN either uid is NULL or uid_length is not equal to UID_LENGTH AND uid is
not NULL, uid_length must to be NOT equal to UID_LENGTH, so additional
conditional in if statement is not necessary. It will be always true. It is
only harder to analyze function code.

11 years agop2p: Fix not freed channel allocated in p2p_bind
Wiktor Lawski [Wed, 19 Sep 2012 13:20:43 +0000 (15:20 +0200)]
p2p: Fix not freed channel allocated in p2p_bind

Channel was not freed because of non-zero reference count. Function
g_io_add_watch increments reference count (to value of 2 in p2p_bind). Pointer
to channel is not saved by neard, so the only one reference count decrement is
done by g_source_remove in function free_server_data. It is safe to decrement
reference count right after adding a watch.

Issue was reported by valgrind:

378 (360 direct, 18 indirect) bytes in 3 blocks are definitely lost in loss record 118 of 143
    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x412102: p2p_listen (p2p.c:260)
    by 0x4E6A4DF: g_hash_table_foreach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x417C06: near_device_driver_register (device.c:468)
    by 0x419771: __near_plugin_init (plugin.c:180)
    by 0x407E2E: main (main.c:214)

11 years agonfctype1: Fix possible memory leak in meta_recv
Wiktor Lawski [Wed, 19 Sep 2012 13:20:42 +0000 (15:20 +0200)]
nfctype1: Fix possible memory leak in meta_recv

If read_dynamic_tag returned an error or neard does not support specified
response, memory allocated for t1_tag should also be freed.

11 years agoadapter: Fix error message for StopPollLoop
Wiktor Lawski [Wed, 19 Sep 2012 13:20:41 +0000 (15:20 +0200)]
adapter: Fix error message for StopPollLoop

Now when adapter is not polling and StopPollLoop is called, correct error
message will be returned.

11 years agoAUTHORS: Mention Dorota's contributions
Samuel Ortiz [Fri, 21 Sep 2012 06:50:10 +0000 (08:50 +0200)]
AUTHORS: Mention Dorota's contributions

11 years agosnep: Add handover select frame check
Olivier Guiter [Thu, 13 Sep 2012 14:46:44 +0000 (16:46 +0200)]
snep: Add handover select frame check

11 years agotest: Add a Bluetooth handover wrapper script
Samuel Ortiz [Wed, 19 Sep 2012 00:15:52 +0000 (02:15 +0200)]
test: Add a Bluetooth handover wrapper script

11 years agoadapter: Remove the linked device when DEP goes down
Samuel Ortiz [Mon, 17 Sep 2012 10:06:42 +0000 (12:06 +0200)]
adapter: Remove the linked device when DEP goes down

11 years agodevice: Add a target index accessor
Samuel Ortiz [Mon, 17 Sep 2012 10:06:14 +0000 (12:06 +0200)]
device: Add a target index accessor

11 years agotag: Remove redundant __near_tag_get_idx function
Dorota Moskal [Mon, 10 Sep 2012 08:06:30 +0000 (10:06 +0200)]
tag: Remove redundant __near_tag_get_idx function

__near_tag_get_idx function wasn't needed as the same action was
performed by near_tag_get_target_idx.

11 years agomifare: Correct comments format and DBG message
Dorota Moskal [Mon, 10 Sep 2012 08:06:27 +0000 (10:06 +0200)]
mifare: Correct comments format and DBG message

11 years agomifare: Add Mifare Classic writing functions
Dorota Moskal [Mon, 10 Sep 2012 08:06:26 +0000 (10:06 +0200)]
mifare: Add Mifare Classic writing functions

Added specific Mifare Classic tag writing funcions, following
Mifare Classic mandatory NDEF Write Procedure:
* Setting length field of NDEF message to 00h first,
* writing NDEF data,
* correcting length field to actual value after.

11 years agomifare: Rename mifare cookie fields
Dorota Moskal [Mon, 10 Sep 2012 08:06:25 +0000 (10:06 +0200)]
mifare: Rename mifare cookie fields

Change 'rs' to 'rws' in 4 cookie fields to note that they will also
be used for writing: rws_next_fct, rws_block_start, rws_block_end,
rws_completed.

11 years agomifare: Add mifare_check_presence and check_presence
Dorota Moskal [Mon, 10 Sep 2012 08:06:24 +0000 (10:06 +0200)]
mifare: Add mifare_check_presence and check_presence

When tag type 2 is Mifare Classic, specific mifare check presence is run.

11 years agomonitor-near: Add Devices to the Adapter properties
Samuel Ortiz [Thu, 13 Sep 2012 13:57:29 +0000 (15:57 +0200)]
monitor-near: Add Devices to the Adapter properties

11 years agobluetooth: Fix OOB alignement issue
Samuel Ortiz [Thu, 13 Sep 2012 13:55:43 +0000 (15:55 +0200)]
bluetooth: Fix OOB alignement issue

Use the BlueZ alignement macro access for that matter. It could eventually
be exported through near.h if needed.

11 years agosnep: Add some further comments on the SNEP_REQ_GET support code
Samuel Ortiz [Thu, 13 Sep 2012 13:40:26 +0000 (15:40 +0200)]
snep: Add some further comments on the SNEP_REQ_GET support code

11 years agoadapter: Send the Devices property changed earlier
Samuel Ortiz [Thu, 13 Sep 2012 13:29:26 +0000 (15:29 +0200)]
adapter: Send the Devices property changed earlier

As opposed to a tag, a device should be accessible before the first read
(That could potentially never happen) so the Adapter Devices property change
should be sent when the DEP link is up.

11 years agosnep: SNEP GET client for Android 4.1 handover support
Olivier Guiter [Tue, 11 Sep 2012 13:44:22 +0000 (15:44 +0200)]
snep: SNEP GET client for Android 4.1 handover support

Prepare a SNEP GET frame to request bluetooth handover select frame from
Android 4.1 devices.

11 years agosnep: SNEP GET request for Android 4.1 handover
Olivier Guiter [Tue, 11 Sep 2012 13:44:21 +0000 (15:44 +0200)]
snep: SNEP GET request for Android 4.1 handover

Handle incoming SNEP GET request from an Android 4.1 device. This code
includes a hack to fix malformed Android NDEF frame ('Hr' is used instead
of 'cr').
Also handling SNEP GET from the server goes against the SNEP specifications
recomendations but is mandatory to support all Jelly Bean NFC devices.

11 years agohandover: Add fallback code for p2p services
Olivier Guiter [Tue, 11 Sep 2012 13:44:20 +0000 (15:44 +0200)]
handover: Add fallback code for p2p services

This code would allow non-strict implementations of p2p (e.g. Android 4
uses SNEP for handover, so first we try to connect to the Handover service,
and, if it fails, fallback to SNEP service) services.