1# Copyright 2022 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from __future__ import annotations 16from bumble.pairing import PairingConfig, PairingDelegate 17from dataclasses import dataclass 18from typing import Any, Dict 19 20 21@dataclass 22class Config: 23 io_capability: PairingDelegate.IoCapability = PairingDelegate.NO_OUTPUT_NO_INPUT 24 identity_address_type: PairingConfig.AddressType = PairingConfig.AddressType.RANDOM 25 pairing_sc_enable: bool = True 26 pairing_mitm_enable: bool = True 27 pairing_bonding_enable: bool = True 28 smp_local_initiator_key_distribution: PairingDelegate.KeyDistribution = ( 29 PairingDelegate.DEFAULT_KEY_DISTRIBUTION 30 ) 31 smp_local_responder_key_distribution: PairingDelegate.KeyDistribution = ( 32 PairingDelegate.DEFAULT_KEY_DISTRIBUTION 33 ) 34 35 def load_from_dict(self, config: Dict[str, Any]) -> None: 36 io_capability_name: str = config.get( 37 'io_capability', 'no_output_no_input' 38 ).upper() 39 self.io_capability = getattr(PairingDelegate, io_capability_name) 40 identity_address_type_name: str = config.get( 41 'identity_address_type', 'random' 42 ).upper() 43 self.identity_address_type = getattr( 44 PairingConfig.AddressType, identity_address_type_name 45 ) 46 self.pairing_sc_enable = config.get('pairing_sc_enable', True) 47 self.pairing_mitm_enable = config.get('pairing_mitm_enable', True) 48 self.pairing_bonding_enable = config.get('pairing_bonding_enable', True) 49 self.smp_local_initiator_key_distribution = config.get( 50 'smp_local_initiator_key_distribution', 51 PairingDelegate.DEFAULT_KEY_DISTRIBUTION, 52 ) 53 self.smp_local_responder_key_distribution = config.get( 54 'smp_local_responder_key_distribution', 55 PairingDelegate.DEFAULT_KEY_DISTRIBUTION, 56 ) 57