1#!/usr/bin/env python3
2#
3#   Copyright 2022 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17
18class OobData:
19    """
20    This represents the data generated from the device
21    """
22
23    address = None
24    confirmation = None
25    randomizer = None
26
27    ADDRESS_WITH_TYPE_LENGTH = 14
28
29    def __init__(self, address, confirmation, randomizer):
30        self.address = address
31        self.confirmation = confirmation
32        self.randomizer = randomizer
33
34    def to_sl4a_address(self):
35        oob_address = self.address.upper()
36        address_str_octets = []
37        i = 1
38        buf = ""
39        for c in oob_address:
40            buf += c
41            if i % 2 == 0:
42                address_str_octets.append(buf)
43                buf = ""
44            i += 1
45        address_str_octets = address_str_octets[:6]
46        address_str_octets.reverse()
47        return ":".join(address_str_octets)
48
49    def to_sl4a_address_type(self):
50        if len(self.address) != self.ADDRESS_WITH_TYPE_LENGTH:
51            return -1
52        return self.address.upper()[-1]
53