Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .astyleignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
BUILD
CI
system
9 changes: 9 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ writeGEO KEYWORD2
readGEO KEYWORD2
writeEMail KEYWORD2
readEMail KEYWORD2
writeWifi KEYWORD2
readWifi KEYWORD2
writeVcard KEYWORD2
readVcard KEYWORD2
appendAAR KEYWORD2
appendBluetoothOOB KEYWORD2
writeMyApp KEYWORD2
writeText KEYWORD2
readText KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino ST25DV
version=2.1.2
version=2.2.0
author=STMicroelectronics
maintainer=stm32duino
sentence=Allows controlling the NFC ST25DV
Expand Down
106 changes: 106 additions & 0 deletions src/ST25DVSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,38 @@ int ST25DV::begin(uint8_t *buffer, uint16_t bufferLength)
return NFCTAG_OK;
};

int ST25DV::writeText(String text, String iso_lang, NDEF_Text_encoding_t encoding)
{
NDEF_Text_info_t text_info;


strcpy(text_info.text, text.c_str());
strcpy(text_info.language_code, iso_lang.c_str());
text_info.encoding = encoding;

return ndef.NDEF_WriteText(&text_info);
}

int ST25DV::readText(String *text)
{
uint16_t ret;
NDEF_Text_info_t info;
sRecordInfo_t recordInfo;

ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
if (ret) {
return ret;
}

ret = ndef.NDEF_ReadText(&recordInfo, &info);
if (ret) {
return ret;
}
*text = String(info.text);

return 0;
}

int ST25DV::writeURI(String protocol, String uri, String info)
{
sURI_Info _URI;
Expand Down Expand Up @@ -273,6 +305,80 @@ int ST25DV::readEMail(String *emailAdd, String *subject, String *message)
return NDEF_OK;
}

/**
* @brief Writes a WIFI record
*
* @param SSID
* @param auth: authentication type
* @param enc: Encryption type
* @param key
* @retval success or failure
*/
int ST25DV::writeWifi(String SSID, Ndef_Wifi_Authentication_t auth, Ndef_Wifi_Encryption_t enc, String key)
{
sWifiTokenInfo _wifi;

strncpy(_wifi.NetworkSSID, SSID.c_str(), 32);
strncpy(_wifi.NetworkKey, key.c_str(), 32);

_wifi.AuthenticationType = auth;
_wifi.EncryptionType = enc;

return ndef.NDEF_WriteWifiToken(&_wifi);
}

int ST25DV::readWifi(sWifiTokenInfo *wifitoken)
{
uint16_t ret;
sRecordInfo_t recordInfo;

ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
if (ret) {
return ret;
}

return ndef.NDEF_ReadWifiToken(&recordInfo, wifitoken);

}

int ST25DV::writeVcard(sVcardInfo vcard)
{

return ndef.NDEF_WriteVcard(&vcard);
}

int ST25DV::readVcard(sVcardInfo *vcard)
{
uint16_t ret;
sRecordInfo_t recordInfo;

ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
if (ret) {
return ret;
}

return ndef.NDEF_ReadVcard(&recordInfo, vcard);

}

int ST25DV::appendAAR(String pkgName)
{
sAARInfo _info;
strncpy(_info.PackageName, pkgName.c_str(), 80);

return ndef.NDEF_AddAAR(&_info);
}

int ST25DV::appendBluetoothOOB(Ndef_Bluetooth_OOB_t bluetooth, char *recordId)
{
return ndef.NDEF_AppendBluetoothOOB(&bluetooth, recordId);
}

int ST25DV::writeMyApp(sMyAppInfo *pMyAppStruct)
{
return ndef.NDEF_WriteMyApp(pMyAppStruct);
}

/**
* @brief reads the type of NDEF on the tag
* @param None
Expand Down
9 changes: 9 additions & 0 deletions src/ST25DVSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ST25DV {
int begin(uint8_t *buffer, uint16_t bufferLength);
int writeURI(String protocol, String uri, String info);
int readURI(String *s);
int writeText(String text, String iso_lang, NDEF_Text_encoding_t encoding);
int readText(String *text);
int writeUnabridgedURI(String uri, String info);
int readUnabridgedURI(String *s);
int writeSMS(String phoneNumber, String message, String info);
Expand All @@ -46,6 +48,13 @@ class ST25DV {
int readGEO(String *latitude, String *longitude);
int writeEMail(String emailAdd, String subject, String message, String info);
int readEMail(String *emailAdd, String *subject, String *message);
int writeWifi(String SSID, Ndef_Wifi_Authentication_t auth, Ndef_Wifi_Encryption_t enc, String key);
int readWifi(sWifiTokenInfo *wifitoken);
int writeVcard(sVcardInfo vcard);
int readVcard(sVcardInfo *vcard);
int appendAAR(String pkgName);
int appendBluetoothOOB(Ndef_Bluetooth_OOB_t bluetooth, char *recordId);
int writeMyApp(sMyAppInfo *pMyAppStruct);
NDEF_TypeDef readNDEFType();
NDEF *getNDEF();

Expand Down
6 changes: 3 additions & 3 deletions src/libNDEF/NDEF_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class NDEF {
void NDEF_PrepareSMSMessage(sSMSInfo *pSMSStruct, uint8_t *pNDEFMessage, uint16_t *size);

//lib_NDEF_Text
uint16_t NDEF_WriteText(char *text);
uint16_t NDEF_WriteText(NDEF_Text_info_t *text_info);
uint16_t NDEF_ReadText(sRecordInfo_t *pRecordStruct, NDEF_Text_info_t *pText);

//lib_NDEF_URI
Expand All @@ -131,7 +131,7 @@ class NDEF {
int NDEF_getVcardPicture(uint8_t *pPayload, uint32_t PayloadSize, uint8_t *pPict);

//lib_NDEF_Wifi
uint16_t NDEF_ReadWifiToken(struct sRecordInfo *pRecordStruct, sWifiTokenInfo *pWifiTokenStruct);
uint16_t NDEF_ReadWifiToken(sRecordInfo *pRecordStruct, sWifiTokenInfo *pWifiTokenStruct);
uint16_t NDEF_WriteWifiToken(sWifiTokenInfo *pWifiTokenStruct);

//lib_wrapper
Expand Down Expand Up @@ -180,7 +180,7 @@ class NDEF {


//Vcard static
void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString);
void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, const char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString);
void NDEF_ExtractVcard(sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct);

//Wifi static
Expand Down
30 changes: 30 additions & 0 deletions src/libNDEF/default_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#ifndef _DEFAULT_CONFIG_H_
#define _DEFAULT_CONFIG_H_


#define NDEF_MAX_SIZE (512)
#define NDEF_RECORD_MAX_SIZE (100)

#define URI_PROTOCOL_MAX_SIZE (20)
#define URI_MESSAGE_MAX_SIZE (100)
#define URI_INFO_MAX_SIZE (20)


#define TEXT_MAX_SIZE (100)
#define TEXT_LANGUAGE_CODE_MAX_SIZE (10)

#define SMS_PHONE_MAX_SIZE (16)
#define SMS_MESSAGE_MAX_SIZE (400)
#define SMS_INFO_MAX_SIZE (400)

#define GEO_LATITUDE_MAX_SIZE (20)
#define GEO_LONGITUDE_MAX_SIZE (20)
#define GEO_INFO_MAX_SIZE (100)

#define EMAIL_ADDRESS_MAX_SIZE (64)
#define EMAIL_SUBJECT_MAX_SIZE (100)
#define EMAIL_MESSAGE_MAX_SIZE (2000)
#define EMAIL_INFO_MAX_SIZE (400)

#endif
12 changes: 7 additions & 5 deletions src/libNDEF/lib_NDEF.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
{goto Error;} else
#endif

#if __has_include("custom_config.h")
#include "custom_config.h"
#else
#include "default_config.h"
#endif


/* Error codes for Higher level */
#define NDEF_OK RESULTOK
#define NDEF_ERROR ERRORCODE_GENERIC
Expand All @@ -51,11 +58,6 @@
#define NDEF_ERROR_LOCKED 4
#define NDEF_ERROR_NOT_FORMATED 5

//#define NDEF_MAX_SIZE NFC_DEVICE_MAX_NDEFMEMORY
//#define NDEF_RECORD_MAX_SIZE (512)
#define NDEF_MAX_SIZE (100)
#define NDEF_RECORD_MAX_SIZE (100)

#define NDEF_SIZE_OFFSET 0
#define FIRST_RECORD_OFFSET 0

Expand Down
6 changes: 3 additions & 3 deletions src/libNDEF/lib_NDEF_Geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#include "lib_NDEF.h"

typedef struct {
char Latitude[20];
char Longitude[20];
char Information[100];
char Latitude[GEO_LATITUDE_MAX_SIZE];
char Longitude[GEO_LONGITUDE_MAX_SIZE];
char Information[GEO_INFO_MAX_SIZE];
} sGeoInfo;

#endif /* __LIB_NDEF_GEO_H */
Expand Down
6 changes: 3 additions & 3 deletions src/libNDEF/lib_NDEF_SMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@


typedef struct {
char PhoneNumber[16];
char Message[400];
char Information[400];
char PhoneNumber[SMS_PHONE_MAX_SIZE];
char Message[SMS_MESSAGE_MAX_SIZE];
char Information[SMS_INFO_MAX_SIZE];
} sSMSInfo;

#endif /* __LIB_NDEF_SMS_H */
Expand Down
26 changes: 15 additions & 11 deletions src/libNDEF/lib_NDEF_Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,28 @@

/**
* @brief This function write the text in the TAG.
* @param text : text to write.
* @param text_info: text_info struct containing text, lang and encoding
* @retval NDEF_OK : NDEF file data written in the tag.
* @retval NDEF_ERROR : not able to store NDEF in tag.
* @retval NDEF_ERROR_MEMORY_INTERNAL : Cannot write to tag.
* @retval NDEF_ERROR_NOT_FORMATED : CCFile data not supported or not present.
* @retval NDEF_ERROR_MEMORY_TAG : Size not compatible with memory.
* @retval NDEF_ERROR_LOCKED : Tag locked, cannot be write.
*/
uint16_t NDEF::NDEF_WriteText(char *text)
uint16_t NDEF::NDEF_WriteText(NDEF_Text_info_t *text_info)
{
uint16_t status = NDEF_ERROR;
uint32_t textSize, Offset = 0;

if (strlen(text_info->language_code) > 10) {
return status;
}

/* TEXT : 1+en+message */
textSize = 3 + strlen(text);
textSize = 1 + strlen(text_info->language_code) + strlen(text_info->text);

/* TEXT header */
NDEF_Buffer[Offset] = 0xD1;
NDEF_Buffer[Offset] = 0xC1;
if (textSize < 256) {
NDEF_Buffer[Offset] |= 0x10; // Set the SR bit
}
Expand All @@ -97,12 +100,13 @@ uint16_t NDEF::NDEF_WriteText(char *text)
Offset += TEXT_TYPE_STRING_LENGTH;

/* TEXT payload */
NDEF_Buffer[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH;
memcpy(&NDEF_Buffer[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH);
Offset += ISO_ENGLISH_CODE_STRING_LENGTH;
NDEF_Buffer[Offset++] = strlen(text_info->language_code) | text_info->encoding << 7;

memcpy(&NDEF_Buffer[Offset], text_info->language_code, strlen(text_info->language_code));
Offset += strlen(text_info->language_code);

memcpy(&NDEF_Buffer[Offset], text, strlen(text));
Offset += strlen(text);
memcpy(&NDEF_Buffer[Offset], text_info->text, strlen(text_info->text));
Offset += strlen(text_info->text);

status = NfcTag_WriteNDEF(Offset, NDEF_Buffer);

Expand Down Expand Up @@ -130,8 +134,8 @@ uint16_t NDEF::NDEF_ReadText(sRecordInfo_t *pRecordStruct, NDEF_Text_info_t *pTe
- text_record_info->language_length /* minus language code length */
- sizeof(uint8_t); /* minus the status byte length */

if ((text_record_info->language_length >= NDEF_TEXT_LANGUAGE_CODE_MAX_LENGTH) ||
(text_length >= NDEF_TEXT_MAX_LENGTH)) {
if ((text_record_info->language_length >= TEXT_LANGUAGE_CODE_MAX_SIZE) ||
(text_length >= TEXT_MAX_SIZE)) {
/* One of the text info structure buffer is too small */
return NDEF_ERROR_MEMORY_INTERNAL;
}
Expand Down
9 changes: 2 additions & 7 deletions src/libNDEF/lib_NDEF_Text.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
/* Includes ------------------------------------------------------------------*/
#include "lib_NDEF.h"

/** @brief NDEF Text buffer length. */
#define NDEF_TEXT_MAX_LENGTH 40
/** @brief NDEF Language code buffer length. */
#define NDEF_TEXT_LANGUAGE_CODE_MAX_LENGTH 10

/** @brief NDEF Text encoding possible values. */
typedef enum {
NDEF_TEXT_UTF8 = 0,
Expand All @@ -48,8 +43,8 @@ typedef enum {
/** @brief This structure is used to handle information from a NDEF Text record. */
typedef struct {
NDEF_Text_encoding_t encoding; /**< metadata: UTF-8 / UTF-16. */
char language_code[NDEF_TEXT_LANGUAGE_CODE_MAX_LENGTH]; /**< metadata: Language code as specified by IANA. */
char text[NDEF_TEXT_MAX_LENGTH]; /**< The text itself. */
char language_code[TEXT_LANGUAGE_CODE_MAX_SIZE]; /**< metadata: Language code as specified by IANA. */
char text[TEXT_MAX_SIZE]; /**< The text itself. */
} NDEF_Text_info_t;


Expand Down
6 changes: 3 additions & 3 deletions src/libNDEF/lib_NDEF_URI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ typedef struct {
// char protocol[80];
// char URI_Message[400];
// char Information[400];
char protocol[20];
char URI_Message[100];
char Information[20];
char protocol[URI_PROTOCOL_MAX_SIZE];
char URI_Message[URI_MESSAGE_MAX_SIZE];
char Information[URI_INFO_MAX_SIZE];
} sURI_Info;

#endif /* __LIB_NDEF_URI_H */
Expand Down
4 changes: 2 additions & 2 deletions src/libNDEF/lib_NDEF_Vcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @param SizeOfKeyWord Number of bytes of the vCard property keyword we are looking for.
* @param pString Pointer on a string used to return the vCard property read.
*/
void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, const char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString)
void NDEF::NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, const char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString)
{
uint8_t *pLastByteAdd, *pLook4Word, *pEndString;

Expand Down Expand Up @@ -90,7 +90,7 @@ void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, const char *p
* @param pRecordStruct Pointer on the vCard record structure.
* @param pVcardStruct Pointer on the `sCardInfo` structure to fill.
*/
void NDEF_ExtractVcard(sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct)
void NDEF::NDEF_ExtractVcard(sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct)
{
uint32_t PayloadSize;
uint8_t *pPayload;
Expand Down
Loading