a
    kÄ#dv  ã                   @   sŽ  d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZmZmZmZ ddlm  mZ ddlmZmZ dZdd	d
ddœZdddddddddddddddœZG dd„ deƒZG dd„ deeƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZG d&d'„ d'eƒZG d(d)„ d)eƒZ G d*d+„ d+eƒZ!eeedd,� eee d-d,� eeedd.� eeed-d.� eeed/d.� eee!d0d.� eeeed1� dS )2a°  
scapy.contrib.eddystone - Google Eddystone Bluetooth LE proximity beacons.

The Eddystone specification can be found at:
https://github.com/google/eddystone/blob/master/protocol-specification.md

These beacons are used as building blocks for other systems:

* Google's Physical Web <https://google.github.io/physical-web/>
* RuuviTag <https://github.com/ruuvi/ruuvi-sensor-protocols>
* Waze Beacons <https://www.waze.com/beacons>

é    )Úorb)ÚIntFieldÚSignedByteFieldÚStrFieldÚBitFieldÚStrFixedLenFieldÚ
ShortFieldÚFixedPointFieldÚByteEnumField)ÚEIR_HdrÚEIR_ServiceData16BitUUIDÚ!EIR_CompleteList16BitServiceUUIDsÚLowEnergyBeaconHelperN)Úbind_layersÚPacketiªþ  s   http://www.s   https://www.s   http://s   https://)r   é   é   é   s   .com/s   .org/s   .edu/s   .net/s   .info/s   .biz/s   .gov/s   .coms   .orgs   .edus   .nets   .infos   .bizs   .gov)r   r   r   r   é   é   é   é   é   é	   é
   é   é   é   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚEddystoneURLFieldc                 C   sš   |d u rdS t ƒ }d}|t|ƒk r’t|| ƒ}|dkr~t ¡ D ]2\}}| ||¡r>| |¡ |t|ƒd 7 } qˆq>| |¡ n
| |¡ |d7 }qt|ƒS )Nó    r   é.   r   )Ú	bytearrayÚlenr   ÚEDDYSTONE_URL_TABLEÚitemsÚ
startswithÚappendÚbytes)ÚselfÚpktÚxÚoÚpÚcÚkÚv© r0   úN/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/contrib/eddystone.pyÚi2m;   s     


zEddystoneURLField.i2mc                 C   sP   |sd S t ƒ }|D ]4}t|ƒ}t |¡}|d u r<| |¡ q| |¡ qt|ƒS ©N)r!   r   r#   Úgetr&   Úextendr'   )r(   r)   r*   r+   r-   ÚiÚrr0   r0   r1   Úm2iR   s    
zEddystoneURLField.m2ic                 C   s   t |tjƒr| d¡}|S )NÚascii)Ú
isinstanceÚsixÚ	text_typeÚencode)r(   r)   r*   r0   r0   r1   Úany2i`   s    
zEddystoneURLField.any2iN)Ú__name__Ú
__module__Ú__qualname__r2   r8   r>   r0   r0   r0   r1   r   9   s   r   c                   @   s4   e Zd ZdZdZedddƒedddƒgZdd	„ ZdS )
ÚEddystone_Framezœ
    The base Eddystone frame on which all Eddystone messages are built.

    https://github.com/google/eddystone/blob/master/protocol-specification.md
    zEddystone FrameÚtypeNr   Úreservedr   c                 C   s(   t jtƒ ttgd� tƒ tƒ  |  g S )z1Builds a list of EIR messages to wrap this frame.)Z	svc_uuids)r   Zbase_eirr   r   ÚEDDYSTONE_UUIDr   ©r(   r0   r0   r1   Ú	build_eirr   s    ÿýzEddystone_Frame.build_eir)r?   r@   rA   Ú__doc__Únamer   Úfields_descrG   r0   r0   r0   r1   rB   f   s   

þrB   c                   @   s>   e Zd ZdZdZeddƒedddƒeddd	ƒed
ddƒgZdS )ÚEddystone_UIDz„
    An Eddystone type for transmitting a unique identifier.

    https://github.com/google/eddystone/tree/master/eddystone-uid
    zEddystone UIDÚtx_powerr   Ú	namespaceNr   Úinstancer   rD   r   ©r?   r@   rA   rH   rI   r   r   rJ   r0   r0   r0   r1   rK   |   s   


ürK   c                   @   sF   e Zd ZdZdZeddƒeddeƒeddƒgZ	dd	„ Z
ed
d„ ƒZdS )ÚEddystone_URLz†
    An Eddystone type for transmitting a URL (to a web page).

    https://github.com/google/eddystone/tree/master/eddystone-url
    zEddystone URLrL   r   Ú
url_schemeÚurlNc                 C   s   t | j | j S r3   )ÚEDDYSTONE_URL_SCHEMESrQ   rR   rF   r0   r0   r1   Úto_url˜   s    zEddystone_URL.to_urlc                 C   s\   |   d¡} d}t ¡ D ]*\}}|  |¡r|}| t|ƒd… }  qJqtdƒ‚tƒ t|| d� S )z@Creates an Eddystone_Frame with a Eddystone_URL for a given URL.r9   Nz*URLs must start with EDDYSTONE_URL_SCHEMES)rQ   rR   )r=   rS   r$   r%   r"   Ú	ExceptionrB   rP   )rR   Úschemer.   r/   r0   r0   r1   Úfrom_url›   s    

þzEddystone_URL.from_url)r?   r@   rA   rH   rI   r   r
   rS   r   rJ   rT   ÚstaticmethodrW   r0   r0   r0   r1   rP   ‹   s   
ýrP   c                   @   s(   e Zd ZdZdZedddddœƒgZdS )ÚEddystone_TLMz�
    An Eddystone type for transmitting beacon telemetry information.

    https://github.com/google/eddystone/tree/master/eddystone-tlm
    zEddystone TLMÚversionNZunencryptedZ	encrypted)r   r   )r?   r@   rA   rH   rI   r
   rJ   r0   r0   r0   r1   rY   ­   s   þÿrY   c                   @   s<   e Zd ZdZdZeddƒeddddƒed	d
ƒedd
ƒgZd
S )ÚEddystone_TLM_Unencryptedz¤
    A subtype of Eddystone-TLM for transmitting telemetry in unencrypted form.

    https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
    zEddystone TLM (Unencrypted)Zbatt_mvr   Ztemperaturei€ÿÿÿé   r   Zadv_cntNZsec_cnt)	r?   r@   rA   rH   rI   r   r	   r   rJ   r0   r0   r0   r1   r[   ¼   s   ür[   c                   @   s6   e Zd ZdZdZedddƒedddƒedddƒgZdS )	ÚEddystone_TLM_Encryptedzæ
    A subtype of Eddystone-TLM for transmitting telemetry in encrypted form.

    This implementation does not support decrypting this data.

    https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-encrypted.md
    zEddystone TLM (Encrypted)ZetlmNr   Úsaltr   Zmic)r?   r@   rA   rH   rI   r   rJ   r0   r0   r0   r1   r]   Ë   s   


ýr]   c                   @   s*   e Zd ZdZdZeddƒedddƒgZdS )ÚEddystone_EIDzÑ
    An Eddystone type for transmitting encrypted, ephemeral identifiers.

    This implementation does not support decrypting this data.

    https://github.com/google/eddystone/tree/master/eddystone-eid
    zEddystone EIDrL   r   ZeidNr   rO   r0   r0   r0   r1   r_   Û   s
   
þr_   )rZ   r   )rC   r   r   )Zsvc_uuid)"rH   Zscapy.compatr   Zscapy.fieldsr   r   r   r   r   r   r	   r
   Zscapy.layers.bluetoothr   r   r   r   Zscapy.libs.sixZlibsr;   Zscapy.packetr   r   rE   rS   r#   r   rB   rK   rP   rY   r[   r]   r_   r0   r0   r0   r1   Ú<module>   sR   (üò-"