
    hO                     @   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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e          Z G d dee          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z G d' d(e          Z G d) d*e          Z eeed+            eeed,+            eeed-            eeed,-            eeed.-            eeed/-            eeee0           d1S )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LowEnergyBeaconHelper)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                        e Zd Zd Zd Zd ZdS )EddystoneURLFieldc                    |dS t                      }d}|t          |          k     rt          ||                   }|dk    rwt                                          D ]G\  }}|                    ||          r,|                    |           |t          |          dz
  z  } nH|                    |           n|                    |           |dz  }|t          |          k     t          |          S )N    r   .   r   )	bytearraylenr   EDDYSTONE_URL_TABLEitems
startswithappendbytes)selfpktxopckvs           [/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/contrib/eddystone.pyi2mzEddystoneURLField.i2m:   s    93KK#a&&jjAaD		ABww/5577    DAq||Aq)) SVVaZ
 HHQKKKFA #a&&jj Qxxr"   c                     |sd S t                      }|D ]X}t          |          }t                              |          }||                    |           C|                    |           Yt          |          S N)r$   r   r&   getr)   extendr*   )r+   r,   r-   r.   r0   irs          r3   m2izEddystoneURLField.m2iQ   sw     	4KK 	 	AAA#''**AyQxxr"   c                 Z    t          |t                    r|                    d          }|S )Nascii)
isinstancestrencode)r+   r,   r-   s      r3   any2izEddystoneURLField.any2i_   s*    a 	"!!Ar"   N)__name__
__module____qualname__r4   r;   rA    r"   r3   r    r    8   sA          .      r"   r    c                   P    e Zd ZdZdZ eddd           eddd          gZ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                     t           j        t                      t          t          g          z  t                      t                      z  | z  gz   S )z1Builds a list of EIR messages to wrap this frame.)	svc_uuids)r   base_eirr   r   EDDYSTONE_UUIDr   r+   s    r3   	build_eirzEddystone_Frame.build_eirq   sX     %-II9E  ! ! ! !II0222T91
 
 	
r"   )rB   rC   rD   __doc__namer   fields_descrO   rE   r"   r3   rG   rG   e   s]         
 Dq!!Q""K

 
 
 
 
r"   rG   c                   x    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   rI   r   rB   rC   rD   rP   rQ   r   r   rR   rE   r"   r3   rT   rT   {   sk         
 D
A&&dB//T1--T1--	KKKr"   rT   c                   z    e Zd ZdZdZ edd           edde           edd          gZ	d Z
e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 URLrU   r   
url_schemeurlNc                 6    t           | j                 | j        z   S r6   )EDDYSTONE_URL_SCHEMESr[   r\   rN   s    r3   to_urlzEddystone_URL.to_url   s    $T_5@@r"   c                 ,   |                      d          } d}t                                          D ]5\  }}|                     |          r|}| t	          |          d         }  n6t          d          t                      t          ||           z  S )z@Creates an Eddystone_Frame with a Eddystone_URL for a given URL.r=   Nz*URLs must start with EDDYSTONE_URL_SCHEMES)r[   r\   )r@   r^   r'   r(   r%   	ExceptionrG   rZ   )r\   schemer1   r2   s       r3   from_urlzEddystone_URL.from_url   s     jj!!)//11 	J 	JDAq~~a   #a&&''l
 HIII  =$ $ $  	r"   )rB   rC   rD   rP   rQ   r   r   r^   r    rR   r_   staticmethodrc   rE   r"   r3   rZ   rZ      s         
 D
A&&lA'<==%&&KA A A   \  r"   rZ   c                   8    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versionNunencrypted	encrypted)r   r   )rB   rC   rD   rP   rQ   r   rR   rE   r"   r3   rf   rf      sI         
 Di(
 (
 	 	KKKr"   rf   c                   v    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)batt_mvr   temperaturei   r   adv_cntNsec_cnt)	rB   rC   rD   rP   rQ   r	   r
   r   rR   rE   r"   r3   rk   rk      sf         
 )D
9a  tR33D!!D!!	KKKr"   rk   c                   b    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)etlmNr   saltr   mic)rB   rC   rD   rP   rQ   r   rR   rE   r"   r3   rr   rr      s\          'Dr**q))a((KKKr"   rr   c                   H    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 EIDrU   r   eidNr   rX   rE   r"   r3   rw   rw      sG          D
A&&a((KKKr"   rw   )rg   r   )rH   r   r   )svc_uuidN)rP   scapy.compatr   scapy.fieldsr   r   r   r   r   r	   r
   r   scapy.layers.bluetoothr   r   r   r   scapy.packetr   r   rM   r^   r&   r    rG   rT   rZ   rf   rk   rr   rw   rE   r"   r3   <module>r~      sI         A A A A A A A A A A A A A A A A A A A A= = = = = = = = = = = = , , , , , , , , 	     $* * * * * * * *Z
 
 
 
 
f3 
 
 
,    F       F   D    F              f        F    M4a @ @ @ @ M2A > > > > O] 3 3 3 3 O] 3 3 3 3 O] 3 3 3 3 O] 3 3 3 3 $o O O O O O Or"   