Skip to content

101. Add Sesame (Add) ​

The phone sends a command and Token to add, sesame5 replies the command is successful, and ssm_touch actively pushes the Sesame list to the phone. (For details of the Sesame list, see 102_pub_ssm_key)

Activity Diagram (Add Sesame4) ​

The Bluetooth address of Sesame4 cannot be parsed from the sent information, so it needs to scan the surrounding Bluetooth devices to find the Bluetooth address of Sesame4.

Activity Diagram (Add Sesame5) ​

The Bluetooth address of Sesame5 can be parsed from the sent information, so there's no need to scan the surrounding Bluetooth devices.

sessionKey = AES_CMAC(key:device_name, input:"candy")

address = sessionKey[0~5]

address[5] |= 0xC0

Sequence Diagram ​

Phone Sends Out Data ​

Byte32 ~ 1716 ~ 10
DatasecretKeydevice_nameitem code

item code : SSM3_ITEM_ADD_SESAME (101)

ssm_touch Return Content ​

Byte210
Dataresitem_codetype
DescriptionCommand processing statusCommand numberPush type

type : SSM2_OP_CODE_RESPONSE (0x07)

item code : SSM3_ITEM_ADD_SESAME (101)

res : CMD_RESULT_SUCCESS (0x00)

iOS, Android, ESP32 Examples ​

Android Example ​

kotlin
    override fun insertSesame(sesame: CHDevices, result: CHResult<CHEmpty>) {
      if (checkBle(result)) return
      if (sesame !is CHSesameLock) {// 不是锁不处理
          L.d("hcia", "[SSM BTN]isLocker?")
          result.invoke(Result.failure(CHError.BleInvalidAction.value))
          return
      }
      L.d("hcia", "送出鑰匙sesame.getKey():" + sesame.getKey())

      if (sesame is CHSesameOS3) {///ss5/5pro,bike2
          val ssm = sesame as CHDeviceUtil
          val noDashUUID = ssm.sesame2KeyData!!.deviceUUID.replace("-", "")
          val noDashUUIDDATA = noDashUUID.hexStringToByteArray()
          val ssmSecKa = ssm.sesame2KeyData!!.secretKey.hexStringToByteArray()
          sendCommand(SesameOS3Payload(SesameItemCode.ADD_SESAME.value, noDashUUIDDATA + ssmSecKa)) { ssm2ResponsePayload ->
//                L.d("hcia", "ADD_SESAME cmdResultCode:" + ssm2ResponsePayload.cmdResultCode)
              result.invoke(Result.success(CHResultState.CHResultStateBLE(CHEmpty())))
          }
      } else {/// ss3/4,bot1,bike1
          val ssm = sesame as CHDeviceUtil
          val noDashUUID = ssm.sesame2KeyData!!.deviceUUID.replace("-", "")
          val b64k = noDashUUID.hexStringToByteArray().base64Encode().replace("=", "")
          val ssmIRData = b64k.toByteArray()
          val ssmPKData = ssm.sesame2KeyData!!.sesame2PublicKey.hexStringToByteArray()
          val ssmSecKa = ssm.sesame2KeyData!!.secretKey.hexStringToByteArray()
          val allKey = ssmIRData + ssmPKData + ssmSecKa
          sendCommand(SesameOS3Payload(SesameItemCode.ADD_SESAME.value, allKey)) {
              result.invoke(Result.success(CHResultState.CHResultStateBLE(CHEmpty())))
          }
      }
  }

iOS Example ​

swift
     func insertSesame(_ device: CHDevice, matterProductModel: MatterProductModel, result: @escaping CHResult<CHEmpty>) {
      if (self.checkBle(result)) { return }
      let noDashUUID = device.deviceId.uuidString.replacingOccurrences(of: "-", with: "", options: [], range: nil)
      let noDashUUIDData = noDashUUID.hexStringtoData()
      let ssmSecKa = device.getKey()!.secretKey.hexStringtoData()
      let matter = UInt8(device.productModel.rawValue).data + matterProductModel.rawValue.data
      sendCommand(.init(.addSesame,noDashUUIDData + ssmSecKa + matter)) { (response) in
          result(.success(CHResultStateNetworks(input: CHEmpty())))
      }
  }

ESP Example ​

c
        log_info_array_ex("[main][SSM3_ITEM_ADD_SESAME]", p_param->data, p_param->length)
    talk_to_mob(p_param->conidx, SSM2_SEG_PARSING_TYPE_CIPHERTEXT, ble_tx_buf, 3);
    ssm_add_key(p_param->data, p_param->length);
    publish_ssm_keys(p_param->conidx);