Skip to content

140 Password Add ​

The smartphone sends a command via Bluetooth to ssm_touch to add a password. The data sent includes the password, and password name. (If the name exceeds 20 bytes, only the first 20 bytes will be used.) Upon successful addition, the device returns a response.

Sequence Diagram ​

Mobile Sent Data ​

ByteContent
[0]Password header(KB_HEADER)
[1]Password Type(KB_TYPE)
[2]Password length(in bytes)
[3 ~ 18]Password(byte array)
[19]Name length(in bytes)
[20-39]Password name(byte array)

item code : SSM_OS3_PASSCODE_ADD (138)


Enumerations and Data Structure ​

c
typedef enum {
    KB_DATA_EMPTY = 0xFF,
    KB_DATA_USED = 0xF0,
    KB_DATA_DELETED = 0x00,
} KB_HEADER;

typedef enum {
    KB_TYPE_LOCAL = 0x00,
} KB_TYPE;

typedef struct {
    uint8_t kb_header;  // EMPTY 0xFF, USED 0xF0, DELETED 0x00
    uint8_t kb_type;  // Type of Password(0x00: local, 0x01: cloud)
    uint8_t kb_id_lg;  // Length of Password
    uint8_t kb_id[16];  // Content of Password
    uint8_t kb_name_lg;  // Length of name
    uint8_t kb_name[KB_NAME_LENGTH];  // Content of name
} card_note_t;  ///total 40 bytes

Payload Format ​

The payload data structure for password addition is as follows:

Byte OffsetNameTypeDescription
kb_headeruint8Password header(see KB_HEADER)
kb_typeuint8Password Type(see KB_TYPE)
0kb_id_lguint8Length of password (in bytes)
Password ID Len ~ 1kb_iduint8[16]Password as byte array
Password ID Len + 1kb_name_lguint8Length of name (in bytes)
(Password Name Len + Password ID Len + 1) ~ (Password ID Len + 2)kb_nameuint8[20]UTF-8 encoded name byte array

Example Payload Bytes ​

Assuming Password is 123456 and name is "Home":

Byte OffsetContent (Hex)Description
00xF0KB_DATA_USED(used)
10x00KB_TYPE_LOCAL(local)
20x06Password length = 6 bytes("123456")
3~1801 02 03 04 05 06 00 00 00 00 00 00 00 00 00 00"123456" + padding (total 16 bytes)
190x04Name length = 4 bytes
20~3948 6F 6D 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"Home" in UTF-8 + 0 padding (total 20 bytes)

ssm_touch Return Content ​

Byte210
DataresCommand codeResponse type
DescriptionCommand resultCurrent command identifierResponse type constant
  • type : SSM2_OP_CODE_RESPONSE(0x07)
  • item code : SSM_OS3_PASSCODE_ADD(138)
  • res:CMD_RESULT_SUCCESS(0x00)or failure status code

Failure Status Codes ​

C
typedef enum {
    CMD_RESULT_SUCCESS,
    CMD_RESULT_INVALID_FORMAT,
    CMD_RESULT_NOT_SUPPORTED,
    CMD_RESULT_STORAGE_FAIL,
    CMD_RESULT_INVALID_SIG,
    CMD_RESULT_NOT_FOUND,
    CMD_RESULT_UNKNOWN,
    CMD_RESULT_BUSY,
    CMD_RESULT_INVALID_PARAM,
    CMD_RESULT_INVALID_ACTION,
} cmd_result_e;

iOS、Android、ESP32 Example ​

Android Example ​

kotlin
internal fun ByteArray.padEnd(length: Int, value: Byte = 0x00.toByte()): ByteArray {
    if (this.size >= length) return this
    return this + ByteArray(length - this.size) { value }
}

override fun keyBoardPassCodeAdd(id: ByteArray, name: String, result: CHResult<CHEmpty>) {
        sendCommandSafely(
            SesameOS3Payload(
                SesameItemCode.SSM_OS3_PASSCODE_ADD.value,
                byteArrayOf(0xF0/*KB_DATA_USED*/.toByte()) + byteArrayOf(0x00/*KB_TYPE_LOCAL*/.toByte()) + byteArrayOf(id.size.toByte()) + id.padEnd(16, 0x00.toByte()) + byteArrayOf(name.toByteArray().size.toByte()) + name.toByteArray().padEnd(16, 0x00.toByte())
            ), result
        ) { res ->
            result.invoke(Result.success(CHResultState.CHResultStateBLE(CHEmpty())))
        }
    }

esp32 Example ​

c
// todo

iOS Example ​

swift
TODO()