private byte[] buildAnrData(int length, int adnRecIndex, String anr) {
   byte[] data = new byte[length];
   for (int i = 0; i < length; i++) {
     data[i] = (byte) 0xff;
   }
   if (TextUtils.isEmpty(anr)) {
     Log.w(LOG_TAG, "[buildAnrData] Empty anr record");
     return data; // return the empty record (for delete)
   }
   data[ANR_DESCRIPTION_ID] = (byte) (0x0);
   byte[] byteAnr = PhoneNumberUtils.numberToCalledPartyBCD(anr);
   int maxlength = ANR_ADDITIONAL_NUMBER_END_ID - ANR_ADDITIONAL_NUMBER_START_ID + 1;
   if (byteAnr.length > maxlength) {
     System.arraycopy(byteAnr, 0, data, ANR_TON_NPI_ID, maxlength);
     data[ANR_BCD_NUMBER_LENGTH] = (byte) (maxlength);
   } else {
     System.arraycopy(byteAnr, 0, data, ANR_TON_NPI_ID, byteAnr.length);
     data[ANR_BCD_NUMBER_LENGTH] = (byte) (byteAnr.length);
   }
   data[ANR_CAPABILITY_ID] = (byte) 0xFF;
   data[ANR_EXTENSION_ID] = (byte) 0xFF;
   if (length == 17) {
     // TODO: should update the SFI at the same time???
     int pbrIndex = getPbrIndexBy(adnRecIndex);
     int recordIndex = adnRecIndex - getInitIndexBy(pbrIndex);
     data[ANR_ADN_RECORD_IDENTIFIER_ID] = (byte) (recordIndex + 1);
   }
   Log.w(LOG_TAG, " buildAnrData: data is" + IccUtils.bytesToHexString(data));
   return data;
 }
Esempio n. 2
0
  /**
   * Build adn hex byte array based on record size The format of byte array is defined in 51.011
   * 10.5.1
   *
   * @param recordSize is the size X of EF record
   * @return hex byte[recordSize] to be written to EF record return null for wrong format of dialing
   *     number or tag
   */
  public byte[] buildAdnString(int recordSize) {
    byte[] bcdNumber;
    byte[] byteTag;
    byte[] adnString;
    int footerOffset = recordSize - FOOTER_SIZE_BYTES;

    // create an empty record
    adnString = new byte[recordSize];
    for (int i = 0; i < recordSize; i++) {
      adnString[i] = (byte) 0xFF;
    }

    if (TextUtils.isEmpty(number)) {
      Log.w(LOG_TAG, "[buildAdnString] Empty dialing number");
      return adnString; // return the empty record (for delete)
    } else if (number.length() > (ADN_DIALING_NUMBER_END - ADN_DIALING_NUMBER_START + 1) * 2) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of dialing number is 20");
      return null;
    } else if (alphaTag != null && alphaTag.length() > footerOffset) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of tag is " + footerOffset);
      return null;
    } else {
      bcdNumber = PhoneNumberUtils.numberToCalledPartyBCD(number);

      System.arraycopy(bcdNumber, 0, adnString, footerOffset + ADN_TON_AND_NPI, bcdNumber.length);

      adnString[footerOffset + ADN_BCD_NUMBER_LENGTH] = (byte) (bcdNumber.length);
      adnString[footerOffset + ADN_CAPABILITY_ID] = (byte) 0xFF; // Capability Id
      adnString[footerOffset + ADN_EXTENSION_ID] = (byte) 0xFF; // Extension Record Id

      if (TextUtils.isEmpty(alphaTag)) {
        Log.d(LOG_TAG, " alphaTag is " + alphaTag);
      } else if (GsmAlphabet.isStringToGsm8Bit(alphaTag)) {
        byteTag = GsmAlphabet.stringToGsm8BitPacked(alphaTag);
        if (byteTag.length > footerOffset) {
          System.arraycopy(byteTag, 0, adnString, 0, footerOffset);
        } else {
          System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
        }
        Log.w(LOG_TAG, "use stringToGsm8BitPacked to encode");
      } else {
        adnString[0] = (byte) 0x80;
        try {
          byteTag = alphaTag.getBytes("UTF-16BE");
          if ((byteTag.length + 1) > footerOffset) {
            System.arraycopy(byteTag, 0, adnString, 1, footerOffset - 1);
          } else {
            System.arraycopy(byteTag, 0, adnString, 1, byteTag.length);
          }
          Log.w(LOG_TAG, "use UTF-16BE to encode");
        } catch (UnsupportedEncodingException e) {
          Log.w(LOG_TAG, "encoding alphaTag failed : UnsupportedEncodingException");
        }
      }

      return adnString;
    }
  }
Esempio n. 3
0
  /**
   * Build adn hex byte array based on record size The format of byte array is defined in 51.011
   * 10.5.1
   *
   * @param recordSize is the size X of EF record
   * @return hex byte[recordSize] to be written to EF record return null for wrong format of dialing
   *     number or tag
   */
  @DSSource({DSSourceKind.NETWORK})
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:59:17.039 -0500",
      hash_original_method = "43E5A3A3017D389C996FCD504E7A9103",
      hash_generated_method = "E3F599972D04B8E5D7F86AB1411559E9")
  public byte[] buildAdnString(int recordSize) {
    byte[] bcdNumber;
    byte[] byteTag;
    byte[] adnString;
    int footerOffset = recordSize - FOOTER_SIZE_BYTES;

    // create an empty record
    adnString = new byte[recordSize];
    for (int i = 0; i < recordSize; i++) {
      adnString[i] = (byte) 0xFF;
    }

    if (TextUtils.isEmpty(number)) {
      Log.w(LOG_TAG, "[buildAdnString] Empty dialing number");
      return adnString; // return the empty record (for delete)
    } else if (number.length() > (ADN_DIALING_NUMBER_END - ADN_DIALING_NUMBER_START + 1) * 2) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of dialing number is 20");
      return null;
    } else if (alphaTag != null && alphaTag.length() > footerOffset) {
      Log.w(LOG_TAG, "[buildAdnString] Max length of tag is " + footerOffset);
      return null;
    } else {
      bcdNumber = PhoneNumberUtils.numberToCalledPartyBCD(number);

      System.arraycopy(bcdNumber, 0, adnString, footerOffset + ADN_TON_AND_NPI, bcdNumber.length);

      adnString[footerOffset + ADN_BCD_NUMBER_LENGTH] = (byte) (bcdNumber.length);
      adnString[footerOffset + ADN_CAPABILITY_ID] = (byte) 0xFF; // Capability Id
      adnString[footerOffset + ADN_EXTENSION_ID] = (byte) 0xFF; // Extension Record Id

      if (!TextUtils.isEmpty(alphaTag)) {
        byteTag = GsmAlphabet.stringToGsm8BitPacked(alphaTag);
        System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
      }

      return adnString;
    }
  }