mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-07 13:45:03 -05:00
Sansa Connect: Use deviceid in USB Serial Number
Atmel AT88SC6416C CryptoMemory is almost I2C compatible. The device is connected to bitbanged I2C bus shared with compliant I2C devices. Change-Id: Iec54702db1bdfb93c01291eef18ec60391c63b16
This commit is contained in:
parent
663539619c
commit
b4ecd612f7
8 changed files with 183 additions and 0 deletions
|
|
@ -294,4 +294,12 @@ int i2c_read_bytes(unsigned short address, unsigned short reg,
|
|||
return i2c_read_data(dm320_i2c_bus, address, reg, buf, count);
|
||||
}
|
||||
|
||||
int i2c_write_read_bytes(unsigned short address,
|
||||
const unsigned char* buf_write, int count_write,
|
||||
unsigned char* buf_read, int count_read)
|
||||
{
|
||||
return i2c_write_read_data(dm320_i2c_bus, address, buf_write, count_write,
|
||||
buf_read, count_read);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ int i2c_read(unsigned short address, unsigned char* buf, int count);
|
|||
#ifdef HAVE_SOFTWARE_I2C
|
||||
int i2c_read_bytes(unsigned short address, unsigned short reg,
|
||||
unsigned char* buf, int count);
|
||||
int i2c_write_read_bytes(unsigned short address,
|
||||
const unsigned char* buf_write, int count_write,
|
||||
unsigned char* buf_read, int count_read);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: $
|
||||
*
|
||||
* Copyright (C) 2021 by Tomasz Moń
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <ctype.h>
|
||||
#include "cryptomem-sansaconnect.h"
|
||||
#include "i2c-dm320.h"
|
||||
|
||||
/* Command values */
|
||||
#define WRITE_USER_ZONE 0xB0
|
||||
#define READ_USER_ZONE 0xB2
|
||||
#define SYSTEM_WRITE 0xB4
|
||||
#define SYSTEM_READ 0xB6
|
||||
#define VERIFY_CRYPTO 0xB8
|
||||
#define VERIFY_PASSWORD 0xBA
|
||||
|
||||
/* SYSTEM_WRITE ADDR 1 values */
|
||||
#define WRITE_CONFIG 0x00
|
||||
#define WRITE_FUSES 0x01
|
||||
#define SEND_CHECKSUM 0x02
|
||||
#define SET_USER_ZONE 0x03
|
||||
|
||||
int cryptomem_read_deviceid(char deviceid[32])
|
||||
{
|
||||
int ret;
|
||||
unsigned int i;
|
||||
unsigned char cmd_data[3];
|
||||
|
||||
/* It is assumed that other I2C communication has already taken place
|
||||
* (e.g. power_init()) before this function is called and thus we don't
|
||||
* have to send atleast 5 dummy clock cycles here.
|
||||
*/
|
||||
|
||||
cmd_data[0] = SET_USER_ZONE;
|
||||
cmd_data[1] = 0;
|
||||
cmd_data[2] = 0;
|
||||
ret = i2c_write(SYSTEM_WRITE, cmd_data, sizeof(cmd_data));
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
cmd_data[0] = 0;
|
||||
cmd_data[1] = 0;
|
||||
cmd_data[2] = 32;
|
||||
ret = i2c_write_read_bytes(READ_USER_ZONE, cmd_data, sizeof(cmd_data),
|
||||
deviceid, 32);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Verify that deviceid contains only printable ASCII characters */
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if (!isprint(deviceid[i]))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: $
|
||||
*
|
||||
* Copyright (C) 2021 by Tomasz Moń
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CRYPTOMEM_SANSACONNECT_H_
|
||||
#define _CRYPTOMEM_SANSACONNECT_H_
|
||||
|
||||
int cryptomem_read_deviceid(char deviceid[32]);
|
||||
|
||||
#endif /* _CRYPTOMEM_SANSACONNECT_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue