Monday, April 30, 2012

Near Field Communication - Android Perspective

NFC :
NFC stands for Near Field Communication .A technology which aims at communicating between two NFC compatible devices, tags(NFC Tags) , Readers. Writers, etc placed in a close range of ~4cm.A device communicating with other NFC device can communicate in three ways :
> Reader - Writer Modes
   In this mode a device can read or write from any other NFC device.A phoen with NFC enabled can read or write a tag(NFC memory) from the another Phone.The data being read is in the form of NDEF (NFC Data Exchange Format) format which is genearlly exchanged  with the NFC device.
> Peer -2- peer Mode
In this mode two device can interact with each other using the Peer-2-peer messages and the communicating link is the NFC.Of course the speed is very slow yet this is a zero configuration setup mode.
> Card Emulation modes
This is the most widely yet most rarely used mode .In this a phone can actually emulate(can behave) as a Credit card, or any secure payment card .The information is stored in the NFC Secure element which can reside in the phone at three different places(one at a time)
> SIM card

> SD card
> Embedded Secure Element called SmartMx(similar to CN072 is a secure element in the Smart MX family)

According to the NXP documentation of PN544, three SE variants are
supported:
- SIM Card (via UICC)
- Embedded (SmartMX security chip)
- SD Card
yes Keys are private and most likely needs to be provided by Service Provider

CN072 is a secure element in the Smart MX family



I have tried some commands, which I found on page eleven at the
following pdf document:

http://www.nfc-reader.com/NFC-smart-card-reader/ACR122-API-Manual/API_ACR122.pdf

public static final byte[] KEY_DEFAULT =  {(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF, 
(byte)0xFF,(byte)0xFF}; 

Public byte [] exchangeAPDU(int handle,byte [] data){...} 

I tested with an Omnikey 5321, but that reader automatically activated
the SMX up to the ISO 14443-4 layer, so it was not possible to transmit
any MIFARE Commands.

All these are connected via SWP_UICC(SIM Card) or NFC(NFC wired mode - SD Card or SmartMx).The connection is between NFC Controller like pn544(a NFC micro controller fomr the NXP) and the Secure Element.

     NFC Android Code Study :
        How NFC works right from API level to System Level


      NFC Java classes :
                     frameworks/base/core/java/android/nfc
                     frameworks/base/core/java/com/android/internal/nfc

     NFC Application :
                   packages/apps/Nfc
                     
    Hardware abstraction layer from the NXP :
                       external/libnfc-nxp

             

With JavaME access to the secure element was provided with JSR177 which supported the communication with smart card applications usind APDU commands - atleast Read


Latest and uptoDate Discussion is going here.



Phones available to purchase today:
  • The Samsung Galaxy Nexus is the latest Google reference handset and is now shipping in the UK and the US. The phone runs Android 4.0 Ice Cream Sandwich. Follow the Galaxy Nexus story here.
  • The Google Nexus S, a full-featured smartphone running Android 2.3 'Gingerbread' and manufactured by Samsung, has NFC support built in. The device, the first widely available and easily obtainable NFC handset, is available at retail in the US (together with a 4G variant, the Nexus S 4G from Sprint), the UK and 27 other countries.
  • Samsung has begun shipping the Galaxy S II Android 2.3 handset. An NFC version of the phone has been available since launch in Korea, but is only just starting to appear in other markets, via Orangein Europe and AT&T and T-Mobile in the USA.
  • The BlackBerry Bold 9790, codenamed 'Bellagio', and the BlackBerry Curve 9380, also known as 'Orlando' were announced in November 2011 and are now shipping.
  • The BlackBerry Bold 9900 and 9930, the first handsets from Research in Motion to include NFC, were announced in early May 2011 and are now shipping.
  • The BlackBerry Curve 9350BlackBerry Curve 9360 andBlackBerry Curve 9370 were announced in August 2011 and are now shipping.
  • The Porsche Design P'9981 by BlackBerry is a 'restricted edition' leather and stainless steel-clad designer handset announced in October 2011 that retails at US$2,000. The device was referred to as the R47 and the Bold 9980 during its development.
  • An NFC version of the Samsung Galaxy Note tablet phone is available in Korea and will be coming to AT&T in the US during the second quarter of 2012.
  • The Nokia C7 smartphone contains NFC hardware and, via Symbian Belle, can now be used for NFC tag reading and writing applications. The C7 will be able to support secure NFC services such as mobile payments from the first half of 2012. The Nokia Astound, the US version of the Nokia C7 which is exclusive to T-Mobile and is positioned as an entry-level smartphone, also comes with NFC.
  • The Nokia N9 is a high-end MeeGo-based tablet-style smart phone which started shipping in September 2011. The 16GB version retails at of €480 (US$652) while the 64GB option carries a price tag of €560 (US$761) before taxes or operator subsidies. The N9 is not believed to support secure NFC.
  • Nokia announced three NFC phones in August 2011 — the Nokia 700,Nokia 701 and Nokia 600. The 700 and the 701 are available now but the 600 was cancelled before it shipped. All run Symbian Belle andwill be able to support secure NFC services such as mobile payments from the first half of 2012.
  • The Nokia 603 is a Symbian Belle device with NFC, designed for first time smartphone owners. The device retails at around €200 (US$275) before taxes and subsidies and started shipping on 21 October 2011.
  • The Nokia Oro is a phone "intended for someone who doesn't want their mobile device to look the same as other people's." The handset, which bears more than a passing resemblance to Nokia's C7, is gold-plated with a sapphire crystal home key and a fine leather back. The Symbian Anna based device also boasts NFC. The Oro retails at upwards of €800.
  • The Acer E320 Liquid Express is an entry-level Android smartphone and is the Taiwanese manufacturer's first NFC handset. The company has stated that all its Android smartphones will in future come with NFC.
  • The HTC Ruby, also known as the HTC Amaze 4G, is a high-end Android device and the first NFC phone from the Taiwanese manufacturer. It became available in October 2011 from T-Mobile in the US. The industry had long been expecting the arrival of an NFC phone from the company in the third quarter of 2011.
  • A version of the HTC Incredible designed to run China UnionPay's NFC payments service via a microSD-based NFC add-on was announced in August 2011.
  • The Sonim XP1301 Core NFC is an ultra-rugged handset designed for commercial use. The sub-£300 device was announced on 20 September 2011 and is available now.
  • Sonim's XPand NFC expansion pack is a battery cover replacement that adds NFC to the XP3300 Force rugged mobile phone.
  • The Samsung Wave 578 is now available from Orange France, in the UK as a 'Quick Tap' handset via Orange, and in Singapore. The handset, announced at the Mobile World Congress in February 2011, runs Samsung's Bada smartphone platform and will be offered by Orange across Europe.
  • The Motorola Droid Razr has not been advertised as an NFC handset, but a teardown has revealed it carries an NXP PN544 NFC controller chip.
  • The LG T530 is the Korean electronics company's first mass-market NFC handset, a touchscreen feature phone. It is available now in France as the LG Ego.
  • The LG Optimus Net is an Android smartphone that comes with NFC in some markets.
  • The Prada phone by LG 3.0, also referred to as the LG-P940 and the K2, is the LG's first Android-based NFC device, running version 2.3 Gingerbread.
  • The Mobiwire Cosyphone is an NFC handset supporting the single wire protocol (SWP). It is aimed at the over-50s and at the B2B market.
  • The Samsung S5230 NFC, also known as GT-5230NStarAvila,Player One and Tocco Lite, is widely available. This phone isavailable at retail in France, where it is known as the Samsung Player One Cityzi. It was also used in Telefonica's Sitges pre-commercial pilot as well as in the Czech Republic and Poland. The Tocco Lite was also the first NFC phone offered by Orange for itsQuick Tap NFC payments roll-out in the UK.
  • The Samsung S5260 NFC, also known as the GT-S5260P, isavailable with NFC from Orange in France where it is known as thePlayer City.
  • The Huawei Sonic is the Chinese telecoms giant's first NFC handset, a sub-US$200 Android phone. The device, also known as the U8650NFC, is marketed in Turkey as the Turkcell T20.
  • The Turkcell T11 Maxiphone is an Android 2.3.4-based single wire protocol smartphone, manufactured by China's ZTE and priced at 389TL (US$213). The T11, launched in January 2012, is the second Turkcell-branded NFC handset and supports the world's first SIM-based NFC road toll payment application.
  • The Sky Vega Racer from Pantech is a high-end dual-core smartphone that is only available in Korea. Billed as the fastest Android handset yet, it is aimed at the same market segment as Samsung's Galaxy S II.
  • The Sky Vega LTE is a premium smartphone for the South Korean market, announced in October 2011.
  • The Samsung SHW-A170K is a touch screen featurephone designed for KT and to meet the needs of the Korean market. It features SWP and is the launch handset for KT's Show Touch commercial NFC service.
  • Chinese phone manufacturer Hedy is supplying SWP-compliant NFC handsets for China Unicom's NFC roll out, using an NFC controller manufactured by Shanghai Fudan Microelectronics.
  • Shanghai Simcom is also manufacturing NFC handsets using Shanghai Fudan components. The EVDO phones are marketed under the East Com brand name.
  • The Motorola MC75A HF is an enterprise-class rugged handheld computer that combines mobile communication and secure contactless transaction capability.
  • Malaysian manufacturer Fifth Media offers specialist NFC PDAs/smartphones aimed at the B2B market. The Axia A206, a collaboration with Garmin Asus and based on the latter's M10, runs Windows Mobile 6.5.3 and costs from US$620 to $700 depending on volume.
  • The Casio DT-X8 is a business-class rugged handheld terminal that can handle NFC, 2D barcodes and more.
  • The Casio IT-800, launched in late 2009, is another ruggedised handheld PDA built for business use that incorporates NFC.


Coming soon...

Phones that have been announced but are not yet shipping or widely available:
  • The Nokia 801T is a Symbian smartphone designed for use on China Mobile's TD-SCDMA network.
  • Panasonic has announced a 'global' smartphone, expected to launch in March 2012, which looks set to include NFC functionality and a 4.3-inch OLED screen.
  • Sony unveiled the Sony Xperia S at CES 2012. The handset is set to include NFC functionality, a 4.3-inch HD screen, 12MP camera and 1.5GHz dual core processor. The Xperia S is believed to be the device previously known as the Sony Ericsson Nozomi. In mid-2011 Sonycontracted to buy NFC controller chips with an embedded secure element from NXP.
  • The Sony Xperia Ion, an LTE variant of the Xperia S, was alsoannounced at CES 2012. The Ion is exclusive to AT&T and has a 4.6-inch HD screen.
  • The Lenovo K800 features NFC and will be the first smartphone to be built around Intel processors. The device, announced at CES 2012by Intel CEO Paul Otellini and Lenovo senior VP Liu Jun, is set to be released first in China in spring.
  • LG has announced the LG Viper, which will offer NFC and Google Wallet functionality, a 4-inch 800x480 pixel screen, 5MP camera and 1.2GHz processor. The Viper is expected in 2012.
  • Microsoft's Windows Phone operating system will offer NFC in 2012, the company's Andy Lees has said. An earlier report, citing unidentified sources, said Microsoft plans to include mobile payment technology in its phone OS as part of an effort to narrow Google's lead in handset software. The OS giant has also announced there will be support for NFC in Windows 8 and a leaked corporate video hints at NFC being a major feature of Windows Phone 8.
  • HTCLGMotorolaRIMSamsung and Sony Ericsson have announced that they will all be implementing Isis' NFC and technology standards.
  • Samsung has announced two new smartphones, the Wave M and theWave Y, which run the maker's own Bada 2.0 operating system and will be available in both NFC and non-NFC versions.
  • Chinese handset manufacturer OiiA Technology has announced it will be launching a high end Android G.To smartphone with NFC in early 2012.
  • The LG Optimus LTE, also known by the model number LG LU6200, is a high-end Android smartphone which boasts a 4.5-inch HD screen, LTE and NFC. The handset is available in South Korea from the U+ network.
  • The Nokia N5, a smartphone believed to run Symbian, has cleared FCC approval in the US and can be expected soon.
  • Chinese handset manufacturer ZTE, now the world's fourth largest mobile phone maker, has announced it is to include NFC functionalityin its Android-based QSC6270 platform devices as well as a number of more entry-level feature phones from the second quarter of 2011. The company has deals with chip suppliers NXP and Inside Secure.
  • Multiple additional Android 2.3 'Gingerbread' and Android 4 'Ice Cream Sandwich'-based NFC phones are expected to become available now the latest versions of the operating system incorporate NFC support. However, it is important to understand that simply running Android 2.3+ does not mean a handset comes with NFC; special hardware is required as well.
  • RFID medical sensor specialist Gentag's GT-601 phone is aimed at "people who are concerned only with basic voice communication, mobile payments, social networks, and diagnostics using a low-cost mobile wireless device." The candybar handset is expected to retail at $119 or 89 euros and incorporates an NXP PN544 NFC controller.
  • Nokia has confirmed that all its future Symbian smartphones will support NFC from 2011.
Source :  http://www.nfcworld.com/nfc-phones-list/#available '




Good Links I have Collected on NFC:






http://phonegap.com/2011/09/26/building-an-nfc-enabled-android-application-with-phonegap/
http://www.slideshare.net/todbotdotcom/nfc-rfid-on-android
http://stackoverflow.com/questions/6770774/getting-started-with-open-nfc-emulator
http://www.finextra.com/community/fullblog.aspx?blogid=5306
http://stackoverflow.com/questions/4957062/what-is-nfc-and-its-implementation
http://groups.google.com/group/android-platform/browse_thread/thread/7f9f24ac4373a92a
http://android.stackexchange.com/questions/5044/nfc-functionality-in-google-nexus-s
http://www.nexperts.com/typo/index.php?id=19
http://buynfcstickers.com/index.php/nfc-phones
http://www.engadget.com/2011/02/22/nexus-s-and-nexus-one-get-android-gingerbread-2-3-3-fixes-rando/
http://stackoverflow.com/questions/7713378/nfc-on-samsung-nexus-s
http://www.slideshare.net/momobeijing/nokia-nfc-presentation
http://www.libnfc.org/community/topic/504/which-reader-for-nfc-communication-with-googlesamsung-nexus-s/
http://pocketnow.com/android/nexus-s-nfc-writing-capabilities-included-but-hidden
http://blog.ucilia.com/telecommunications-technology-smartphones-hardware-news/147-nfc-the-future-technology-for-mobile-phones.html
http://androidcommunity.com/nexus-s-able-to-write-nfc-tags-as-well-as-read-them-20110125/
http://www.samsungnexuss.com/samsung-google-nexus-s-hacked-to-write-nfc-tags/
http://gibraltarsf.com/blog/?p=13
http://stackoverflow.com/questions/4550335/how-to-write-rfid-tag-for-nexus-s-nfc-to-read
http://android.stackexchange.com/questions/3419/how-does-nfc-on-google-nexus-s-and-android-2-3-work
http://www.intomobile.com/2011/01/26/android-hidden-nfc-capabilities-unlocked/
http://www.nfc.cc/technology/nfc-tag-types
http://stackoverflow.com/questions/6283393/writing-nfc-tags-using-a-nexus-s
http://groups.google.com/group/android-developers/browse_thread/thread/6cc3fc3138e949c5?pli=1
http://www.google.co.in/#sclient=psy-ab&hl=en&source=hp&q=nfc+tutorial+puuting+card+in+emulation+mode+&pbx=1&oq=nfc+tutorial+puuting+card+in+emulation+mode+&aq=f&aqi=&aql=&gs_sm=e&gs_upl=7229l13945l3l14743l10l8l1l0l0l2l307l1994l0.1.5.2l9l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=7ed63dd09c3c8f36&biw=1368&bih=658
http://developer.android.com/resources/samples/NFCDemo/index.html
http://stackoverflow.com/questions/5762234/nfc-tutorial-for-android-other-than-api-demo
http://mifareclassicdetectiononandroid.blogspot.com/2011/04/reading-mifare-classic-1k-from-android.html
http://www.adafruit.com/datasheets/Introduction_to_NFC_v1_0_en.pdf
http://stackoverflow.com/questions/5197263/nfcadapter-getdefaultadapterthis-returns-null-in-emulator













How I started Gstreamer?

Gstreamer was buzzing around the town with a loud and good noise.Nearby folks like stagefright, open core were making their  stand strong for not getting replaced by the Gstreamer.While the cold war was going on I decided to take on the gstreamer tyranny in the Multimedia World .
Here is how I planned my Gstreamer knowledge sabotage.I decided I will not waste time(not so derogatory here for a software like gstreamer) much on reading the manuals and documentation.Even If I do I will hit straight to the points which makes me understand the gstreamer concepts.

So I started to follow this plan :


- Reading the Manuals and documentation- especially GStreamer Plugin Writer's Guide and GStreamer Application Development Manual .This was the toughest part, required lot of patience to sit and roll your eyes all over the screen to read the manuals and user guide documentation.


- Read the mailing list on gstreamer site - gstreamer-devel ,


- Following stack overflow on whatever I though is doubtful for me.I wanted to earn reputation as well on SO so a dual greedy motive behind this.I read most of the  Gstreamer  Tagged Question and posted few as well.I followed people with good reputation on the Gstreamer tags and they even replied most of my questions.

-After going though the Gstreamer manuals and User Guides , I decided to read the Application's source codes being written with the Gstreamer.

- Ok Now enough of reading the manuals and Documentations and goitn though the source codes I decided to contribute (no matter even if i contribute to the review comments of the Gstreamer Modules) to the Gstreamer code.So for this I joined the github,sourceforgenet and watched teh gstreamer based projects ............<under construction >

While i was studying the Gstreamer i decided to make the note(which I intended to take the form of Tutorials) so I decide to jot down my understanding on the Gstreamer.

I found few good people and really really good questions.I not only read them but also contacted them on LinkedIN
People like
Felipe Contreras and their work gave me insight on whats currently going in the Gstreamer Field.

Following are the good links I came across : ............<under construction >
  
I started with the simple hello world pro-gramme given in the Gstreamer manual :
 
Here is the code for it : 
 
#include <gst/gst.h>
#include <glib.h>


static gboolean
bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  GMainLoop *loop = (GMainLoop *) data;

  switch (GST_MESSAGE_TYPE (msg)) {

    case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      g_main_loop_quit (loop);
      break;

    case GST_MESSAGE_ERROR: {
      gchar  *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_free (debug);

      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);

      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }

  return TRUE;
}


static void
on_pad_added (GstElement *element,
              GstPad     *pad,
              gpointer    data)
{
  GstPad *sinkpad;
  GstElement *decoder = (GstElement *) data;

  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad created, linking demuxer/decoder\n");

  sinkpad = gst_element_get_static_pad (decoder, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);
}



int
main (int   argc,
      char *argv[])
{
  GMainLoop *loop;

  GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
  GstBus *bus;

  /* Initialisation */
  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);


  /* Check input arguments */
  if (argc != 2) {
    g_printerr ("Usage: %s <Ogg/Vorbis filename>\n", argv[0]);
    return -1;
  }


  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("audio-player");
  source   = gst_element_factory_make ("filesrc",       "file-source");
  demuxer  = gst_element_factory_make ("oggdemux",      "ogg-demuxer");
  decoder  = gst_element_factory_make ("vorbisdec",     "vorbis-decoder");
  conv     = gst_element_factory_make ("audioconvert",  "converter");
  sink     = gst_element_factory_make ("autoaudiosink", "audio-output");

  if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
  }

  /* Set up the pipeline */

  /* we set the input filename to the source element */
  g_object_set (G_OBJECT (source), "location", argv[1], NULL);

  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* we add all elements into the pipeline */
  /* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */
  gst_bin_add_many (GST_BIN (pipeline),
                    source, demuxer, decoder, conv, sink, NULL);

  /* we link the elements together */
  /* file-source -> ogg-demuxer ~> vorbis-decoder -> converter -> alsa-output */
  gst_element_link (source, demuxer);
  gst_element_link_many (decoder, conv, sink, NULL);
  g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);

  /* note that the demuxer will be linked to the decoder dynamically.
     The reason is that Ogg may contain various streams (for example
     audio and video). The source pad(s) will be created at run time,
     by the demuxer when it detects the amount and nature of streams.
     Therefore we connect a callback function which will be executed
     when the "pad-added" is emitted.*/


  /* Set the pipeline to "playing" state*/
  g_print ("Now playing: %s\n", argv[1]);
  gst_element_set_state (pipeline, GST_STATE_PLAYING);


  /* Iterate */
  g_print ("Running...\n");
  g_main_loop_run (loop);


  /* Out of the main loop, clean up nicely */
  g_print ("Returned, stopping playback\n");
  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (pipeline));

  return 0;
}
 
 
Before compiling and running this  you have to install the Gstreamer from the synaptic manager or you have download the  sources(tar ball) form here and then compile and install it .(follow the INSTALL document)
 
Gstreamer will be installed in  /usr/local/bin

You may also need the Glib so do the same for Glib source also , download the Glib from here and  compile and install it.

Also before compiling the Gstreamer export the path : 
 
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
 
pkg-config is computer software that provides a unified interface for querying installed libraries for the purpose of compiling software from its source code. pkg-config was originally designed for Linux but is now also available for the various BSDs, Microsoft Windows, Mac OS X, and Solaris (defintion from the wikipedia)
 
When a library is installed (automatically through the use of an RPM, deb, or other binary packaging system or by compiling from the source), a .pc file should be included and placed into a directory with other .pc files (the exact directory is dependent upon your system and outlined in the pkg-config man page). This file has several entries.
 
Here is an example .pc file for libpng:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include
 
Name: libpng
Description: Loads and saves PNG files
Version: 1.2.8
Libs: -L${libdir} -lpng12 -lz
Cflags: -I${includedir}/libpng12
This file demonstrates how libpng informs that its libraries can be found in /usr/local/lib and its headers in /usr/local/include, that the library name is libpng, and that the version is 1.2.8. It also gives the additional linker flags that are needed to compile code that uses this library.
 
Here is an example of usage of pkg-config while compiling:
gcc -o test test.c $(pkg-config --libs --cflags libpng)
 
 
 
 
 
gcc -Wall helloworld.c -o helloworld $(pkg-config --cflags --libs gstreamer-0.10)
 

 
 To be continued....