PN532 NFC shield of Adafruit based on PN532 of Seeed.

Fork of PN532 by Seeed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers llcp.h Source File

llcp.h

00001 
00002 #ifndef __LLCP_H__
00003 #define __LLCP_H__
00004 
00005 #include "mac_link.h"
00006 
00007 #define LLCP_DEFAULT_TIMEOUT  20000
00008 #define LLCP_DEFAULT_DSAP     0x04
00009 #define LLCP_DEFAULT_SSAP     0x20
00010 
00011 /**
00012  * The LLCP class
00013  */
00014 class LLCP {
00015 public:
00016     LLCP(PN532Interface &interface) : link(interface) {
00017         headerBuf = link.getHeaderBuffer(&headerBufLen);
00018         ns = 0;
00019         nr = 0;
00020     };
00021 
00022     /**
00023      * @brief    Actiave PN532 as a target
00024      * @param    timeout max time to wait, 0 means no timeout
00025      * @return   > 0     success
00026      *           = 0     timeout
00027      *           < 0     failed
00028      */
00029     int8_t activate(uint16_t timeout = 0);
00030 
00031     int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00032 
00033     int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00034 
00035     int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00036 
00037     int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00038 
00039     /**
00040      * @brief    write a packet, the packet should be less than (255 - 2) bytes
00041      * @param    header  packet header
00042      * @param    hlen    length of header
00043      * @param    body    packet body
00044      * @param    blen    length of body
00045      * @return   true    success
00046      *           false   failed
00047      */
00048     bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0);
00049 
00050     /**
00051      * @brief    read a  packet, the packet will be less than (255 - 2) bytes
00052      * @param    buf     the buffer to contain the packet
00053      * @param    len     lenght of the buffer
00054      * @return   >=0     length of the packet 
00055      *           <0      failed
00056      */
00057     int16_t read(uint8_t *buf, uint8_t len);
00058 
00059     uint8_t *getHeaderBuffer(uint8_t *len) {
00060         uint8_t *buf = link.getHeaderBuffer(len);
00061         len -= 3;       // I PDU header has 3 bytes
00062         return buf;
00063     };
00064 
00065 private:
00066     MACLink link;
00067     uint8_t ssap;
00068     uint8_t dsap;
00069     uint8_t *headerBuf;
00070     uint8_t headerBufLen;
00071     uint8_t ns;         // Number of I PDU Sent
00072     uint8_t nr;         // Number of I PDU Received
00073 
00074     static uint8_t SYMM_PDU[2];
00075 };
00076 
00077 #endif // __LLCP_H__