Thursday, July 11, 2013

Coding of Communication Settings & Access Rights in Mifare DESFire


  • Coding of Communication Settings

Settingan komunikasi mendefinisikan level security yang digunakan antara PCD dan PICC. Settingan komunikasi ini selalu berhubungan dengan level file.
Setting komunikasi ini hanya satu byte dalam setiap file applikasi, konfigurasinya seperti terlihat di bawah :


Pada tabel tersebut terlihat bahwa jika ingin menggunakan DES/3DES maka settingannya adalah 0x03 dalam bilangan hex.
Key yang digunakan untuk DES dan 3DES tersebut terdiri dari 16 byte. Jika 8 byte pertama dari key tersebut sama dengan 8 byte berikutnya {byte 9 - 16}, maka PICC akan menggunakan DES. Namun jika tidak sama maka akan digunakan 3DES. Contohnya :
          key1{byte 1-8}= 0x0011223344556677
          key2{byte 9-16}=0x0011223344556677
brarti pada kasus ini PICC secara otomatis akan menggunakan DES. Tetapi jika
         key1 = 0x9988776655332211
         key2 = 0x1122334455667799
maka PICC akan menggunakan TDES. Hehe.. simple kn yh... :D


  • Coding of Access Rights
Ada empat hak akses {2 byte untuk setiap file, sprt trlht di bawah} yang tersimpan dalam setiap aplikasi di PICC, yaitu :
1. Read Access (GetValue, Debit for Value files)
2. Write Access (GetValue, Debit, LimitedCredit for Value files)
3. Read&Write Access (GetValue, Debit, LimitedCredit, Credit for Value files)
4. ChangeAccessRights


Setiap hak akses tersebut dikodekan dalam 4 bit atau satu nibble. Setiap nibble mewakili satu key yang tersimpan dalam masing-masing database key suatu applikasi. 
Satu nibble memungkinkan untuk menghasilkan 16 nilai yang berbeda. Oleh sebab itu settingan nilai-nilai tersebut mengikuti aturan berikut :
  1. Jika nilainya 0 - 13 {Maks. 14 keys}, maka nibble ini merepresentasikan jenis-jenis key yang ada dalam applikasi. Hal menunjukkan bahwa jika kita memilih key nomor 14 - 15 brarti PICC akan memberikan error respon
  2. Jika nibble tersebut bernilai 14 (0xE). Ini berarti "FREE ACCESS". Jadi PCD dapat mengirimkan command-command tertentu tanpa harus didahului oleh proses authentikasi
  3. Jika bernilai 15(0xF). Ini adalah kebalikan dari 14, jadi "DENY ACCESS". Maka PCD tidak dapat melakukan apa-apa terhadap applikasi yang berada pada PICC
Nah jika suatu file mempunyai konfigurasi :
0x12 0x3E
maka untuk melakuan Read file, PCD dapat menggunakan key ke-1 atau key ke-3. Trz untuk Write file, PCD dapat menggunakan key ke-2 dan key ke-3.

Kemudian jika konfigurasi filenya adalah 0x45 0xEE. Maka PCD untuk melakukan Read atau Write boleh tidak menggunakan key apapun juga karena konfigurasi Read&Write-nya di set ke 0xE, "free access". Tetapi dapat pula menggunakan key no. 4 untuk read dan key no. 5 untuk write.


Sunday, June 2, 2013

Bitmaps Intro

A bitmap is a series of points (bits) arranged like a map so that, when put together, they produce a picture that can be written to, copied from, re-arranged, changed, manipulated, or stored as a computer file. Bitmaps are used to display pictures on graphical applications, word processors, database files, or audience presentations. To display its product on a device such as a monitor or a printer, a bitmap holds some properties and follows a set of rules.

There are various types of bitmap, based on the number of colors that the bitmap can display. First of all, a bitmap can monochrome in which case each pixel corresponds to 1 bit. A bit can also be colored. The number of colors that a bitmap can display is equal to 2 raised to the number of pits/pixel. For example, a simple bitmap uses only 4 pits/pixel or 4 bpp can handle only 2^4 = 16 colors. A more enhanced bitmap that requires 8 bpp can handle 2^8 = 256 colors. Bitmap are divided in two categories that control their availability to display on a device, namely :

1)    A device-independent bitmap (DIB) is a bitmap that is designed to be loaded on any application or display on any device and produce the same visual effect. To make this possible, such a bitmap contains a table of colors that describes how the colors of the bitmap should be used on pixels when displaying it. The characteristics of a DIB are defined by the BITMAPINFO structure.

2)    A device-dependent bitmap(DDB) is a bitmap created from the BITMAP structure the dimension of the bitmap.

Unlike the other GDI tools, creating a bitmap usually involves more steps. For example, we may want to create a bitmap to display on a window. We may create another bitmap to paint a geometric area, in which case the bitmap would be used as a brush.
Before creating a bitmap as a GDI object, we should first have a bitmap. We can do this by defining an array of unsigned hexadecimal numbers. Such a bitmap can be used for a brush.
To create and manipulate bitmaps, the MFC library provides the CBitmap class. The use of this class depends on the type of bitmap we want to create and how we want to use that bitmap. One way we can use a bitmap is to display a picture on a window. To do this, we must first have a picture resource. Although the Image Editor built -in Microsoft Visual C++ is meant to help with regular application resources, it has a problem handling a bitmap that displays more than 16 colors. The remedy used is to import the bitmap we want to use. Once our bitmap is ready, call the CBitmap::LoadBitmap() method. Its syntaxes :

       BOOL LoadBitmap(UINT nIDResource);
       BOOL LoadBitmap(LPCTSTR lpszResourceName);

The first version takes, as argument, the identifier of the bitmap we want to use. If the bitmap is recognized by its name, we can use the second version of this method and provide the lpszResourceName argument.
Before selecting the newly created bitmap object, allocate a block of computer memory that would hold the bitmap and can then copy it to the actual device. This job can be taken care of by the CDC::CreateCompatibleDC() method. Its syntax is :

      virtual BOOL CreateCompatibleDC(CDC *pDC);

This method takes a pointer to a device context. If it is successful, it returns TRUE or a non-zero value. If it is not, it returns FALSE or 0.

Practical Learning :
1. Start a new project and name it Bitmap1
2. Create is as a Single Document application based on CView
3. In the class View, expand everything and access the CMainFrame::PreCreateWindow() method
4. Change its code as follows:
      BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
      {
         if( !CFrameWnd::PreCreateWindow(cs)) return FALSE;
     
         //The new width of the window's frame
        cs.cx = 480;
     
        //The new height of the window's frame
       cs.cy = 490;

       //Remove the untitled thing
      cs.style & = ~FWS_ADDTOTITLE;
      return TRUE;
      }

5. In the Resource view, display the string table and change the IDR_MAINFRAME caption to Poipo on Phone\n\nBitmap\n\nBitmap1.Document\nBitmap Document

6. Right-click any folder and click import...
7. In the import Resource dialog box, change the Files of Type to All files and, in the Look In Combo Box, change the folder to the one that holds the accompanying exercise for this example.
8. select the bitmap
9. Click import. After the bitmap has been imported, we may receive a message box. Then just click OK
10. Right-click the new IDB_BITMAP1 resource and click Properties
11. Change its ID to whatever name we want
12. Add a message handler of the WM_PAINT message for the CBitmap1 View class and implement it as follows :

 void CBitmap1View::OnPaint()
 {
      CPaintDC dc(this); //device context for painting
   
      //TODO: Add your message handler code here
      CBitmap BmpPoipo;
      CDC MemDCPoipo;

     //Load the bitmap from the resource
     BmpPoipo.LoadBitmap(IDB_POIPO);
     //Create a memory device compatible with the above CPaintDC variable
     MemDCPoipo.CreateCompatibleDC(&dc);
     //Select the new bitmap
     CBitmap *BmpPrevious = MemDCPoipo.SelectObject(&BmpPoipo);

     //Copy the bits from the memory DC into the current dc
     dc.BitBlt(20,10,436,364,&MemDCPoipo,0,0,SRCCOPY);

     //Restore the old bitmap
     dc.SelectObject(BmpPrevious);

    //Note : Do not call CView::OnPaint() for painting messages
 }

13. Run the applications... :D