a
    kÄ#dØ  ã                   @   s¤   d Z ddlmZmZmZmZmZmZmZ ddl	m
Z
mZmZ ddlmZmZ dZG dd„ deeƒZG dd	„ d	eeƒZG d
d„ deƒZeeeed� eeedd� dS )a	  
scapy.contrib.ibeacon - Apple iBeacon Bluetooth LE proximity beacons.

Packet format documentation can be found at at:

* https://en.wikipedia.org/wiki/IBeacon#Packet_Structure_Byte_Map (public)
* https://developer.apple.com/ibeacon/ (official, requires license)

é    )ÚByteEnumFieldÚConditionalFieldÚLenFieldÚPacketListFieldÚ
ShortFieldÚSignedByteFieldÚ	UUIDField)ÚEIR_HdrÚEIR_Manufacturer_Specific_DataÚLowEnergyBeaconHelper)Úbind_layersÚPacketéL   c                   @   sb   e Zd ZdZdZeddddddd	d
dddœƒeedddd�dd„ ƒgZdd„ Z	dd„ Z
dd„ ZdS )ÚApple_BLE_Submessagez#
    A basic Apple submessage.
    zApple BLE submessageÚsubtypeNÚoverflowZibeaconZairdropZairpodsZairplay_sinkZairplay_srcZhandoffZnearby)é   é   é   é   é	   é
   é   é   ÚlenÚB)Úfmtc                 C   s
   | j dkS )Nr   ©r   )Zpkt© r   úL/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/contrib/ibeacon.pyÚ<lambda>/   ó    zApple_BLE_Submessage.<lambda>c                 C   s>   | j dkr"|d d… |dd … fS |d | j… || jd … fS )Nr   r   )r   r   )ÚselfÚsr   r   r   Úextract_padding3   s    
z$Apple_BLE_Submessage.extract_paddingc                 C   s   t | gd�S )z+Wraps this submessage in a Apple_BLE_Frame.)Úplist)ÚApple_BLE_Frame©r"   r   r   r   Úbuild_frame<   s    z Apple_BLE_Submessage.build_framec                 C   s   |   ¡  ¡ S )zSee Apple_BLE_Frame.build_eir.)r(   Ú	build_eirr'   r   r   r   r)   @   s    zApple_BLE_Submessage.build_eir)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Únamer   r   r   Úfields_descr$   r(   r)   r   r   r   r   r      s(   ø
ýõ	r   c                   @   s*   e Zd ZdZdZeddeƒgZdd„ ZdS )r&   zÚ
    The wrapper for a BLE manufacturer-specific data advertisement from Apple
    devices.

    Each advertisement is composed of one or multiple submessages.

    The length of this field comes from the EIR_Hdr.
    zApple BLE broadcast framer%   Nc                 C   s   t jtƒ tƒ  |  g S )z1Builds a list of EIR messages to wrap this frame.)r   Zbase_eirr	   r
   r'   r   r   r   r)   S   s    ÿzApple_BLE_Frame.build_eir)	r*   r+   r,   r-   r.   r   r   r/   r)   r   r   r   r   r&   E   s
   
ÿr&   c                   @   s>   e Zd ZdZdZeddejd�eddƒeddƒeddƒgZ	dS )	ÚIBeacon_DatazS
    iBeacon broadcast data frame. Composed on top of an Apple_BLE_Submessage.
    ziBeacon dataÚuuidN)Zuuid_fmtÚmajorÚminorZtx_power)
r*   r+   r,   r-   r.   r   Z	FORMAT_BEr   r   r/   r   r   r   r   r0   [   s   ür0   )Z
company_idr   r   N)r-   Zscapy.fieldsr   r   r   r   r   r   r   Zscapy.layers.bluetoothr	   r
   r   Zscapy.packetr   r   Z	APPLE_MFGr   r&   r0   r   r   r   r   Ú<module>   s   
$*ÿ