<?xml version="1.0" encoding="utf-8"?>
<!-- 
     draft-rfcxml-general-template-standard-00
  
     This template includes examples of the most commonly used features of RFCXML with comments 
     explaining how to customise them. This template can be quickly turned into an I-D by editing 
     the examples provided. Look for [REPLACE], [REPLACE/DELETE], [CHECK] and edit accordingly.
     Note - 'DELETE' means delete the element or attribute, not just the contents.
     
     Documentation is at https://authors.ietf.org/en/templates-and-schemas
-->
<?xml-model href="rfc7991bis.rnc"?><!-- Required for schema validation and schema-aware editing -->
<!-- <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?> -->
<!-- This third-party XSLT can be enabled for direct transformations in XML processors, including most browsers -->


<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
<!ENTITY zwsp   "&#8203;">
<!ENTITY nbhy   "&#8209;">
<!ENTITY wj     "&#8288;">
]>
<!-- If further character entities are required then they should be added to the DOCTYPE above.
     Use of an external entity file is not recommended. -->

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="exp" docName="draft-evan-amateur-radio-ipv6-04" ipr="trust200902" obsoletes="" updates="" submissionType="IETF" xml:lang="en" version="3">
  <!-- [REPLACE] 
       * docName with name of your draft
     [CHECK] 
       * category should be one of std, bcp, info, exp, historic
       * ipr should be one of trust200902, noModificationTrust200902, noDerivativesTrust200902, pre5378Trust200902
       * updates can be an RFC number as NNNN
       * obsoletes can be an RFC number as NNNN 
-->

  <front>
    <title abbrev="Callsign-Derived IPv6 IIDs">A Method for Deriving Stable IPv6 Interface Identifiers from Amateur Radio Callsigns</title>
 
    <seriesInfo name="Internet-Draft" value="draft-evan-amateur-radio-ipv6-04"/>

    <author fullname="Evan Pratten" initials="E." surname="Pratten">
      <!-- [CHECK]
             * initials should not include an initial for the surname
             * role="editor" is optional -->
      <!-- Can have more than one author -->

      <!-- all of the following elements are optional -->
      <address>
        <email>evan@ewpratten.com</email>
        <uri>https://ewpratten.com</uri>
      </address>
    </author>

    <date year="2023"/>
    <!-- On draft subbmission:
         * If only the current year is specified, the current day and month will be used.
         * If the month and year are both specified and are the current ones, the current day will
           be used
         * If the year is not the current one, it is necessary to specify at least a month and day="1" will be used.
    -->

    <area>General</area>
    <workgroup>Internet Engineering Task Force</workgroup>
    <!-- "Internet Engineering Task Force" is fine for individual submissions.  If this element is 
          not present, the default is "Network Working Group", which is used by the RFC Editor as 
          a nod to the history of the RFC Series. -->

    <keyword>ipv6</keyword>
    <keyword>amateur radio</keyword>
    <keyword>packet radio</keyword>
    <keyword>interface id</keyword>
    <keyword>interface identifier</keyword>
    <!-- [REPLACE/DELETE]. Multiple allowed.  Keywords are incorporated into HTML output files for 
         use by search engines. -->

    <abstract>
      <t>
        This document defines a method for generating stable IPv6 Interface Identifiers for amateur packet 
        radio nodes. 
        
        This method is meant to be an alternative to hardware address based Interface Identifier generation 
        such that the benefits of stable addressing may be achieved even on nodes that have unstable, 
        changing, or experimental networking hardware. 

        Instead of a physically-derived address, this method utilizes an amateur radio node's
        government-assigned callsign as the basis for its Interface Identifier.
      </t>
    </abstract>

  </front>

  <middle>

    <section>
      <name>Introduction</name>
      <t>
        This document specifies the steps an amateur packet radio node takes in order to generate a stable 
        and unique IPv6 Interface Identifier (IID) <xref target="RFC2460"/>. The resulting Interface Identifier 
        SHALL be used in conjunction with processes such as (but not limited to) Stateless Address 
        Autoconfiguration (SLAAC) <xref target="RFC4862"/>, DHCPv6 <xref target="RFC3315"/>, or manual configuration 
        to configure IPv6 connectivity on the node.
      </t>
      <t> 
        Callsign-derived Interface Identifier generation requires minimal manual configuration, and when paired with 
        SLAAC may allow a mobile amateur packet radio node to automatically connect to, and communicate with any 
        compliant amateur radio network provided that the node has been configured with a callsign, and is 
        communicating on the correct radio frequency.
      </t>
    </section>

    <section>
      <name>Terminology</name>
      <t>
        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
        "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
        document are to be interpreted as described in <xref target="RFC2119"/>.
      </t>
    </section>

    <section>
      <name>Foreword on Node Identification</name>
      <t>
        Amateur packet radio nodes generally identify themselves with a string of ASCII characters comprised of:
      </t>
      <ol>
        <li>
          The station's government-assigned callsign
        </li>
        <li>
          A dash (-)
        </li>
        <li>
          A number ranging from 0 to 15, inclusive. 
          This will be referred to for the remainder of this document as the node's "ID". 
          Stations that do not use a node ID generally will use a "0" in this place.
        </li>
      </ol>
      <t>
        For example, a node operated under the callsign "VA3ZZA" with the node ID of "5" would identify itself on-air as "VA3ZZA-5". 
      </t>
    </section>

    <section>
      <name>The Algorithm</name>
      <t>
        To determine a 64 bit long <xref target="RFC4291"/> Interface Identifier for an amateur packet radio node in 
        conformance with this specification, the following steps MUST be be taken:
      </t>
      <ol>
        <li>Set the lest significant 4 bits of the Interface Identifier to the node's ID number.</li>
        <li>
          <t>If the callsign is less than or equal to 9 characters in length:</t>
          <ol>
            <li>
              Set the most significant bit of the Interface Identifier (the hash bit) to 0. 
              This indicates that "Direct Encoding" is in use.
            </li>
            <li>
              Using the "Direct Encoding Charset" defined below, pack the UPPERCASE callsign into the middle 59 bits of the 
              Interface Identifier. 
              Callsigns shorter than 9 characters must be right-padded with spaces. This means that the callsign "VA3ZZA" 
              would be encoded as "VA3ZZA   " (3 trailing spaces).
            </li>
          </ol>
        </li>
        <li>
          <t>If the callsign is greater than 9 characters in length:</t>
          <ol>
            <li>
              Set the most significant bit of the Interface Identifier (the hash bit) to 1. 
              This indicates that hashing is in use.
            </li>
            <li>SHA-256 hash the callsign</li>
            <li>Bitwise AND the hash with the 64 bit value 0x7FFFFFFFFFFFFFF0</li>
            <li>Bitwise OR the result to the Interface Identifier</li>
          </ol>
        </li>
      </ol>

      <t>
        Addresses generated using this method will look like the following:
      </t>
      <artwork type="ascii-art" name="box.txt">
      <![CDATA[
AAAA:AAAA:AAAA:AAAA:BCCC:CCCC:CCCC:CCCD
|                 | ||               ||
|                 | ||               |+- Node ID
|                 | |+---------------+-- Callsign or Hash
|                 | +------------------- Hash Bit + Callsign or Hash
+-----------------+--------------------- Prefix
      ]]>
      </artwork>

      <section>
        <name>Direct Encoding Charset</name>
        <t>When directly packing a shorter callsign into the Interface Identifier, the following charset MUST be used:</t>

        <artwork type="ascii-art" name="charset.txt">
<![CDATA[
<space> - 000000  S - 010011
      A - 000001  T - 010100
      B - 000010  U - 010101
      C - 000011  V - 010110
      D - 000100  W - 010111
      E - 000101  X - 011000
      F - 000110  Y - 011001
      G - 000111  Z - 011010
      H - 001000  0 - 011011
      I - 001001  1 - 011100
      J - 001010  2 - 011101
      K - 001011  3 - 011110
      L - 001100  4 - 011111
      M - 001101  5 - 100000
      N - 001110  6 - 100001
      O - 001111  7 - 100010
      P - 010000  8 - 100011
      Q - 010001  9 - 100100
      R - 010010  / - 100101
]]>
        </artwork>

        <t>Each character translates to 6 bits. This allows for more efficient packing of longer callsigns.</t>
      </section>

      <section>
        <name>An Example Implementation</name>
        <sourcecode name="encode.py" type="python3" markers="false">
<![CDATA[
import hashlib

CHARSET = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/"

def encode(callsign: str, node_id: int = 0) -> int:
    
    # The output is a 64-bit integer
    output = 0x0000000000000000
    
    # The right-most 4 bits are the node ID
    output |= node_id & 0x0F
    
    # If the callsign is longer than 9 characters, 
    # perform a hash operation
    if len(callsign) > 9:
        # Set the hash bit
        output |= 0x8000000000000000
        
        # Hash the callsign
        hashed = hashlib.sha256(callsign.encode("ascii")).digest()
    
        # Truncate the hash to 59 bits
        output |= int.from_bytes(hashed, "big") & 0x7FFFFFFFFFFFFFF0

    else:
        # Text-transform and right-pad the callsign 
        # with spaces as needed
        callsign = callsign.upper().ljust(9, " ")
        
        # Fill in the remaining bits via the charset. 
        # The leftmost callsign character will be the 
        # leftmost 6 bits of the output
        for i in range(9):
            six_bits = CHARSET.index(callsign[i]) & 0x3F
            output |= six_bits << (58 - (i * 6))
        
    return output
]]>
        </sourcecode>
      </section>

      <section>
        <name>Using the Interface Identifier</name>
        <t>
          It is recommended to use the generated Interface Identifier with Stateless Address Autoconfiguration
          to automatically determine the node's IPv6 prefix and establish routes to other hosts in a radio network.
        </t>
        <t>
          While SLAAC is the recommended method of configuration, it is not required. Amateur packet radio networks 
          may also use alternate address configuration mechanisms such as DHCPv6 or manual 
          configuration as the participants see fit.
        </t>
      </section>
    
      <section>
        <name>Resolving SLAAC Duplicate Address Detection Conflicts</name>
        <t>
          As a side effect of basing the Interface Identifier on an existing globally unique identifier, 
          DAD <xref target="RFC4862"/> conflicts should be non-existent for permanent callsigns.
        </t>
        <t>
          If a conflict is encountered when using a permanent callsign, the node operator SHOULD contact the operator 
          of the offending station, and/or the appropriate regulatory authority about possible 
          unauthorized use of a callsign.
        </t>
        <t>
          Due to the need for hashing of longer temporary callsigns, a hash collision may occur. 
          If this happens, the node operator SHOULD append a suffix to the node's callsign. 
          Callsign suffixes are arbitrary strings that start with "/" and contain characters A-Z and 0-9.
          For example, adding a suffix of "IETF" to "VA3ZZA" could result in a callsign like "VA3ZZA/IETF".
        </t>
      </section>

      <section>
        <name>Benefits of this method</name>
        <t>
          This method of Interface Identifier generation has the following benefits:
        </t>
        <ul>
          <li>
            Callsigns are uniquely assigned to stations by existing governing bodies. Using them as the basis of address 
            creation will ensure a unique seed or basis for the Interface Identifier.
          </li>
          <li>
            Hashing long callsigns instead of trying to directly encode them allows support for excessively long temporary callsigns.
          </li>
          <li>
            Encoding the station ID in the final nibble of the address allows for up to 16 nodes under the same callsign 
            to be assigned addresses within the same /124. This allows address-based access control logic to operate on 
            a whole callsign (first 60 bits of the interface ID) at once, an ability not possible if the ID was also hashed.
          </li>
          <li>
            Stations operating with permanent callsigns will have the benefit of their callsign being automatically transmitted with 
            every packet (encoded in the source address), in a format that satisfies many governments' station identification requirements.
          </li>
        </ul>
      </section>

      <section>
        <name>Drawbacks of this method</name>
        <ul>
          <li>
            Stations operating with excessively long temporary callsigns will need to separately identify their transmissions as 
            their callsign will not be transmitted by default with each packet.
          </li>
          <li>
            Stations operating with excessively long temporary callsigns may encounter hash collisions with other stations (although extremely unlikely). 
            In the event of this happening, the node operator will be required to perform additional reconfiguration of their node.
          </li>
        </ul>
      </section>
    </section>

    <section>
      <name>Privacy Considerations</name>
      <t>
        The International Telecommunication Union requires all stations operating in the amateur service to 
        self-identify when transmitting. Various countries also impose further requirements such as the 
        interval and method by which stations must identify themselves. 
      </t>
      <t>
        The legal requirement to identify all transmissions nullifies any privacy benefits gained from other 
        privacy-aware addressing methods.
      </t>
    </section>

    <section anchor="IANA">
      <!-- All drafts are required to have an IANA considerations section. See RFC 8126 for a guide.-->
      <name>IANA Considerations</name>
      <t>This memo includes no request to IANA.</t>
    </section>

    <section anchor="Security">
      <!-- All drafts are required to have a security considerations section. See RFC 3552 for a guide. -->
      <name>Security Considerations</name>
      <t>This document should not affect the security of the Internet.</t>
    </section>

    <!-- NOTE: The Acknowledgements and Contributors sections are at the end of this template -->
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>

        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4291.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4862.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2460.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.3315.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>
        <!-- The recommended and simplest way to include a well known reference -->

      </references>

      <!-- <references>
        <name>Informative References</name>


      </references> -->
    </references>

    <!-- <section>
      <name>Appendix 1 [REPLACE/DELETE]</name>
      <t>This becomes an Appendix [REPLACE]</t>
    </section> -->

    <!-- <section anchor="Acknowledgements" numbered="false">
      <name>Acknowledgements</name>
      <t>This template uses extracts from templates written by Pekka Savola, Elwyn Davies and 
        Henrik Levkowetz. [REPLACE]</t>
    </section> -->

    <!-- <section anchor="Contributors" numbered="false">
      <name>Contributors</name>
      <t>Thanks to all of the contributors. [REPLACE]</t>
    </section> -->

  </back>
</rfc>
