### Setup Python 2 Virtual Environment Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-dev.txt Create and activate a Python 2 virtual environment for project development. Ensure Python 2 is installed on your system. ```bash virtualenv -p python2 venv/python2 && source venv/python2/bin/activate ``` -------------------------------- ### Setup Python 3 Virtual Environment Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-dev.txt Create and activate a Python 3 virtual environment for project development. Ensure Python 3 is installed on your system. ```bash virtualenv -p python3 venv/python3 && source venv/python3/bin/activate ``` -------------------------------- ### Setup Python 2 and 3 Virtual Environments Source: https://github.com/nfcpy/ndeflib/blob/master/docs/contributing.md Create virtual environments for Python 2 and 3, set up the ndef tool in develop mode, and install development dependencies. ```default virtualenv python-2 python3 -m venv python-3 source python-2/bin/activate python setup.py develop pip install -r requirements-dev.txt source python-3/bin/activate python setup.py develop pip install -r requirements-dev.txt ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-dev.txt Install or upgrade development requirements for the project. This command should be run after setting up the virtual environment. ```bash pip install --upgrade -r requirements-dev.txt ``` -------------------------------- ### Build and Upload to PyPI Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-pypi.txt Commands to build the source distribution and wheel, and upload to PyPI test or production servers. Ensure you have setuptools, wheel, and twine installed. ```bash python setup.py sdist bdist_wheel ``` ```bash twine upload -r test -s dist/ndeflib-x.y.z* ``` ```bash twine upload -r pypi -s dist/ndeflib-x.y.z* ``` -------------------------------- ### View Generated Documentation Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-dev.txt Open the generated HTML documentation in a web browser. Requires Sphinx and the sphinx-rtd-theme to be installed. ```bash firefox docs/_build/html/index.html ``` -------------------------------- ### WifiSimpleConfigRecord Usage Example Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Demonstrates how to create and populate a WifiSimpleConfigRecord with various Wi-Fi TLV attributes, including Out-Of-Band Password, SSID, RF bands, AP channel, MAC address, and vendor extensions. It also shows how to integrate this record into a Handover Select Record and encode the complete NDEF message. ```APIDOC ## Example Usage of WifiSimpleConfigRecord ### Description This example demonstrates the creation and usage of the `WifiSimpleConfigRecord` class, including setting various Wi-Fi TLV attributes and integrating it into an NDEF message. ### Method ```python import ndef import hashlib pkhash = hashlib.sha256(b'registrar public key').digest()[0:20] oobpwd = ndef.wifi.OutOfBandPassword(pkhash, 0x0007, b'') wfaext = ndef.wifi.WifiAllianceVendorExtension(('version-2', b'\x20')) carrier = ndef.WifiSimpleConfigRecord() carrier.name = '0' carrier.set_attribute('oob-password', oobpwd) carrier.set_attribute('ssid', b'802.11 network') carrier.set_attribute('rf-bands', '2.4GHz') carrier.set_attribute('ap-channel', 6) carrier.set_attribute('mac-address', b'\1\2\3\4\5\6') carrier['vendor-extension'] = [wfaext.encode()] print(carrier) hs = ndef.handover.HandoverSelectRecord('1.3') hs.add_alternative_carrier('active', carrier.name) octets = b''.join(ndef.message_encoder([hs, carrier])) print(len(octets)) ``` ### Output ``` NDEF Wifi Simple Config Record ID '0' Attributes 0x1001 0x1020 0x102C 0x103C 0x1045 0x1049 120 ``` ``` -------------------------------- ### Create and Configure Handover Message Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/handover.md Example demonstrating the creation of a Handover Select message, including a HandoverMediationRecord and a carrier record, and adding an alternative carrier to the mediation record. ```python >>> import ndef >>> carrier = ndef.Record('mimetype/subtype', 'ref', b'1234') >>> message = [ndef.HandoverMediationRecord('1.3'), carrier] >>> message[0].add_alternative_carrier('active', carrier.name) ``` -------------------------------- ### Set and Get LE Role Capabilities Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Demonstrates setting and retrieving the LE role capabilities of a device. The role can be 'Peripheral', 'Central', 'Peripheral/Central', or 'Central/Peripheral'. ```python >>> record['LE Role'] = b'\x02' >>> print(record.role_capabilities) Peripheral/Central >>> record.role_capabilities = "Central" >>> assert record['LE Role'] == b'\x01' ``` -------------------------------- ### Set and Get Flags Bitmap Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Shows how to set and retrieve the Flags bitmap for discoverable modes and BR/EDR support. Accepts numerical values or tuples of description strings. ```python >>> record['Flags'] = b'\x05' >>> print(record.flags) (5, 'LE Limited Discoverable Mode', 'BR/EDR Not Supported') >>> record.flags = ("LE General Discoverable Mode",) >>> record['Flags'] b'\x02' >>> record.flags = 8 >>> print(record.flags) (8, 'Simultaneous LE and BR/EDR to Same Device Capable (Controller)') ``` -------------------------------- ### Build and View Local Documentation Source: https://github.com/nfcpy/ndeflib/blob/master/docs/contributing.md Create the HTML documentation locally and open the main index file in your browser to preview the documentation. ```default (cd docs && make html) firefox docs/_build/html/index.html ``` -------------------------------- ### Create PeerToPeerDeviceInfo instance Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initialize PeerToPeerDeviceInfo with P2P Device Address, Configuration Methods, Primary Device Type, Secondary Device Type List, and Device Name. All arguments are mandatory. ```python >>> import ndef >>> adr = b'\x01\x02\x03\x04\x05\x06' >>> cfg = ('Label', 'Display') >>> pdt = 'Computer::Tablet' >>> sdtl = ('Computer::PC', ) >>> name = 'my tablet' >>> info = ndef.wifi.PeerToPeerDeviceInfo(adr, cfg, pdt, sdtl, name) ``` -------------------------------- ### Get Wi-Fi Peer-to-Peer Record Type Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Access the read-only 'type' attribute to get the MIME type for WifiPeerToPeerRecord. ```python >>> ndef.wifi.WifiPeerToPeerRecord().type 'application/vnd.wfa.p2p' ``` -------------------------------- ### Get Credential Attribute by Name Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieve a specific Credential attribute by its name. An optional index can be provided to get attributes that can have multiple values. ```python >>> import ndef >>> credential = ndef.wifi.Credential(('mac-address', b'123456')) >>> print(credential.get_attribute('mac-address')) MAC Address 31:32:33:34:35:36 >>> print(credential.get_attribute('mac-address', 1)) None ``` -------------------------------- ### Get Encoded Payload Data from WifiSimpleConfigRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieves the NDEF Record PAYLOAD as a bytes object, encoded from the current attribute data. The data is empty initially and gets populated as attributes are added. ```python >>> record = ndef.wifi.WifiSimpleConfigRecord() >>> record.data b'' >>> record['ap-channel'] = [b'\x00\x06'] >>> record.data b'\x10\x01\x00\x02\x00\x06' ``` -------------------------------- ### Initialize ConfigMethods with Names Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initialize ConfigMethods with one or more configuration method names. Any of the configuration method names can be tested for containment. ```python >>> import ndef >>> config_methods = ndef.wifi.ConfigMethods("Label", "Display") >>> assert ndef.wifi.ConfigMethods(0x000C) == config_methods >>> "Label" in config_methods True >>> config_methods.value (12, 'Label', 'Display') ``` -------------------------------- ### Get ChannelList length Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Determine the number of channel entries in the ChannelList. ```python >>> len(channel_list) 2 ``` -------------------------------- ### simple_pairing_randomizer_192 Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Gets or sets the Simple Pairing Randomizer R-192, used in pairing authentication. ```APIDOC ## simple_pairing_randomizer_192 ### Description Gets or sets the Simple Pairing Randomizer R-192. This is used with P192 Elliptic Curve Diffie Hellmann for authentication. If one device can only send information, authentication of the reading device will be based on that device knowing a random number R read from the NFC Tag. This attribute returns either the 128-bit integer converted from the 16-octet ‘Simple Pairing Randomizer R-192’ EIR value or None if the EIR data type is not present. When set, it stores a 128-bit integer as the 16-octet value of the ‘Simple Pairing Randomizer R-192’ EIR data type. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python record.simple_pairing_randomizer_192 = 0x010203040506070809000A0B0C0D0E0F ``` ### Response #### Success Response (200) - **simple_pairing_randomizer_192** (integer) - The 128-bit integer value of the Simple Pairing Randomizer R-192, or None. #### Response Example ```python # Example of getting the value print(record.simple_pairing_randomizer_192) # Example of getting the hex representation print(record.get('Simple Pairing Randomizer R-192').hex()) ``` ``` -------------------------------- ### Create and Encode Wi-Fi Simple Config Record with Handover Select Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Demonstrates creating a WifiSimpleConfigRecord with various attributes, including an Out-of-Band Password and a WifiAllianceVendorExtension, then encoding it into an NDEF message along with a HandoverSelectRecord. Use this to generate NDEF data for Wi-Fi provisioning. ```python >>> import ndef >>> import hashlib >>> pkhash = hashlib.sha256(b'registrar public key').digest()[0:20] >>> oobpwd = ndef.wifi.OutOfBandPassword(pkhash, 0x0007, b'') >>> wfaext = ndef.wifi.WifiAllianceVendorExtension(('version-2', b'\x20')) >>> carrier = ndef.WifiSimpleConfigRecord() >>> carrier.name = '0' >>> carrier.set_attribute('oob-password', oobpwd) >>> carrier.set_attribute('ssid', b'802.11 network') >>> carrier.set_attribute('rf-bands', '2.4GHz') >>> carrier.set_attribute('ap-channel', 6) >>> carrier.set_attribute('mac-address', b'\1\2\3\4\5\6') >>> carrier['vendor-extension'] = [wfaext.encode()] >>> print(carrier) NDEF Wifi Simple Config Record ID '0' Attributes 0x1001 0x1020 0x102C 0x103C 0x1045 0x1049 >>> hs = ndef.handover.HandoverSelectRecord('1.3') >>> hs.add_alternative_carrier('active', carrier.name) >>> octets = b''.join(ndef.message_encoder([hs, carrier])) >>> len(octets) 120 ``` -------------------------------- ### simple_pairing_hash_192 Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Gets or sets the Simple Pairing Hash C-192, used for secure pairing. ```APIDOC ## simple_pairing_hash_192 ### Description Gets or sets the Simple Pairing Hash C-192. This is a commitment of the device’s public key computed as HMAC-SHA-256 for the Curve-192 ECPK and Randomizer R-192. The Hash C should be generated anew for each pairing. This attribute returns either the 128-bit integer converted from the 16-octet ‘Simple Pairing Hash C-192’ EIR value or None if the EIR data type is not present. When set, it stores a 128-bit integer as the 16-octet value of the ‘Simple Pairing Hash C-192’ EIR data type. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python record.simple_pairing_hash_192 = 0x1234567890ABCDEF1234567890ABCDEF ``` ### Response #### Success Response (200) - **simple_pairing_hash_192** (integer) - The 128-bit integer value of the Simple Pairing Hash C-192, or None. #### Response Example ```python # Example of getting the value print(record.simple_pairing_hash_192) # Example of getting the hex representation print(record.get('Simple Pairing Hash C-192').hex()) ``` ``` -------------------------------- ### Access P2P Device Name Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Read-only attribute to get the friendly name of a P2P Device. ```python >>> info.device_name 'my tablet' ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/nfcpy/ndeflib/blob/master/requirements-dev.txt Generate project documentation using Sphinx. This command should be run from the 'docs/' directory. ```bash make html doctest ``` -------------------------------- ### Create and Populate DeviceInformationRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/deviceinfo.md Demonstrates initializing a DeviceInformationRecord with vendor and model names, then setting optional fields like unique_name, uuid_string, and version_string. It also shows how to encode the record into an NDEF message and check its byte length. ```python import ndef record = ndef.DeviceInformationRecord('Sony', 'RC-S380') record.unique_name = 'Black NFC Reader connected to PC' record.uuid_string = '123e4567-e89b-12d3-a456-426655440000' record.version_string = 'NFC Port-100 v1.02' len(b''.join(ndef.message_encoder([record]))) 92 ``` -------------------------------- ### Get ChannelList country string Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieve the country string associated with the ChannelList. This is a read-only attribute. ```python >>> import ndef >>> ndef.wifi.ChannelList(b"de\x04", (81, (1,))).country_string b'de\x04' ``` -------------------------------- ### Initialize WifiSimpleConfigRecord with Attribute Tuples Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Demonstrates initializing a WifiSimpleConfigRecord with pre-defined attribute type-value tuples. The same attribute type can appear multiple times. This is useful for creating records with known initial data. ```python >>> import ndef >>> print(ndef.WifiSimpleConfigRecord((0x1001, b'\x00\x06'), ('ap-channel', b'\x00\x06'))) NDEF Wifi Simple Config Record ID '' Attributes 0x1001 0x1001 ``` -------------------------------- ### Get WifiSimpleConfigRecord Type Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieves the read-only type of the Wifi Simple Configuration Record, which is 'application/vnd.wfa.wsc'. ```python >>> ndef.wifi.WifiSimpleConfigRecord().type 'application/vnd.wfa.wsc' ``` -------------------------------- ### Create and Compare Version2 Objects Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Demonstrates creating Version2 objects using different argument formats and asserting their equality. Use this to represent Wi-Fi version information. ```python import ndef assert ndef.wifi.Version2(0x20) == ndef.wifi.Version2(2, 0) ``` -------------------------------- ### Flags Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Get or set the Flags bitmap. Contains information on discoverable mode and BR/EDR support. ```APIDOC ## Flags ### Description Get or set the Flags bitmap. The ‘Flags’ AD type contains information on which discoverable mode to use and BR/EDR support and capability. The attribute returns the numerical flags value and descriptions for raised bits as an N-tuple. The attribute accepts either a numerical flags value or a tuple of description strings. ### Method GET, SET ### Endpoint N/A (Attribute of a record object) ### Request Example ```python >>> record['Flags'] = b'\x05' # Setting flags to 5 (LE Limited Discoverable Mode, BR/EDR Not Supported) >>> print(record.flags) (5, 'LE Limited Discoverable Mode', 'BR/EDR Not Supported') >>> record.flags = ("LE General Discoverable Mode",) # Setting flags to LE General Discoverable Mode >>> record['Flags'] b'\x02' >>> record.flags = 8 # Setting flags to 8 (Simultaneous LE and BR/EDR to Same Device Capable (Controller)) >>> print(record.flags) (8, 'Simultaneous LE and BR/EDR to Same Device Capable (Controller)') ``` ### Response #### Success Response (200) - **flags** (tuple) - A tuple containing the numerical flags value and descriptions for raised bits. ``` -------------------------------- ### simple_pairing_randomizer_256 Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Gets or sets the Simple Pairing Randomizer R-256, used in pairing authentication with Curve-256. ```APIDOC ## simple_pairing_randomizer_256 ### Description Gets or sets the Simple Pairing Randomizer R-256. This is used with P256 Elliptic Curve Diffie Hellmann for authentication. If one device can only send information, authentication of the reading device will be based on that device knowing a random number R read from the NFC Tag. This attribute returns either the 128-bit integer converted from the 16-octet ‘Simple Pairing Randomizer R-256’ EIR value or None if the EIR data type is not present. When set, it stores a 128-bit integer as the 16-octet value of the ‘Simple Pairing Randomizer R-256’ EIR data type. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python record.simple_pairing_randomizer_256 = 0x010203040506070809000A0B0C0D0E0F ``` ### Response #### Success Response (200) - **simple_pairing_randomizer_256** (integer) - The 128-bit integer value of the Simple Pairing Randomizer R-256, or None. #### Response Example ```python # Example of getting the value print(record.simple_pairing_randomizer_256) # Example of getting the hex representation print(record.get('Simple Pairing Randomizer R-256').hex()) ``` ``` -------------------------------- ### Create ChannelList instance Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initialize a ChannelList with a country string and multiple channel entries, each specifying an operating class and a list of channels. The country string must be bytes. ```python >>> import ndef >>> channel_list = ndef.wifi.ChannelList(b"de\x04", (81, (1, 6)), (115, (36, 44))) ``` -------------------------------- ### simple_pairing_hash_256 Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Gets or sets the Simple Pairing Hash C-256, used for secure pairing with Curve-256. ```APIDOC ## simple_pairing_hash_256 ### Description Gets or sets the Simple Pairing Hash C-256. This is a commitment of the device’s public key computed as HMAC-SHA-256 for the Curve-256 ECPK and Randomizer R-256. The Hash C should be generated anew for each pairing. This attribute returns either the 128-bit integer converted from the 16-octet ‘Simple Pairing Hash C-256’ EIR value or None if the EIR data type is not present. When set, it stores a 128-bit integer as the 16-octet value of the ‘Simple Pairing Hash C-256’ EIR data type. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python record.simple_pairing_hash_256 = 0x1234567890ABCDEF1234567890ABCDEF ``` ### Response #### Success Response (200) - **simple_pairing_hash_256** (integer) - The 128-bit integer value of the Simple Pairing Hash C-256, or None. #### Response Example ```python # Example of getting the value print(record.simple_pairing_hash_256) # Example of getting the hex representation print(record.get('Simple Pairing Hash C-256').hex()) ``` ``` -------------------------------- ### Access PeerToPeerDeviceInfo config methods Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieve the supported Configuration Methods as a tuple, including the bitmap value and descriptive strings. This attribute is read-only. ```python >>> info.config_methods (12, 'Label', 'Display') ``` -------------------------------- ### Access Descriptor Device Name Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Read-only attribute to get the friendly name of the P2P Device from a Descriptor. ```python >>> descriptor.device_name 'first device' ``` -------------------------------- ### Create Wi-Fi Simple Config Record Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Instantiate a Wi-Fi Simple Configuration Record. This record is used to encapsulate Wi-Fi credentials for easy network connection. ```python record = ndef.wifi.WifiSimpleConfigRecord() ``` -------------------------------- ### Access Descriptor Device Address Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Read-only attribute to get the 6-byte P2P Device Identifier from a Descriptor. ```python >>> descriptor.device_address b'\x01\x02\x03\x04\x05\x06' ``` -------------------------------- ### Get Minor Device Class String Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Retrieve the minor device class string from a DeviceClass object. ```python >>> ndef.bluetooth.DeviceClass(0x120104).minor_device_class ``` -------------------------------- ### Initialize WifiAllianceVendorExtension Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Demonstrates initializing a WifiAllianceVendorExtension with a version-2 subelement. This class is used for WFA-specific extensions. ```python import ndef wfa_ext = ndef.wifi.WifiAllianceVendorExtension(('version-2', b'\x20')) ``` -------------------------------- ### Create PeerToPeerCapability from strings Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initialize PeerToPeerCapability using lists of capability strings. This provides a more readable way to define capabilities. ```python >>> attr_2 = ndef.wifi.PeerToPeerCapability(['Service Discovery'], ['Group Formation']) ``` -------------------------------- ### Get Major Device Class String Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Retrieve the major device class string from a DeviceClass object. ```python >>> ndef.bluetooth.DeviceClass(0x120104).major_device_class ``` -------------------------------- ### Get Device Names from PeerToPeerGroupInfo Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Iterates through a PeerToPeerGroupInfo object to extract the device names of all connected P2P clients. ```python >>> [client_info.device_name for client_info in group_info] ['first device', 'second device'] ``` -------------------------------- ### Create Wi-Fi Credential Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Use this to set up a Wi-Fi credential with various attributes like network index, SSID, authentication type, encryption type, network key, and MAC address. It also shows how to add a Wi-Fi Alliance Vendor Extension. ```python import ndef credential = ndef.wifi.Credential() credential.set_attribute('network-index', 1) credential.set_attribute('ssid', b'my network name') credential.set_attribute('authentication-type', 'WPA2-Personal') credential.set_attribute('encryption-type', 'AES') credential.set_attribute('network-key', b'my secret password') credential.set_attribute('mac-address', b'\xFF\xFF\xFF\xFF\xFF\xFF') wfa_ext = ndef.wifi.WifiAllianceVendorExtension() wfa_ext.set_attribute('network-key-shareable', 1) credential['vendor-extension'] = [wfa_ext.encode()] print(credential) ``` -------------------------------- ### Create and Add Alternative Carrier to Handover Initiate Record Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/handover.md Demonstrates creating a HandoverInitiateRecord and adding an alternative carrier. The version can be a string or integer. Alternative carriers are defined by power state, data reference, and auxiliary data references. ```python >>> import ndef >>> carrier = ndef.Record('mimetype/subtype', 'ref', b'1234') >>> message = [ndef.HandoverInitiateRecord('1.3'), carrier] >>> message[0].add_alternative_carrier('active', carrier.name) ``` -------------------------------- ### Get Major Service Class Strings Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Retrieve a tuple of major service class strings from a DeviceClass object. ```python >>> ndef.bluetooth.DeviceClass(0x120104).major_service_class ``` -------------------------------- ### Create and Print PeerToPeerGroupInfo Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initializes a PeerToPeerGroupInfo object with client data tuples and prints its representation. This object holds information about P2P Clients in a P2P Group. ```python >>> import ndef >>> client_info_1 = ( ... b'\x01\x02\x03\x04\x05\x06', # P2P Device Address ... b'\x11\x12\x13\x14\x15\x16', # P2P Interface Address ... ('Service Discovery',), # Device Capabilities ... ('NFC Interface',), # Configuration Methods ... "Computer::Tablet", # Primary Device Type ... (), # Secondary Device Types ... 'first device', # Device name ... ) >>> client_info_2 = ( ... b'\x21\x22\x23\x24\x25\x26', # P2P Device Address ... b'\x31\x32\x33\x34\x35\x36', # P2P Interface Address ... ('Service Discovery',), # Device Capabilities ... ('NFC Interface',), # Configuration Methods ... "Computer::Tablet", # Primary Device Type ... (), # Secondary Device Types ... 'second device', # Device name ... ) >>> group_info = ndef.wifi.PeerToPeerGroupInfo(client_info_1, client_info_2) >>> print(group_info) P2P Group Info (Device 1: 01:02:03:04:05:06 11:12:13:14:15:16 Capability ['Service Discovery'] Config 0x0040 ['NFC Interface'] Type 'Computer::Tablet ' Name 'first device'), (Device 2: 21:22:23:24:25:26 31:32:33:34:35:36 Capability ['Service Discovery'] Config 0x0040 ['NFC Interface'] Type 'Computer::Tablet ' Name 'second device') ``` -------------------------------- ### Get Bluetooth Easy Pairing Record Type Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Accesses the read-only type of the Bluetooth Easy Pairing Record. ```python >>> record.type 'application/vnd.bluetooth.ep.oob' ``` -------------------------------- ### Access operating class from ChannelList entry Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Get the operating class number from a specific channel entry within the ChannelList. ```python >>> channel_list[0].operating_class 81 ``` -------------------------------- ### Create and Encode SmartposterRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/smartposter.md Demonstrates creating a SmartposterRecord with a resource URL, setting a title, resource type, size, and action, then encoding it into an NDEF message. The length of the encoded message is also shown. ```python >>> import ndef >>> record = ndef.SmartposterRecord('https://github.com/nfcpy/ndeflib') >>> record.set_title('Python package for parsing and generating NDEF', 'en') >>> record.resource_type = 'text/html' >>> record.resource_size = 1193970 >>> record.action = 'exec' >>> len(b''.join(ndef.message_encoder([record]))) ``` -------------------------------- ### Create VendorExtension Object Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Illustrates initializing a VendorExtension with vendor ID and vendor data. Ensure vendor_id is 3 bytes and vendor_data is between 0 and 1021 bytes. ```python import ndef vendor_id, vendor_data = (b'\x00\x37\x2A', b'123') assert ndef.wifi.VendorExtension(vendor_id, vendor_data).value == (vendor_id, vendor_data) ``` -------------------------------- ### Access channel numbers from ChannelList entry Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Get the list of channel numbers associated with a specific operating class in a ChannelList entry. ```python >>> channel_list[0].channel_numbers (1, 6) ``` -------------------------------- ### Create BluetoothLowEnergyRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Instantiate a BluetoothLowEnergyRecord with device address and advertising data. The device address is a tuple containing the address bytes and a flag for address type, and advertising data is a tuple of AD type and data bytes. ```python >>> import ndef >>> record = ndef.BluetoothLowEnergyRecord((0x08, b'My Blue'), (0x0D, b'100420')) >>> print(record) NDEF Bluetooth Low Energy Record ID '' Attributes 0x08 0x0D ``` -------------------------------- ### Get and Set Bluetooth LE Address Type Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Retrieve or update the address type ('public' or 'random') for a Bluetooth LE address. ```python >>> bdaddr = ndef.bluetooth.DeviceAddress('01:02:03:04:05:06', 'public') >>> bdaddr.type = 'random' >>> bdaddr ``` -------------------------------- ### Role Capabilities Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Get or set the LE role capabilities of the device. The value is a string describing one of the four defined roles. ```APIDOC ## Role Capabilities ### Description Get or set the LE role capabilities of the device. The value is a string describing one of the four defined roles `Peripheral`, `Central`, `Peripheral/Central` (Peripheral Role preferred for connection establishment), or `Central/Peripheral` (Central is preferred for connection establishment). ### Method GET, SET ### Endpoint N/A (Attribute of a record object) ### Request Example ```python >>> record['LE Role'] = b'\x02' # Setting role to Peripheral/Central >>> print(record.role_capabilities) Peripheral/Central >>> record.role_capabilities = "Central" # Setting role to Central >>> assert record['LE Role'] == b'\x01' ``` ### Response #### Success Response (200) - **role_capabilities** (string) - The LE role capabilities of the device. ``` -------------------------------- ### Clone ndeflib Repository Source: https://github.com/nfcpy/ndeflib/blob/master/docs/contributing.md Fork the repository and clone it locally to begin development. Ensure you are in the cloned directory. ```default git clone git@github.com:your-username/ndeflib.git cd ndeflib ``` -------------------------------- ### Get and Set Bluetooth Device Address String Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Access and modify the MAC address string of a DeviceAddress object. Accepts ':' or '-' as delimiters. ```python >>> bdaddr = ndef.bluetooth.DeviceAddress('01:02:03:04:05:06') >>> bdaddr.addr '01:02:03:04:05:06' >>> bdaddr.addr = '06-05-04-03-02-01' >>> bdaddr.addr ``` -------------------------------- ### Create and Access Smartposter Record Source: https://context7.com/nfcpy/ndeflib/llms.txt Creates a Smartposter record with a resource URL, multilingual titles, action, resource hints, and an icon. Requires the `ndef` library and an icon file. ```python import ndef # Create a smartposter with resource URL sp = ndef.SmartposterRecord("https://github.com/nfcpy/ndeflib") # Add multilingual titles sp.set_title("NFC Data Exchange Format decoder", "en") sp.set_title("NFC Datenaustauschformat Dekodierer", "de") # Set recommended action: 'exec', 'save', or 'edit' sp.action = 'exec' # Add resource type and size hints sp.resource_type = 'text/html' sp.resource_size = 52428 # Add icon (PNG image data) with open('icon.png', 'rb') as f: sp.add_icon('image/png', f.read()) # Access properties print(sp.resource.iri) # Resource IRI print(sp.title) # English title (or first available) print(sp.titles) # {'en': '...', 'de': '...'} print(sp.action) # 'exec' print(sp.icon) # PNG image bytes ``` ```python # Initialize with all parameters sp = ndef.SmartposterRecord( resource='https://example.com', title={'en': 'Example', 'de': 'Beispiel'}, action='exec', icon=open('icon.png', 'rb').read(), resource_type='text/html', resource_size=1024 ) # Encode smartposter message encoded = b''.join(ndef.message_encoder([sp])) ``` -------------------------------- ### Set and Get Bluetooth Easy Pairing Record Device Address Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Assigns and retrieves the Bluetooth Device Address for the out-of-band BD_ADDR field. ```python >>> record.device_address = '01:02:03:04:05:06' >>> record.device_address ndef.bluetooth.DeviceAddress('01:02:03:04:05:06', 'public') ``` -------------------------------- ### Create PeerToPeerCapability from integers Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initialize PeerToPeerCapability with integer bitmasks for device and group capabilities. Useful for direct bit manipulation. ```python >>> import ndef >>> attr_1 = ndef.wifi.PeerToPeerCapability(0b00000001, 0b01000000) ``` -------------------------------- ### UUID-R Attribute Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md The UUID-R Attribute contains the universally unique identifier (UUID) generated as a GUID by the Registrar. It uniquely identifies an operational device. ```APIDOC ## UUID-R ### Description The UUID-R Attribute contains the universally unique identifier (UUID) generated as a GUID by the Registrar. It uniquely identifies an operational device and should survive reboots and resets. ### Class `ndef.wifi.UUIDRegistrar(value)` The *value* argument may be either a `uuid.UUID` object, or the 16 `bytes` of a UUID, or any `str` value that can be used to initialize `uuid.UUID` object. ### Parameters * **value** (uuid.UUID, bytes, or str) - The UUID value. ### Value The UUID-R string. ### Request Example ```python import ndef import uuid # Example with bytes bytes_uuid = bytes(range(16)) def.wifi.UUIDRegistrar(bytes_uuid).value # Example with string str_uuid = "00010203-0405-0607-0809-0a0b0c0d0e0f" def.wifi.UUIDRegistrar(str_uuid).value ``` ### Response Example ```python # For ndef.wifi.UUIDRegistrar(bytes(range(16))).value '00010203-0405-0607-0809-0a0b0c0d0e0f' # For ndef.wifi.UUIDRegistrar('00010203-0405-0607-0809-0a0b0c0d0e0f').value '00010203-0405-0607-0809-0a0b0c0d0e0f' ``` ``` -------------------------------- ### Initialize HandoverSelectRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/handover.md Initialize the HandoverSelectRecord with version, error information, and alternative carriers. Version can be an integer or a string. Error is a tuple, and alternative carriers are tuples. ```python HandoverSelectRecord(version='1.3', error=None, *alternative_carrier) ``` -------------------------------- ### UUID-E Attribute Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md The UUID-E Attribute contains the universally unique identifier (UUID) generated as a GUID by the Enrollee. It uniquely identifies an operational device. ```APIDOC ## UUID-E ### Description The UUID-E Attribute contains the universally unique identifier (UUID) generated as a GUID by the Enrollee. It uniquely identifies an operational device and should survive reboots and resets. ### Class `ndef.wifi.UUIDEnrollee(value)` The *value* argument may be either a `uuid.UUID` object, or the 16 `bytes` of a UUID, or any `str` value that can be used to initialize `uuid.UUID` object. ### Parameters * **value** (uuid.UUID, bytes, or str) - The UUID value. ### Value The UUID-E string. ### Request Example ```python import ndef import uuid # Example with bytes bytes_uuid = bytes(range(16)) ndef.wifi.UUIDEnrollee(bytes_uuid).value # Example with string str_uuid = "00010203-0405-0607-0809-0a0b0c0d0e0f" def.wifi.UUIDEnrollee(str_uuid).value ``` ### Response Example ```python # For ndef.wifi.UUIDEnrollee(bytes(range(16))).value '00010203-0405-0607-0809-0a0b0c0d0e0f' # For ndef.wifi.UUIDEnrollee("00010203-0405-0607-0809-0a0b0c0d0e0f").value '00010203-0405-0607-0809-0a0b0c0d0e0f' ``` ``` -------------------------------- ### Get WFA Subelement Attribute Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Retrieves a specific WFA subelement attribute by name from a WifiAllianceVendorExtension. The index parameter can be used for multiple attributes of the same name. ```python wfa_ext = ndef.wifi.WifiAllianceVendorExtension(('version-2', b'\x20')) wfa_ext.get_attribute('version-2') ``` -------------------------------- ### WifiSimpleConfigRecord Class Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Details the WifiSimpleConfigRecord class, its initialization, and how to access and manage Wi-Fi TLV attributes using dictionary-like access and specific methods. ```APIDOC ## NDEF Record Classes - Wi-Fi Simple Config Record ### Description The `WifiSimpleConfigRecord` class is used to store Wi-Fi TLV (Type-Length-Value) Attributes as defined in the Wi-Fi Simple Configuration specification. It behaves like a dictionary, allowing access to attributes via numeric IDs or symbolic names. ### Class Definition ```python class WifiSimpleConfigRecord ``` ### Initialization ```python WifiSimpleConfigRecord(*args) ``` Initializes the record with optional Wi-Fi Simple Config Attribute Type and Value tuples. ### Attributes - **type** (read-only): Returns the record type string 'application/vnd.wfa.wsc'. - **name**: A string representing the NDEF Record ID field. Defaults to an empty string. - **data**: A bytes object containing the NDEF Record PAYLOAD encoded from the current attribute data. - **attribute_names** (read-only): A list of all supported WSC Attribute names that can be used as keys or in methods. ### Methods - **get_attribute(name, index=0)**: Retrieves the Wi-Fi Attribute specified by `name` and `index`. Returns `None` if the attribute or index is not found. - **set_attribute(name, *args)**: Sets the Wi-Fi Attribute `name` to a single instance constructed from the provided arguments (`*args`). - **add_attribute(name, *args)**: Adds a new instance of the Wi-Fi Attribute `name` constructed from the provided arguments (`*args`). ### Dictionary-like Access Attributes can be accessed and modified using dictionary syntax with either numeric Attribute IDs or symbolic `attribute_names`. #### Example of Dictionary Access ```python import ndef record = ndef.WifiSimpleConfigRecord() record[0x1020] = [b'\x00\x01\x02\x03\x04\x05'] assert record[0x1020] == record['mac-address'] record['mac-address'].append(b'\x05\x04\x03\x02\x01\x00') print(record['mac-address']) ``` ### Example of Initialization ```python import ndef print(ndef.WifiSimpleConfigRecord((0x1001, b'\x00\x06'), ('ap-channel', b'\x00\x06'))) ``` ### Example of `type` attribute ```python import ndef print(ndef.wifi.WifiSimpleConfigRecord().type) ``` ### Example of `name` attribute ```python import ndef record = ndef.wifi.WifiSimpleConfigRecord() record.name = 'WSC Record' print(record.name) ``` ### Example of `data` attribute ```python import ndef record = ndef.wifi.WifiSimpleConfigRecord() record.data record['ap-channel'] = [b'\x00\x06'] print(record.data) ``` ### Example of `attribute_names` ```python import ndef print('\n'.join(sorted(ndef.wifi.WifiSimpleConfigRecord().attribute_names))) ``` ### Example of `get_attribute` ```python import ndef record = ndef.WifiSimpleConfigRecord(('ap-channel', b'\x00\x06')) print(record.get_attribute('ap-channel', 0)) print(record.get_attribute('ap-channel', 1)) ``` ### Example of `set_attribute` ```python import ndef record = ndef.WifiSimpleConfigRecord(('ap-channel', b'\x00\x06')) record.set_attribute('ap-channel', 10) print(record.get_attribute('ap-channel', 0)) print(record.get_attribute('ap-channel', 1)) ``` ``` -------------------------------- ### Initialize HandoverMediationRecord Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/handover.md Initialize the HandoverMediationRecord with a version number and zero or more alternative carriers. The version can be an integer or a string. ```python HandoverMediationRecord(version='1.3', *alternative_carrier) ``` -------------------------------- ### Security Manager TK Value Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Get or set the Security Manager TK Value used in OOB association model with LE Legacy pairing. ```APIDOC ## Security Manager TK Value ### Description Get or set the Security Manager TK Value. The Security Manager TK Value is used by the LE Security Manager in the OOB association model with LE Legacy pairing. Reading this attribute returns an unsigned integer converted from the 16 byte ‘Security Manager TK Value’ AD type octets, or None if the AD type is not found. An unsigned integer assigned to this attribute is written as the 16 byte ‘Security Manager TK Value’ AD type after conversion. ### Method GET, SET ### Endpoint N/A (Attribute of a record object) ### Request Example ```python >>> record.security_manager_tk_value = 0x1234567890ABCDEF1234567890ABCDEF >>> record.get('Security Manager TK Value').hex() 'efcdab9078563412efcdab9078563412' >>> record.security_manager_tk_value 24197857200151252728969465429440056815 ``` ### Response #### Success Response (200) - **security_manager_tk_value** (integer or None) - The Security Manager TK Value as an unsigned integer, or None if not found. ``` -------------------------------- ### Compare PeerToPeerCapability instances Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Assert equality between two PeerToPeerCapability instances, one initialized with integers and the other with strings. ```python >>> assert attr_1 == attr_2 ``` -------------------------------- ### Set and Get BluetoothLowEnergyRecord Name Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/bluetooth.md Modify or retrieve the NDEF Record ID field. Assigning a string to this attribute sets the record's name. ```python >>> record.name = 'BLE Record' >>> record.name 'BLE Record' ``` -------------------------------- ### Create and Print PeerToPeerGroupID Source: https://github.com/nfcpy/ndeflib/blob/master/docs/records/wifi.md Initializes a PeerToPeerGroupID attribute with a device address and SSID, then prints its representation. Both arguments must be byte strings, and the device address must be 6 bytes long. ```python >>> import ndef >>> attr = ndef.wifi.PeerToPeerGroupID(b'\1\2\3\4\5\6', b'P2P Group SSID') >>> print(attr) P2P Group ID 01:02:03:04:05:06 SSID 50:32:50:20:47:72:6F:75:70:20:53:53:49:44 ```