def send_pairing_request():
    global pairing_procedure, access_address, pairing_iocap, paring_auth_request, master_address, advertiser_address
    master_address_raw = ''.join(map(lambda x: chr(int(x, 16)), master_address.split(':')))
    slave_address_raw = ''.join(map(lambda x: chr(int(x, 16)), advertiser_address.split(':')))
    BLESMPServer.set_pin_code('\x00' * 4)
    BLESMPServer.configure_connection(master_address_raw, slave_address_raw, 0,
                                      pairing_iocap, paring_auth_request)
    hci_res = BLESMPServer.pairing_request()
    if hci_res:
        pairing_procedure = True
        # Pairing request
        pkt = BTLE(access_addr=access_address) / BTLE_DATA() / L2CAP_Hdr() / HCI_Hdr(hci_res)[SM_Hdr]
        driver.send(pkt)
Beispiel #2
0
def send_pairing_request():
    global access_address, pairing_iocap, paring_auth_request, master_address, advertiser_address
    if enable_secure_connections is False:
        paring_auth_request = 0x01
    else:
        paring_auth_request = 0x01 | 0x08  # Secure connections

    master_address_raw = ''.join(map(lambda x: chr(int(x, 16)), master_address.split(':')))
    slave_address_raw = ''.join(map(lambda x: chr(int(x, 16)), advertiser_address.split(':')))
    BLESMPServer.set_pin_code('\x00' * 4)
    BLESMPServer.configure_connection(master_address_raw, slave_address_raw, 0,
                                      pairing_iocap, paring_auth_request)
    hci_res = BLESMPServer.pairing_request()
    if hci_res:
        # Pairing request
        pkt = BTLE(access_addr=access_address) / BTLE_DATA() / L2CAP_Hdr() / HCI_Hdr(hci_res)[SM_Hdr]
        driver.send(pkt)

    start_timeout('smp_timeout', SMP_TIMEOUT, smp_timeout)
            pkt = BTLE(access_addr=access_address) / BTLE_DATA() / CtrlPDU(
            ) / LL_VERSION_IND(version='4.2')
            driver.send(pkt)

        elif LL_VERSION_IND in pkt:
            if version_request_number < 1:
                master_address_raw = ''.join(
                    map(lambda x: chr(int(x, 16)), master_address.split(':')))
                slave_address_raw = ''.join(
                    map(lambda x: chr(int(x, 16)),
                        advertiser_address.split(':')))
                BLESMPServer.configure_connection(master_address_raw,
                                                  slave_address_raw, 0,
                                                  pairing_iocap,
                                                  paring_auth_request)
                hci_res = BLESMPServer.pairing_request()
                if hci_res:
                    pairing_procedure = True
                    # Pairing request
                    pkt = BTLE(access_addr=access_address) / BTLE_DATA(
                    ) / L2CAP_Hdr() / HCI_Hdr(hci_res)[SM_Hdr]
                    driver.send(pkt)
            version_request_number += 1

        elif pairing_procedure and SM_Hdr in pkt:
            update_timeout('scan_timeout')
            # Handle pairing response and so on
            smp_answer = BLESMPServer.send_hci(
                raw(HCI_Hdr() / HCI_ACL_Hdr() / L2CAP_Hdr() / pkt[SM_Hdr]))
            # Check if peripheral accepted secure connections pairing
            if SM_Pairing_Response in pkt: