Martyn Gilbertson / M24SR
Revision:
4:11526ba25edb
Parent:
3:5ebf4b2c51a1
--- a/M24SR.cpp	Thu Aug 29 12:38:46 2019 +0100
+++ b/M24SR.cpp	Thu Feb 13 13:42:16 2020 +0000
@@ -95,7 +95,7 @@
 #define M24SR_DEFAULT_FREQUENCY (uint32_t)500000
 
 
-M24SR::M24SR(PinName sda, PinName scl, uint8_t address, uint8_t *pass) : _i2c(sda,scl), _addr(address),
+M24SR::M24SR(PinName sda, PinName scl, uint8_t address, const uint8_t *pass) : _i2c(sda,scl), _addr(address),
 		_session_open(false), _ndef_size(0), _ndef_hdr_size(0), _write_bytes(0)
 {
 	frequency(M24SR_DEFAULT_FREQUENCY);
@@ -109,7 +109,7 @@
 }
 
 
-void M24SR::password(uint8_t *pass)
+void M24SR::password(const uint8_t *pass)
 {
 	memcpy(_password, pass, 16);
 }
@@ -715,7 +715,7 @@
 }
 
 
-M24SR::status_t M24SR::select_type(uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask)
+M24SR::status_t M24SR::select_type(const uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask)
 {
     status_t status;
     uint16_t length;
@@ -751,7 +751,7 @@
     const uint8_t M24SR_OPENSESSION_COMMAND = 0x26;
     const uint8_t M24SR_KILLSESSION_COMMAND = 0x52;
 
-	status_t ret;
+	status_t ret = M24SR_SUCCESS;
 
 	// if there is an RF session on-going then retry a few times to KILL, once an actual session is started RF is disabled
 	uint8_t retry = 3;
@@ -859,7 +859,7 @@
 }
 
 
-M24SR::status_t M24SR::is_S_block(uint8_t *buffer)
+M24SR::status_t M24SR::is_S_block(const uint8_t *buffer)
 {
     if ((buffer[OFFSET_PCB] & MASK_BLOCK) == MASK_S_BLOCK)
     {
@@ -870,7 +870,7 @@
 }
 
 
-void M24SR::build_I_block_command(uint16_t command_mask, C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer)
+void M24SR::build_I_block_command(uint16_t command_mask, const C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer)
 {
     uint16_t crc16;
     static uint8_t _block_number;
@@ -952,7 +952,7 @@
 }
 
 
-M24SR::status_t M24SR::is_correct_crc_residue(uint8_t *data, uint8_t length)
+M24SR::status_t M24SR::is_correct_crc_residue(const uint8_t *data, uint8_t length)
 {
     uint16_t res_crc = 0x0000;
     status_t status;
@@ -989,15 +989,16 @@
 }
 
 
-uint16_t M24SR::compute_crc(uint8_t *data, uint8_t length)
+uint16_t M24SR::compute_crc(const uint8_t *data, uint8_t length)
 {
     uint8_t block;
     uint16_t crc16 = 0x6363; /* ITU-V.41 */
+    uint8_t len = length;
 
     do {
         block = *data++;
         update_crc(block, &crc16);
-    } while (--length);
+    } while (--len);
 
     return crc16;
 }