maybe this is a bug of CryptoAuthlib in C coding

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

file name:hal_i2c_bitbang.c

function:ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)

description:rxlength is passed in form of pointer,which means it will be updated by hal_i2c_receive(),since first byte received is actual length of data bytes;

in fact,hal_i2c_receive() didn't update rxlength,it updated rxdata[0] as actual length of data bytes being read;

 

next:checking the functions which have called hal_i2c_receive()

file:atca_basic.c

function:ATCA_STATUS atcab_***()

description:many functions in atca_basic.c have typical call of atreceive() like below(i wonder how much skills was played when atreceive() was linked to hal_i2c_receive()):

 

      // receive the response
        if ( (status = atreceive( _gIface, packet.data, &packet.rxsize)) != ATCA_SUCCESS )
            break;

        // Check response size
        if (packet.rxsize < 4) {
            if (packet.rxsize > 0)
                status = ATCA_RX_FAIL;
            else
                status = ATCA_RX_NO_RESPONSE;
            break;
        }

 

Seems that it was checking packet.rxsize as feedback of bytes read,in fact it was not updated......packet.data[0] was indicating that......

 

Above was only i read and  i am worrying if something was out of order...

uzslm

Last Edited: Wed. Feb 1, 2017 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2c_bitbang_at88ck9000.c:
ATCA_STATUS i2c_send_bytes(uint8_t count, uint8_t *data)
{
 ATCA_STATUS status = ATCA_TX_TIMEOUT;

 uint8_t i;

 for (i = 0; i < count; i++) {
  status = i2c_send_byte(data[i]);
  if (status != ATCA_SUCCESS) {
   if (i > 0)
    status = ATCA_TX_FAIL;
   break;
  }
 }

 return status;
}

 

if second and later bytes sent failed,then err code will be ATCA_TX_FAIL,otherwise if the first byte sent failed, status of i2c_send_byte() will be returned(=ATCA_TX_TIMEOUT) ;

what is the difference between ATCA_TX_TIMEOUT and ATCA_TX_FAIL?? does that mean if the first byte to send is device's address,then will return  ATCA_TX_TIMEOUT if the device does not response on the address,otherwise if the device does not response on the data bytes sending to him,will return ATCA_TX_FAIL?

in fact,above function was only used to send data bytes rather than device address,see hal_i2c_bitbang.c:hal_i2c_send():

hal_i2c_send_slave_address() was firstly used to send address,and i2c_send_bytes() was only used for sending data bytes.

so, to my opinion, i2c_send_bytes() will only  return ATCA_TX_FAIL or ATCA_SUCCESS.

uzslm

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ATCA_STATUS hal_i2c_wake(ATCAIface iface)
{
    ATCAIfaceCfg *cfg = atgetifacecfg(iface);

    ATCA_STATUS status = ATCA_WAKE_FAILED;

    int bus     = cfg->atcai2c.bus;
    uint8_t response[4] = { 0x00, 0x00, 0x00, 0x00 };
    uint8_t expected_response[4] = { 0x04, 0x11, 0x33, 0x43 };

    //! Set I2C pins
    i2c_set_pin(i2c_hal_data[bus]->pin_sda, i2c_hal_data[bus]->pin_scl);

    //! Generate Wake Token
    i2c_send_wake_token();

    //! Wait tWHI + tWLO
    atca_delay_us(cfg->wake_delay);

    //! Receive Wake Response
    status = hal_i2c_receive(iface, response, sizeof(response));//obviously this is an error since prototype of hal_i2c_receive() does not match,is the lib tested??
    if (status == ATCA_SUCCESS) {
        //! Compare response with expected_response
        if (memcmp(response, expected_response, 4) != 0)
            status = ATCA_WAKE_FAILED;
    }

    return status;
}

uzslm