Browse Source

fix apdus

master
amougel 7 years ago
parent
commit
c89a1cd2fe
  1. 6
      src/helpers/common.js
  2. 14
      src/helpers/devices/getDeviceInfo.js

6
src/helpers/common.js

@ -30,19 +30,14 @@ export async function getFirmwareInfo(transport: Transport<*>) {
const res = await transport.send(...APDUS.GET_FIRMWARE)
const byteArray = [...res]
const data = byteArray.slice(0, byteArray.length - 2)
console.log('data', data)
const targetIdStr = Buffer.from(data.slice(0, 4))
const targetId = targetIdStr.readUIntBE(0, 4)
console.log(targetId)
const seVersionLength = data[4]
const seVersion = Buffer.from(data.slice(5, 5 + seVersionLength)).toString()
console.log('seversion', seVersion)
const flagsLength = data[5 + seVersionLength]
console.log('flagel', flagsLength)
const flags = Buffer.from(
data.slice(5 + seVersionLength + 1, 5 + seVersionLength + 1 + flagsLength),
).toString()
console.log('flags', flags)
const mcuVersionLength = data[5 + seVersionLength + 1 + flagsLength]
let mcuVersion = Buffer.from(
@ -55,7 +50,6 @@ export async function getFirmwareInfo(transport: Transport<*>) {
mcuVersion = mcuVersion.slice(0, mcuVersion.length - 1)
}
mcuVersion = mcuVersion.toString()
console.log('mcu', mcuVersion)
return { targetId, seVersion, flags, mcuVersion }
} catch (err) {
const error = new Error(err.message)

14
src/helpers/devices/getDeviceInfo.js

@ -18,9 +18,9 @@ export type DeviceInfo = {
// prettier-ignore
const DETECT_CLUBCOIN = [
[0xe0, 0x04, 0x00, 0x00, 0x04, 0x31, 0x10, 0x00, 0x02],
[0xe0, 0x50, 0x00, 0x00, 0x08, 0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7],
[0xe0, 0x51, 0x80, 0x00, 0x8a, 0x41, 0x04, 0xc9, 0x8c, 0xa0, 0x99, 0x53, 0x47, 0x2b, 0x36, 0x06, 0x1e, 0x0e, 0x40, 0xc9, 0x3d, 0x50, 0x52, 0x34, 0x09, 0x0e, 0xfd, 0x74, 0xf1, 0xd7, 0xa2, 0x93, 0xe8, 0x28, 0x15, 0x9a, 0x97, 0x71, 0x1b, 0x33, 0xd1, 0x8a, 0xfc, 0x17, 0xad, 0x15, 0x6e, 0xae, 0xd9, 0x9c, 0xf4, 0x3b, 0x20, 0xe1, 0x5d, 0x64, 0xaf, 0x39, 0xa5, 0x51, 0x3b, 0x4e, 0x3c, 0x5f, 0x43, 0x17, 0xe6, 0x42, 0x70, 0x2f, 0x05, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xf1, 0xd2, 0xb8, 0x34, 0x99, 0x4a, 0x0c, 0x1f, 0x25, 0xea, 0x20, 0xcf, 0x33, 0xe3, 0x2b, 0xd0, 0x6b, 0xcf, 0x7c, 0x42, 0x4a, 0x02, 0xee, 0xe8, 0xf6, 0x96, 0x99, 0x20, 0xe1, 0xe8, 0xc2, 0xb3, 0x02, 0x20, 0x63, 0x2d, 0x19, 0xbd, 0x30, 0xab, 0x20, 0x76, 0x18, 0x78, 0x78, 0xae, 0xaa, 0x0f, 0x4d, 0x48, 0x04, 0x01, 0x32, 0x79, 0xd0, 0x16, 0xde, 0xca, 0x66, 0x93, 0xf3, 0x7b, 0x4e, 0x50, 0x7f, 0x43],
[0xe0, 0x04, 0x00, 0x00, Buffer.from([0x31, 0x10, 0x00, 0x02])],
[0xe0, 0x50, 0x00, 0x00, Buffer.from([0xe4, 0x6c, 0x4c, 0x71, 0x8b, 0xc8, 0x7f, 0xb7])],
[0xe0, 0x51, 0x80, 0x00, Buffer.from([0x41, 0x04, 0xc9, 0x8c, 0xa0, 0x99, 0x53, 0x47, 0x2b, 0x36, 0x06, 0x1e, 0x0e, 0x40, 0xc9, 0x3d, 0x50, 0x52, 0x34, 0x09, 0x0e, 0xfd, 0x74, 0xf1, 0xd7, 0xa2, 0x93, 0xe8, 0x28, 0x15, 0x9a, 0x97, 0x71, 0x1b, 0x33, 0xd1, 0x8a, 0xfc, 0x17, 0xad, 0x15, 0x6e, 0xae, 0xd9, 0x9c, 0xf4, 0x3b, 0x20, 0xe1, 0x5d, 0x64, 0xaf, 0x39, 0xa5, 0x51, 0x3b, 0x4e, 0x3c, 0x5f, 0x43, 0x17, 0xe6, 0x42, 0x70, 0x2f, 0x05, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00, 0xf1, 0xd2, 0xb8, 0x34, 0x99, 0x4a, 0x0c, 0x1f, 0x25, 0xea, 0x20, 0xcf, 0x33, 0xe3, 0x2b, 0xd0, 0x6b, 0xcf, 0x7c, 0x42, 0x4a, 0x02, 0xee, 0xe8, 0xf6, 0x96, 0x99, 0x20, 0xe1, 0xe8, 0xc2, 0xb3, 0x02, 0x20, 0x63, 0x2d, 0x19, 0xbd, 0x30, 0xab, 0x20, 0x76, 0x18, 0x78, 0x78, 0xae, 0xaa, 0x0f, 0x4d, 0x48, 0x04, 0x01, 0x32, 0x79, 0xd0, 0x16, 0xde, 0xca, 0x66, 0x93, 0xf3, 0x7b, 0x4e, 0x50, 0x7f, 0x43])],
]
const PROVIDERS = {
@ -34,23 +34,21 @@ export default async (transport: Transport<*>): Promise<DeviceInfo> => {
const res = await getFirmwareInfo(transport)
let { seVersion } = res
const { targetId, mcuVersion, flags } = res
console.log('raw seVersion', seVersion)
if (seVersion === '1.2') {
try {
for (let i = 0; i < DETECT_CLUBCOIN.length; i++) {
const instructions = DETECT_CLUBCOIN[i]
console.log('i, dsfdf', i, instructions)
await transport.send(...instructions) // TODO type wrong
await transport.send(...instructions)
}
console.log('ici club')
console.log('club 1.2 detected')
seVersion = '1.2.0-club'
} catch (e) {
console.log('failed club', e)
seVersion = '1.2.0'
}
}
const parsedVersion =
seVersion.match(/([0-9]+.[0-9])+(.[0-9]+)?((?!-osu)-([a-z]+))?(-osu)?/) || []
console.log('parsed', seVersion, parsedVersion)
const isOSU = typeof parsedVersion[5] !== 'undefined'
const providerName = parsedVersion[4] || ''
const providerId = PROVIDERS[providerName]

Loading…
Cancel
Save