Bug 996426 - [NFC] Rename emulator commands from 'nfc ntf' to 'nfc nci'. r=tzimmermann
Bug 1000935: Introduce LLCP data links

According to the LLCP specification, data links transfer data between
two Service Access Points; either in connected or unconnected mode.

This patch introduces the data structure llcp_data_link to represent
data links. It replaces the llcp_connection_state structure, which had
a similar purpose, but could incorrectly named and could not deal with
LLCP connections.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added infrastructure for sending LLCP PDUs in NCI packets

LLCP peers mutually pass send permission, and LLCP requires PDUs
to be sent at specific points when the peer has the permission to
do so. If no PDUs are available for transmission, a SYMM PDU has
to be sent for passing permissions to the other peer.

This patch adds the necessary infrastructure to inject LLCP PDUs
into the stream of SYMM PDUs. If the user creates a new LLCP PDU
it is either

  - send immediatelly if the peer has permisison to do so, or
  - queued up to be sent when permission has been received.

Just as before, if no PDUs are queued up, a SYMM PDU will be sent
after a timeout has been reached. Sending a PDU also passes send
permission to the peer.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Implement LLCP PDUs for connection handling

This patch adds support for processing connection-related LLCP
PDUs that was previously missing. The PDUs include

  - CONNECT for connection requests,
  - DISC for disconnection requests,
  - CC for signalling successful connection requests, and
  - DM for signalling failed of ended connections.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added command 'llcp connect' to emulator console

The emulator console now accepts commands for sending LLCP CONNECT
PDUs to the guest system. This feature is not for regular users or
test cases, but only for testing the internals of the emulator!

A possible command looks like

  nfc llcp connect 4 4

where the trailing numbers are the indices of the DSAP and SSAP
Service Access Points. In this example the command would connect
the SAPs for SNEP, which are used for transfering NDEF messages.
SAP numbers are standardized by the NFC Forum.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added LLCP PDUs for sending data

This patch adds LLCP PDUs for sending and receiving data. These
are

  - FRMR for rejecting received frames,
  - I for transfering information over LLCP,
  - RR for signalling receive readiness, and
  - RNR for signalling unreadiness.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added SNEP protocol

The Simple NDEF Exchange Protocol is a high-level protocol for
transfering NDEF records between two NFC peers, with 'put' and
'get' primitives similar to HTTP. The current support for SNEP
includes 'put' and some response codes that are necessary for
sending NDEF records.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Implemented SNEP LLCP SAPs

This commit adds support for SNEP on top of LLCP.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added NDEF messages

The NFC Data Exchange Format specifies the encoding of data for
transmission over NFC connections. This commit adds the protocol
primitives for NDEF and some helper functions.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added SNEP PUT sending and receiving

SNEP PUT is the SNEP request for sending NDEF messages to an NFC
peer. This commit adds functions for sending and receiving PUT
request. The send function sends an NDEF message to the peer, as
specified by SNEP. The receive function returns the data that
was transfered with the last SNEP PUT that was received from the
peer.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added base64 encoding and decoding

To be compatible with all terminals, we'll need base64 encoding for
strings that are read or written on the emulator's console. This
patch adds encoding and edecoding routines for base64.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added SNEP PUT console command

This commit adds a console for using SNEP PUT. An example command
for sending an NDEF message looks like

  snep put 4 4 [0, 3, foo, bar,]

The parameters '4' '4' are LLCPs destination and source SAPs. The
NDEF message's records are given in brackets. Up to 4 records can
be specified. The syntax for each records is

  [<flags>, <tnf>, <type>, <payload>, <id>]

The values of <type>, <payload>, and <id> are base-64 encoded strings,
with <id> being optional. The value of <flags> is a bitmask of NDEF
record flags, but the emulator will add missing flag bits according to
the specified record.

If no NDEF message is given, such as in

  snep put 4 4

the command will output the last NDEF message that was received over
the given SAPs. The message will be printed in JSON encoding for easy
parsing in JavaScript. String fields are again encoded in base64.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Added automatic LLCP connect to SNEP put

SNEP over LLCP connections needs a successful LLCP connect first. An
example looks like

  llcp connect 4 4
  snep put 4 4 [<NDEF>]

This patch adds support for automatically establishing connections
for SNEP PUT if necessary. Running

  snep put 4 4 [<NDEF>]

will first connect LLCP SAPs 4/4 and afterwards send the SNEP PUT
request.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Clear NFC remote endpoint on activation

Some internal state needs to be cleared before the RE structure
can be used. We do this at activation time.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug 1000935: Track last SAP connection in remote endpoint

NFC DOM APIs handle LLCP commands internally and don't expose it
to Gecko or even Gaia. And example is NfcPeer.sendNDEF. To easily
access transfered data from the emulator's console, the RE now
stores the last SAPs that were in use. The received NDEF data can
be accessed by specifying '-1' for SAPs. For example

  snep put -1 -1

prints the last NDEF message that was received via SNEP PUT over
LLCP.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>