Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #60 from DimiL/bug_1061512
Browse files Browse the repository at this point in the history
Bug 1061512 - [NFC] nfcd should notify gecko about NDEF information. r=allstars.chh
  • Loading branch information
allstarschh committed Sep 23, 2014
2 parents 6265fad + de46c74 commit 2a5dc67
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 125 deletions.
65 changes: 27 additions & 38 deletions src/MessageHandler.cpp
Expand Up @@ -25,7 +25,7 @@
#include "NfcDebug.h"

#define MAJOR_VERSION (1)
#define MINOR_VERSION (8)
#define MINOR_VERSION (9)

using android::Parcel;

Expand All @@ -47,6 +47,7 @@ void MessageHandler::notifyTechDiscovered(Parcel& parcel, void* data)
memcpy(dest, event->techList, event->techCount);
parcel.writeInt32(event->ndefMsgCount);
sendNdefMsg(parcel, event->ndefMsg);
sendNdefInfo(parcel, event->ndefInfo);
sendResponse(parcel);
}

Expand Down Expand Up @@ -94,9 +95,6 @@ void MessageHandler::processRequest(const uint8_t* data, size_t dataLen)
case NFC_REQUEST_CONFIG:
handleConfigRequest(parcel);
break;
case NFC_REQUEST_GET_DETAILS:
handleReadNdefDetailRequest(parcel);
break;
case NFC_REQUEST_READ_NDEF:
handleReadNdefRequest(parcel);
break;
Expand Down Expand Up @@ -130,9 +128,6 @@ void MessageHandler::processResponse(NfcResponseType response, NfcErrorCode erro
case NFC_RESPONSE_CONFIG:
handleConfigResponse(parcel, data);
break;
case NFC_RESPONSE_READ_NDEF_DETAILS:
handleReadNdefDetailResponse(parcel, data);
break;
case NFC_RESPONSE_READ_NDEF:
handleReadNdefResponse(parcel, data);
break;
Expand Down Expand Up @@ -204,13 +199,6 @@ bool MessageHandler::handleConfigRequest(Parcel& parcel)

}

bool MessageHandler::handleReadNdefDetailRequest(Parcel& parcel)
{
int sessionId = parcel.readInt32();
//TODO check SessionId
return mService->handleReadNdefDetailRequest();
}

bool MessageHandler::handleReadNdefRequest(Parcel& parcel)
{
int sessionId = parcel.readInt32();
Expand Down Expand Up @@ -294,30 +282,6 @@ bool MessageHandler::handleConfigResponse(Parcel& parcel, void* data)
return true;
}

bool MessageHandler::handleReadNdefDetailResponse(Parcel& parcel, void* data)
{
NdefDetail* ndefDetail = reinterpret_cast<NdefDetail*>(data);

parcel.writeInt32(SessionId::getCurrentId());

if (!ndefDetail) {
sendResponse(parcel);
return true;
}

bool isReadOnly = ndefDetail->isReadOnly;
bool canBeMadeReadOnly = ndefDetail->canBeMadeReadOnly;

bool params[] = {isReadOnly, canBeMadeReadOnly};
void* dest = parcel.writeInplace(sizeof(params));
memcpy(dest, params, sizeof(params));

parcel.writeInt32(ndefDetail->maxSupportedLength);

sendResponse(parcel);
return true;
}

bool MessageHandler::handleReadNdefResponse(Parcel& parcel, void* data)
{
NdefMessage* ndef = reinterpret_cast<NdefMessage*>(data);
Expand Down Expand Up @@ -380,3 +344,28 @@ bool MessageHandler::sendNdefMsg(Parcel& parcel, NdefMessage* ndef)

return true;
}

bool MessageHandler::sendNdefInfo(Parcel& parcel, NdefInfo* info)
{
// if contain ndef information
parcel.writeInt32(info ? true : false);

if (!info) {
return false;
}

// ndef tyoe
NfcNdefType type = (NfcUtil::convertNdefType(info->ndefType));
parcel.writeInt32(static_cast<int>(type));

// max support length
parcel.writeInt32(info->maxSupportedLength);

// is ready only
parcel.writeInt32(info->isReadOnly);

// ndef formatable
parcel.writeInt32(info->isFormatable);

return true;
}
5 changes: 3 additions & 2 deletions src/MessageHandler.h
Expand Up @@ -25,6 +25,7 @@
class NfcIpcSocket;
class NfcService;
class NdefMessage;
class NdefInfo;

class MessageHandler {
public:
Expand All @@ -42,21 +43,20 @@ class MessageHandler {
void notifyTransactionEvent(android::Parcel& parcel, void* data);

bool handleConfigRequest(android::Parcel& parcel);
bool handleReadNdefDetailRequest(android::Parcel& parcel);
bool handleReadNdefRequest(android::Parcel& parcel);
bool handleWriteNdefRequest(android::Parcel& parcel);
bool handleConnectRequest(android::Parcel& parcel);
bool handleCloseRequest(android::Parcel& parcel);
bool handleMakeNdefReadonlyRequest(android::Parcel& parcel);

bool handleConfigResponse(android::Parcel& parcel, void* data);
bool handleReadNdefDetailResponse(android::Parcel& parcel, void* data);
bool handleReadNdefResponse(android::Parcel& parcel, void* data);
bool handleResponse(android::Parcel& parcel);

void sendResponse(android::Parcel& parcel);

bool sendNdefMsg(android::Parcel& parcel, NdefMessage* ndef);
bool sendNdefInfo(android::Parcel& parcel, NdefInfo* info);

NfcIpcSocket* mSocket;
NfcService* mService;
Expand All @@ -68,6 +68,7 @@ struct TechDiscoveredEvent {
void* techList;
uint32_t ndefMsgCount;
NdefMessage* ndefMsg;
NdefInfo* ndefInfo;
};

#endif // mozilla_nfcd_MessageHandler_h
12 changes: 12 additions & 0 deletions src/NfcGonkMessage.h
Expand Up @@ -135,6 +135,18 @@ typedef enum {
NFC_TECH_BARCODE = 11
} NfcTechnology;

/**
* NDEF type
*/
typedef enum {
NFC_NDEF_UNKNOWN_TAG = -1,
NFC_NDEF_TYPE_1_TAG = 0,
NFC_NDEF_TYPE_2_TAG = 1,
NFC_NDEF_TYPE_3_TAG = 2,
NFC_NDEF_TYPE_4_TAG = 3,
NFC_NDEF_MIFARE_CLASSIC_TAG = 4,
} NfcNdefType;

/**
* NDEF Record
* @see NFCForum-TS-NDEF, clause 3.2
Expand Down
44 changes: 7 additions & 37 deletions src/NfcService.cpp
Expand Up @@ -41,7 +41,6 @@ typedef enum {
MSG_SE_FIELD_ACTIVATED,
MSG_SE_FIELD_DEACTIVATED,
MSG_SE_NOTIFY_TRANSACTION_EVENT,
MSG_READ_NDEF_DETAIL,
MSG_READ_NDEF,
MSG_WRITE_NDEF,
MSG_CLOSE,
Expand Down Expand Up @@ -244,6 +243,7 @@ void NfcService::handleLlcpLinkActivation(NfcEvent* event)
data->techList = &techs;
data->ndefMsgCount = 0;
data->ndefMsg = NULL;
data->ndefInfo = NULL;
mMsgHandler->processNotification(NFC_NOTIFICATION_TECH_DISCOVERED, data);
delete data;
ALOGD("%s: exit", FUNC);
Expand Down Expand Up @@ -272,12 +272,12 @@ static void *pollingThreadFunc(void *arg)

void NfcService::handleTagDiscovered(NfcEvent* event)
{
void* pTag = event->obj;
INfcTag* pINfcTag = reinterpret_cast<INfcTag*>(pTag);
INfcTag* pINfcTag = reinterpret_cast<INfcTag*>(event->obj);

// To get complete tag information, need to call read ndef first.
// In readNdef function, it will add NDEF related info in NfcTagManager.
NdefMessage* pNdefMessage = pINfcTag->readNdef();
std::auto_ptr<NdefMessage> pNdefMessage(pINfcTag->readNdef());
std::auto_ptr<NdefInfo> pNdefInfo(pINfcTag->readNdefInfo());

// Do the following after read ndef.
std::vector<TagTechnology>& techList = pINfcTag->getTechList();
Expand All @@ -292,8 +292,9 @@ void NfcService::handleTagDiscovered(NfcEvent* event)
data->sessionId = SessionId::generateNewId();
data->techCount = techCount;
data->techList = gonkTechList;
data->ndefMsgCount = pNdefMessage ? 1 : 0;
data->ndefMsg = pNdefMessage;
data->ndefMsgCount = pNdefMessage.get() ? 1 : 0;
data->ndefMsg = pNdefMessage.get();
data->ndefInfo = pNdefInfo.get();
mMsgHandler->processNotification(NFC_NOTIFICATION_TECH_DISCOVERED, data);

PollingThreadParam* param = new PollingThreadParam();
Expand Down Expand Up @@ -351,9 +352,6 @@ void* NfcService::eventLoop()
case MSG_CONFIG:
handleConfigResponse(event);
break;
case MSG_READ_NDEF_DETAIL:
handleReadNdefDetailResponse(event);
break;
case MSG_READ_NDEF:
handleReadNdefResponse(event);
break;
Expand Down Expand Up @@ -431,39 +429,11 @@ bool NfcService::handleConfigRequest(int powerLevel)
return true;
}

bool NfcService::handleReadNdefDetailRequest()
{
NfcEvent *event = new NfcEvent(MSG_READ_NDEF_DETAIL);
mQueue.push_back(event);
sem_post(&thread_sem);
return true;
}

void NfcService::handleConfigResponse(NfcEvent* event)
{
mMsgHandler->processResponse(NFC_RESPONSE_CONFIG, NFC_SUCCESS, NULL);
}

void NfcService::handleReadNdefDetailResponse(NfcEvent* event)
{
NfcResponseType resType = NFC_RESPONSE_READ_NDEF_DETAILS;

INfcTag* pINfcTag = reinterpret_cast<INfcTag*>
(sNfcManager->queryInterface(INTERFACE_TAG_MANAGER));
if (!pINfcTag) {
mMsgHandler->processResponse(resType, NFC_ERROR_NOT_SUPPORTED, NULL);
return;
}

std::auto_ptr<NdefDetail> pNdefDetail(pINfcTag->readNdefDetail());
if (!pNdefDetail.get()) {
mMsgHandler->processResponse(resType, NFC_ERROR_READ, NULL);
return;
}

mMsgHandler->processResponse(resType, NFC_SUCCESS, pNdefDetail.get());
}

bool NfcService::handleReadNdefRequest()
{
NfcEvent *event = new NfcEvent(MSG_READ_NDEF);
Expand Down
2 changes: 0 additions & 2 deletions src/NfcService.h
Expand Up @@ -58,8 +58,6 @@ class NfcService : public IpcSocketListener {
void handleConnect(int technology);
bool handleConfigRequest(int powerLevel);
void handleConfigResponse(NfcEvent* event);
bool handleReadNdefDetailRequest();
void handleReadNdefDetailResponse(NfcEvent* event);
bool handleReadNdefRequest();
void handleReadNdefResponse(NfcEvent* event);
bool handleWriteNdefRequest(NdefMessage* ndef);
Expand Down
12 changes: 12 additions & 0 deletions src/NfcUtil.cpp
Expand Up @@ -59,3 +59,15 @@ NfcEvtTransactionOrigin NfcUtil::convertOriginType(TransactionEvent::OriginType
return NFC_EVT_TRANSACTION_SIM;
}
}

NfcNdefType NfcUtil::convertNdefType(NdefType type)
{
switch(type) {
case NDEF_TYPE1_TAG: return NFC_NDEF_TYPE_1_TAG;
case NDEF_TYPE2_TAG: return NFC_NDEF_TYPE_2_TAG;
case NDEF_TYPE3_TAG: return NFC_NDEF_TYPE_3_TAG;
case NDEF_TYPE4_TAG: return NFC_NDEF_TYPE_4_TAG;
case NDEF_MIFARE_CLASSIC_TAG: return NFC_NDEF_MIFARE_CLASSIC_TAG;
default: return NFC_NDEF_UNKNOWN_TAG;
}
}
2 changes: 1 addition & 1 deletion src/NfcUtil.h
Expand Up @@ -29,7 +29,7 @@ class NfcUtil{
static void convertNdefPduToNdefMessage(NdefMessagePdu& ndefPdu, NdefMessage* ndefMessage);
static NfcTechnology convertTagTechToGonkFormat(TagTechnology tagTech);
static NfcEvtTransactionOrigin convertOriginType(TransactionEvent::OriginType type);

static NfcNdefType convertNdefType(NdefType type);
private:
NfcUtil();
};
Expand Down
8 changes: 4 additions & 4 deletions src/interface/INfcTag.h
Expand Up @@ -23,7 +23,7 @@
#define INTERFACE_TAG_MANAGER "NfcTagManager"

class NdefMessage;
class NdefDetail;
class NdefInfo;

class INfcTag {
public:
Expand Down Expand Up @@ -59,11 +59,11 @@ class INfcTag {
virtual NdefMessage* readNdef() = 0;

/**
* Read tag information and fill the NdefDetail structure.
* Read tag information and fill the NdefInfo structure.
*
* @return NDEF detail structure.
* @return NDEF Info structure.
*/
virtual NdefDetail* readNdefDetail() = 0;
virtual NdefInfo* readNdefInfo() = 0;

/**
* Write a NDEF message to the tag.
Expand Down
8 changes: 5 additions & 3 deletions src/interface/NdefMessage.h
Expand Up @@ -18,6 +18,7 @@
#define mozilla_nfcd_NdefMessage_h

#include "NdefRecord.h"
#include "TagTechnology.h"
#include <vector>

class NdefMessage{
Expand Down Expand Up @@ -56,13 +57,14 @@ class NdefMessage{
};

/**
* NdefDetail structure contains the information should be returned by readNdefDetail of INfcTag.
* NdefInfo structure contains the information returned by readNdefInfo of INfcTag.
*/
class NdefDetail {
class NdefInfo {
public:
NdefType ndefType;
int maxSupportedLength;
bool isReadOnly;
bool canBeMadeReadOnly;
bool isFormatable;
};

#endif
11 changes: 11 additions & 0 deletions src/interface/TagTechnology.h
Expand Up @@ -34,4 +34,15 @@ typedef enum {
UNKNOWN_TECH = 11
} TagTechnology;


// Pre-defined tag type values.
typedef enum {
NDEF_UNKNOWN_TYPE = -1,
NDEF_TYPE1_TAG = 1,
NDEF_TYPE2_TAG = 2,
NDEF_TYPE3_TAG = 3,
NDEF_TYPE4_TAG = 4,
NDEF_MIFARE_CLASSIC_TAG = 101
} NdefType;

#endif

0 comments on commit 2a5dc67

Please sign in to comment.