"""
from the bluetooth specs, bglib,and bgapi constants
"""
################################################################################
# reference: https://www.bluetooth.com/specifications/assigned-numbers/
gatt_characteristics = {
    0x2A7E: 'Aerobic Heart Rate Lower Limit',
    0x2A84: 'Aerobic Heart Rate Upper Limit',
    0x2A7F: 'Aerobic Threshold',
    0x2A80: 'Age',
    0x2A5A: 'Aggregate',
    0x2A43: 'Alert Category ID',
    0x2A42: 'Alert Category ID Bit Mask',
    0x2A06: 'Alert Level',
    0x2A44: 'Alert Notification Control Point',
    0x2A3F: 'Alert Status',
    0x2AB3: 'Altitude',
    0x2A81: 'Anaerobic Heart Rate Lower Limit',
    0x2A82: 'Anaerobic Heart Rate Upper Limit',
    0x2A83: 'Anaerobic Threshold',
    0x2A58: 'Analog',
    0x2A59: 'Analog Output',
    0x2A73: 'Apparent Wind Direction',
    0x2A72: 'Apparent Wind Speed',
    0x2A01: 'Appearance',
    0x2AA3: 'Barometric Pressure Trend',
    0x2A19: 'Battery Level',
    0x2A1B: 'Battery Level State',
    0x2A1A: 'Battery Power State',
    0x2A49: 'Blood Pressure Feature',
    0x2A35: 'Blood Pressure Measurement',
    0x2A9B: 'Body Composition Feature',
    0x2A9C: 'Body Composition Measurement',
    0x2A38: 'Body Sensor Location',
    0x2AA4: 'Bond Management Control Point',
    0x2AA5: 'Bond Management Features',
    0x2A22: 'Boot Keyboard Input Report',
    0x2A32: 'Boot Keyboard Output Report',
    0x2A33: 'Boot Mouse Input Report',
    0x2B2B: 'BSS Control Point',
    0x2B2C: 'BSS Response',
    0x2AA8: 'CGM Feature',
    0x2AA7: 'CGM Measurement',
    0x2AAB: 'CGM Session Run Time',
    0x2AAA: 'CGM Session Start Time',
    0x2AAC: 'CGM Specific Ops Control Point',
    0x2AA9: 'CGM Status',
    0x2ACE: 'Cross Trainer Data',
    0x2A5C: 'CSC Feature',
    0x2A5B: 'CSC Measurement',
    0x2A2B: 'Current Time',
    0x2A66: 'Cycling Power Control Point',
    0x2A65: 'Cycling Power Feature',
    0x2A63: 'Cycling Power Measurement',
    0x2A64: 'Cycling Power Vector',
    0x2A99: 'Database Change Increment',
    0x2A85: 'Date of Birth',
    0x2A86: 'Date of Threshold Assessment',
    0x2A08: 'Date Time',
    0x2AED: 'Date UTC',
    0x2A0A: 'Day Date Time',
    0x2A09: 'Day of Week',
    0x2A7D: 'Descriptor Value Changed',
    0x2A7B: 'Dew Point',
    0x2A56: 'Digital',
    0x2A57: 'Digital Output',
    0x2A0D: 'DST Offset',
    0x2A6C: 'Elevation',
    0x2A87: 'Email Address',
    0x2B2D: 'Emergency ID',
    0x2B2E: 'Emergency Text',
    0x2A0B: 'Exact Time 100',
    0x2A0C: 'Exact Time 256',
    0x2A88: 'Fat Burn Heart Rate Lower Limit',
    0x2A89: 'Fat Burn Heart Rate Upper Limit',
    0x2A26: 'Firmware Revision String',
    0x2A8A: 'First Name',
    0x2AD9: 'Fitness Machine Control Point',
    0x2ACC: 'Fitness Machine Feature',
    0x2ADA: 'Fitness Machine Status',
    0x2A8B: 'Five Zone Heart Rate Limits',
    0x2AB2: 'Floor Number',
    0x2AA6: 'Central Address Resolution',
    0x2A00: 'Device Name',
    0x2A04: 'Peripheral Preferred Connection Parameters',
    0x2A02: 'Peripheral Privacy Flag',
    0x2A03: 'Reconnection Address',
    0x2A05: 'Service Changed',
    0x2A8C: 'Gender',
    0x2A51: 'Glucose Feature',
    0x2A18: 'Glucose Measurement',
    0x2A34: 'Glucose Measurement Context',
    0x2A74: 'Gust Factor',
    0x2A27: 'Hardware Revision String',
    0x2A39: 'Heart Rate Control Point',
    0x2A8D: 'Heart Rate Max',
    0x2A37: 'Heart Rate Measurement',
    0x2A7A: 'Heat Index',
    0x2A8E: 'Height',
    0x2A4C: 'HID Control Point',
    0x2A4A: 'HID Information',
    0x2A8F: 'Hip Circumference',
    0x2ABA: 'HTTP Control Point',
    0x2AB9: 'HTTP Entity Body',
    0x2AB7: 'HTTP Headers',
    0x2AB8: 'HTTP Status Code',
    0x2ABB: 'HTTPS Security',
    0x2A6F: 'Humidity',
    0x2B22: 'IDD Annunciation Status',
    0x2B25: 'IDD Command Control Point',
    0x2B26: 'IDD Command Data',
    0x2B23: 'IDD Features',
    0x2B28: 'IDD History Data',
    0x2B27: 'IDD Record Access Control Point',
    0x2B21: 'IDD Status',
    0x2B20: 'IDD Status Changed',
    0x2B24: 'IDD Status Reader Control Point',
    0x2A2A: 'IEEE 11073-20601 Regulatory Certification Data List',
    0x2AD2: 'Indoor Bike Data',
    0x2AAD: 'Indoor Positioning Configuration',
    0x2A36: 'Intermediate Cuff Pressure',
    0x2A1E: 'Intermediate Temperature',
    0x2A77: 'Irradiance',
    0x2AA2: 'Language',
    0x2A90: 'Last Name',
    0x2AAE: 'Latitude',
    0x2A6B: 'LN Control Point',
    0x2A6A: 'LN Feature',
    0x2AB1: 'Local East Coordinate',
    0x2AB0: 'Local North Coordinate',
    0x2A0F: 'Local Time Information',
    0x2A67: 'Location and Speed Characteristic',
    0x2AB5: 'Location Name',
    0x2AAF: 'Longitude',
    0x2A2C: 'Magnetic Declination',
    0x2AA0: 'Magnetic Flux Density – 2D',
    0x2AA1: 'Magnetic Flux Density – 3D',
    0x2A29: 'Manufacturer Name String',
    0x2A91: 'Maximum Recommended Heart Rate',
    0x2A21: 'Measurement Interval',
    0x2A24: 'Model Number String',
    0x2A68: 'Navigation',
    0x2A3E: 'Network Availability',
    0x2A46: 'New Alert',
    0x2AC5: 'Object Action Control Point',
    0x2AC8: 'Object Changed',
    0x2AC1: 'Object First-Created',
    0x2AC3: 'Object ID',
    0x2AC2: 'Object Last-Modified',
    0x2AC6: 'Object List Control Point',
    0x2AC7: 'Object List Filter',
    0x2ABE: 'Object Name',
    0x2AC4: 'Object Properties',
    0x2AC0: 'Object Size',
    0x2ABF: 'Object Type',
    0x2ABD: 'OTS Feature',
    0x2A5F: 'PLX Continuous Measurement Characteristic',
    0x2A60: 'PLX Features',
    0x2A5E: 'PLX Spot-Check Measurement',
    0x2A50: 'PnP ID',
    0x2A75: 'Pollen Concentration',
    0x2A2F: 'Position 2D',
    0x2A30: 'Position 3D',
    0x2A69: 'Position Quality',
    0x2A6D: 'Pressure',
    0x2A4E: 'Protocol Mode',
    0x2A62: 'Pulse Oximetry Control Point',
    0x2A78: 'Rainfall',
    0x2B1D: 'RC Feature',
    0x2B1E: 'RC Settings',
    0x2B1F: 'Reconnection Configuration Control Point',
    0x2A52: 'Record Access Control Point',
    0x2A14: 'Reference Time Information',
    0x2A3A: 'Removable',
    0x2A4D: 'Report',
    0x2A4B: 'Report Map',
    0x2AC9: 'Resolvable Private Address Only',
    0x2A92: 'Resting Heart Rate',
    0x2A40: 'Ringer Control point',
    0x2A41: 'Ringer Setting',
    0x2AD1: 'Rower Data',
    0x2A54: 'RSC Feature',
    0x2A53: 'RSC Measurement',
    0x2A55: 'SC Control Point',
    0x2A4F: 'Scan Interval Window',
    0x2A31: 'Scan Refresh',
    0x2A3C: 'Scientific Temperature Celsius',
    0x2A10: 'Secondary Time Zone',
    0x2A5D: 'Sensor Location',
    0x2A25: 'Serial Number String',
    0x2A3B: 'Service Required',
    0x2A28: 'Software Revision String',
    0x2A93: 'Sport Type for Aerobic and Anaerobic Thresholds',
    0x2AD0: 'Stair Climber Data',
    0x2ACF: 'Step Climber Data',
    0x2A3D: 'String',
    0x2AD7: 'Supported Heart Rate Range',
    0x2AD5: 'Supported Inclination Range',
    0x2A47: 'Supported New Alert Category',
    0x2AD8: 'Supported Power Range',
    0x2AD6: 'Supported Resistance Level Range',
    0x2AD4: 'Supported Speed Range',
    0x2A48: 'Supported Unread Alert Category',
    0x2A23: 'System ID',
    0x2ABC: 'TDS Control Point',
    0x2A6E: 'Temperature',
    0x2A1F: 'Temperature Celsius',
    0x2A20: 'Temperature Fahrenheit',
    0x2A1C: 'Temperature Measurement',
    0x2A1D: 'Temperature Type',
    0x2A94: 'Three Zone Heart Rate Limits',
    0x2A12: 'Time Accuracy',
    0x2A15: 'Time Broadcast',
    0x2A13: 'Time Source',
    0x2A16: 'Time Update Control Point',
    0x2A17: 'Time Update State',
    0x2A11: 'Time with DST',
    0x2A0E: 'Time Zone',
    0x2AD3: 'Training Status',
    0x2ACD: 'Treadmill Data',
    0x2A71: 'True Wind Direction',
    0x2A70: 'True Wind Speed',
    0x2A95: 'Two Zone Heart Rate Limit',
    0x2A07: 'Tx Power Level',
    0x2AB4: 'Uncertainty',
    0x2A45: 'Unread Alert Status',
    0x2AB6: 'URI',
    0x2A9F: 'User Control Point',
    0x2A9A: 'User Index',
    0x2A76: 'UV Index',
    0x2A96: 'VO2 Max',
    0x2A97: 'Waist Circumference',
    0x2A98: 'Weight',
    0x2A9D: 'Weight Measurement',
    0x2A9E: 'Weight Scale Feature',
    0x2A79: 'Wind Chill',
}

gatt_declarations = {
    0x2803: 'Characteristic Declaration',
    0x2802: 'Include',
    0x2800: 'Primary Service',
    0x2801: 'Secondary Service',
}

gatt_descriptors = {
    0x2905: 'Characteristic Aggregate Format',
    0x2900: 'Characteristic Extended Properties',
    0x2904: 'Characteristic Presentation Format',
    0x2901: 'Characteristic User Description',
    0x2902: 'Client Characteristic Configuration',
    0x290B: 'Environmental Sensing Configuration',
    0x290C: 'Environmental Sensing Measurement',
    0x290D: 'Environmental Sensing Trigger Setting',
    0x2907: 'External Report Reference',
    0x2909: 'Number of Digitals',
    0x2908: 'Report Reference',
    0x2903: 'Server Characteristic Configuration',
    0x290E: 'Time Trigger Setting',
    0x2906: 'Valid Range',
    0x290A: 'Value Trigger Setting',
}

gatt_services = {
    0x1800: 'Generic Access',
    0x1811: 'Alert Notification Service',
    0x1815: 'Automation IO',
    0x180F: 'Battery Service',
    0x183B: 'Binary Sensor',
    0x1810: 'Blood Pressure',
    0x181B: 'Body Composition',
    0x181E: 'Bond Management Service',
    0x181F: 'Continuous Glucose Monitoring',
    0x1805: 'Current Time Service',
    0x1818: 'Cycling Power',
    0x1816: 'Cycling Speed and Cadence',
    0x180A: 'Device Information',
    0x183C: 'Emergency Configuration',
    0x181A: 'Environmental Sensing',
    0x1826: 'Fitness Machine',
    0x1801: 'Generic Attribute',
    0x1808: 'Glucose',
    0x1809: 'Health Thermometer',
    0x180D: 'Heart Rate',
    0x1823: 'HTTP Proxy',
    0x1812: 'Human Interface Device',
    0x1802: 'Immediate Alert',
    0x1821: 'Indoor Positioning',
    0x183A: 'Insulin Delivery',
    0x1820: 'Internet Protocol Support Service',
    0x1803: 'Link Loss',
    0x1819: 'Location and Navigation',
    0x1827: 'Mesh Provisioning Service',
    0x1828: 'Mesh Proxy Service',
    0x1807: 'Next DST Change Service',
    0x1825: 'Object Transfer Service',
    0x180E: 'Phone Alert Status Service',
    0x1822: 'Pulse Oximeter Service',
    0x1829: 'Reconnection Configuration',
    0x1806: 'Reference Time Update Service',
    0x1814: 'Running Speed and Cadence',
    0x1813: 'Scan Parameters',
    0x1824: 'Transport Discovery',
    0x1804: 'Tx Power',
    0x181C: 'User Data',
    0x181D: 'Weight Scale',
}

gap_data_type = {
    0x01: 'Flags',
    0x02: 'Incomplete List of 16-bit Service Class UUIDs',
    0x03: 'Complete List of 16-bit Service Class UUIDs',
    0x04: 'Incomplete List of 32-bit Service Class UUIDs',
    0x05: 'Complete List of 32-bit Service Class UUIDs',
    0x06: 'Incomplete List of 128-bit Service Class UUIDs',
    0x07: 'Complete List of 128-bit Service Class UUIDs',
    0x08: 'Shortened Local Name',
    0x09: 'Complete Local Name',
    0x0A: 'Tx Power Level',
    0x0D: 'Class of Device',
    0x0E: 'Simple Pairing Hash C-192',
    0x0E: 'Simple Pairing Hash C',
    0x0F: 'Simple Pairing Randomizer R-192',
    0x0F: 'Simple Pairing Randomizer R',
    0x10: 'Device ID',
    0x10: 'Security Manager TK Value',
    0x11: 'Security Manager Out of Band Flags',
    0x12: 'Slave Connection Interval Range',
    0x14: 'List of 16-bit Service Solicitation UUIDs',
    0x15: 'List of 128-bit Service Solicitation UUIDs',
    0x16: 'Service Data - 16-bit UUID',
    0x16: 'Service Data',
    0x17: 'Public Target Address',
    0x18: 'Random Target Address',
    0x19: 'Appearance',
    0x1A: 'Advertising Interval',
    0x1B: 'LE Bluetooth Device Address',
    0x1C: 'LE Role',
    0x1D: 'Simple Pairing Hash C-256',
    0x1E: 'Simple Pairing Randomizer R-256',
    0x1F: 'List of 32-bit Service Solicitation UUIDs',
    0x20: 'Service Data - 32-bit UUID',
    0x21: 'Service Data - 128-bit UUID',
    0x22: 'LE Secure Connections Confirmation Value',
    0x23: 'LE Secure Connections Random Value',
    0x24: 'URI',
    0x25: 'Indoor Positioning',
    0x26: 'Transport Discovery Data',
    0x27: 'LE Supported Features',
    0x28: 'Channel Map Update Indication',
    0x29: 'PB-ADV',
    0x2A: 'Mesh Message',
    0x2B: 'Mesh Beacon',
    0x3D: '3D Information Data',
    0xFF: 'Manufacturer Specific Data',
}
################################################################################
################################################################################
# reference: BLUEGIGA BLUETOOTH SMART SOFTWARE V.1.8 API DOCUMENTATION

bgapi_message_type = {                          # page 14
    0x00: 'command',                               
    0x00: 'response',
    0x80: 'event',
}

address_type = {                                # page 104
    0: 'Public address',         
    1: 'Random address',
}

flags_enum = {                                  # page 76
    1: 'connection_connected,',                 # bit 1
    2: 'connection_encrypted,',                 # bit 2
    3: 'connection_completed,',                 # bit 3
    4: 'connection_parameters_change,',         # bit 4
}

packet_type = {                                 # page 110
    0: 'Connectable advertisement packet',
    2: 'Non connectable advertisement packet',
    4: 'Scan response packet',
    6: 'Discoverable advertisement packet',
}

bgapi_command_classes = {                       # page 15
    0x00: 'system',
    0x01: 'persistent_store',
    0x02: 'attribute_database',
    0x03: 'connection',
    0x04: 'attribute_client',
    0x05: 'security_manager',
    0x06: 'generic_access_profile',
    0x07: 'hardware',
}

attribute_value_type = {                        # page 46
    0: 'attclient_attribute_value_type_read',
    1: 'attclient_attribute_value_type_notify',
    2: 'attclient_attribute_value_type_indicate',
    3: 'attclient_attribute_value_type_read_by_type',
    4: 'attclient_attribute_value_type_read_blob',
    5: 'attclient_attribute_value_type_indicate_rsp_req',
}

bgapi_errors = {                                # page 214
    0x0180: 'invalid parameter',
    0x0181: 'device in wrong state',
    0x0182: 'out of memory',
    0x0183: 'feature not implemented',
    0x0184: 'command not recognized',
    0x0185: 'timeout',
    0x0186: 'not connected',
    0x0187: 'flow',
    0x0188: 'user attribute',
    0x0189: 'invalid license key',
    0x018A: 'command too long',
    0x018B: 'out of bonds',
    0x018C: 'script overflow',
}

bluetooth_errors = {
    0x0205: 'authentication failure',
    0x0206: 'pin or key missing',
    0x0207: 'memory capacity exceeded',
    0x0208: 'connection timeout',
    0x0209: 'connection limit exceeded',
    0x020C: 'command disallowed',
    0x0212: 'invalid command parameters',
    0x0213: 'remote user terminated connection',
    0x0216: 'connection terminated by local host',
    0x0222: 'link layer response timeout',
    0x0228: 'link layer instant passed',
    0x023A: 'controller busy',
    0x023B: 'unacceptable connection interval',
    0x023C: 'directed advertising timeout',
    0x023D: 'message integrity check failure',
    0x023E: 'connection failed to be established',
}

security_manager_protocol_errors = {
    0x0301: 'passkey entry failed',
    0x0302: 'out of band data is not available',
    0x0303: 'authentication requirements',
    0x0304: 'confirm value failed',
    0x0305: 'pairing not supported',
    0x0306: 'encryption key size',
    0x0307: 'command not supported',
    0x0308: 'unspecified reasone',
    0x0309: 'repeated attempts',
    0x030A: 'invalid parameters',
}

attribute_protocol_erors = {
    0x0401: 'invalid handle',
    0x0402: 'read not permitted',
    0x0403: 'write not permitted',
    0x0404: 'invalid PDU',
    0x0405: 'insufficient authentication',
    0x0406: 'request not supported',
    0x0407: 'invalid offset',
    0x0408: 'insufficient authorization',
    0x0409: 'prepare queue full',
    0x040A: 'attribute not found',
    0x040B: 'attribute not long',
    0x040C: 'insufficient encryption key size',
    0x040D: 'invalid attribute value strength',
    0x040E: 'unlikely error',
    0x040F: 'insufficient encryption',
    0x0410: 'unsupported group type',
    0x0411: 'insufficient resources',
    0x0480: 'application error codes',
}

################################################################################
