1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.uwb.params; 18 19 import com.android.server.uwb.config.ConfigParam; 20 import com.android.server.uwb.data.UwbCccConstants; 21 import com.android.server.uwb.data.UwbUciConstants; 22 23 import com.google.uwb.support.base.Params; 24 import com.google.uwb.support.ccc.CccOpenRangingParams; 25 import com.google.uwb.support.ccc.CccParams; 26 import com.google.uwb.support.fira.FiraParams; 27 28 public class CccEncoder extends TlvEncoder { 29 @Override getTlvBuffer(Params param)30 public TlvBuffer getTlvBuffer(Params param) { 31 if (param instanceof CccOpenRangingParams) { 32 return getTlvBufferFromCccOpenRangingParams(param); 33 } 34 return null; 35 } 36 getTlvBufferFromCccOpenRangingParams(Params baseParam)37 private TlvBuffer getTlvBufferFromCccOpenRangingParams(Params baseParam) { 38 CccOpenRangingParams params = (CccOpenRangingParams) baseParam; 39 int hoppingConfig = params.getHoppingConfigMode(); 40 int hoppingSequence = params.getHoppingSequence(); 41 42 int hoppingMode = CccParams.HOPPING_CONFIG_MODE_NONE; 43 44 switch (hoppingConfig) { 45 46 case CccParams.HOPPING_CONFIG_MODE_CONTINUOUS: 47 if (hoppingSequence == CccParams.HOPPING_SEQUENCE_DEFAULT) { 48 hoppingMode = UwbCccConstants.HOPPING_CONFIG_MODE_CONTINUOUS_DEFAULT; 49 } else { 50 hoppingMode = UwbCccConstants.HOPPING_CONFIG_MODE_CONTINUOUS_AES; 51 } 52 break; 53 case CccParams.HOPPING_CONFIG_MODE_ADAPTIVE: 54 if (hoppingSequence == CccParams.HOPPING_SEQUENCE_DEFAULT) { 55 hoppingMode = UwbCccConstants.HOPPING_CONFIG_MODE_MODE_ADAPTIVE_DEFAULT; 56 } else { 57 hoppingMode = UwbCccConstants.HOPPING_CONFIG_MODE_MODE_ADAPTIVE_AES; 58 } 59 break; 60 } 61 62 TlvBuffer tlvBuffer = new TlvBuffer.Builder() 63 .putByte(ConfigParam.DEVICE_TYPE, 64 (byte) UwbUciConstants.DEVICE_TYPE_CONTROLEE) // DEVICE_TYPE 65 .putByte(ConfigParam.STS_CONFIG, 66 (byte) UwbUciConstants.STS_MODE_DYNAMIC) // STS_CONFIG 67 .putByte(ConfigParam.CHANNEL_NUMBER, (byte) params.getChannel()) // CHANNEL_ID 68 .putByte(ConfigParam.NUMBER_OF_CONTROLEES, 69 (byte) params.getNumResponderNodes()) // NUMBER_OF_ANCHORS 70 .putInt(ConfigParam.RANGING_INTERVAL, 71 params.getRanMultiplier() * 96) //RANGING_INTERVAL = RAN_Multiplier * 96 72 .putByte(ConfigParam.RANGE_DATA_NTF_CONFIG, 73 (byte) UwbUciConstants.RANGE_DATA_NTF_CONFIG_DISABLE) // RNG_DATA_NTF 74 .putByte(ConfigParam.DEVICE_ROLE, 75 (byte) UwbUciConstants.RANGING_DEVICE_ROLE_INITIATOR) // DEVICE_ROLE 76 .putByte(ConfigParam.MULTI_NODE_MODE, 77 (byte) FiraParams.MULTI_NODE_MODE_ONE_TO_MANY) // MULTI_NODE_MODE 78 .putByte(ConfigParam.SLOTS_PER_RR, 79 (byte) params.getNumSlotsPerRound()) // SLOTS_PER_RR 80 .putByte(ConfigParam.KEY_ROTATION, (byte) 0X01) // KEY_ROTATION 81 .putByte(ConfigParam.HOPPING_MODE, (byte) hoppingMode) // HOPPING_MODE 82 .putByteArray(ConfigParam.RANGING_PROTOCOL_VER, 83 ConfigParam.RANGING_PROTOCOL_VER_BYTE_COUNT, 84 params.getProtocolVersion().toBytes()) // RANGING_PROTOCOL_VER 85 .putShort(ConfigParam.UWB_CONFIG_ID, (short) params.getUwbConfig()) // UWB_CONFIG_ID 86 .putByte(ConfigParam.PULSESHAPE_COMBO, 87 params.getPulseShapeCombo().toBytes()[0]) // PULSESHAPE_COMBO 88 .putShort(ConfigParam.URSK_TTL, (short) 0x2D0) // URSK_TTL 89 // T(Slotk) = N(Chap_per_Slot) * T(Chap) 90 // T(Chap) = 400RSTU 91 // reference : digital key release 3 20.2 MAC Time Grid 92 .putShort(ConfigParam.SLOT_DURATION, 93 (short) (params.getNumChapsPerSlot() * 400)) // SLOT_DURATION 94 .putByte(ConfigParam.PREAMBLE_CODE_INDEX, 95 (byte) params.getSyncCodeIndex()) // PREAMBLE_CODE_INDEX 96 .build(); 97 98 return tlvBuffer; 99 } 100 } 101