1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.location.cts.asn1.supl2.supl_init; 18 19 /* 20 */ 21 22 23 // 24 // 25 import android.location.cts.asn1.base.Asn1Null; 26 import android.location.cts.asn1.base.Asn1Object; 27 import android.location.cts.asn1.base.Asn1Sequence; 28 import android.location.cts.asn1.base.Asn1Tag; 29 import android.location.cts.asn1.base.BitStream; 30 import android.location.cts.asn1.base.BitStreamReader; 31 import android.location.cts.asn1.base.SequenceComponent; 32 import android.location.cts.asn1.supl2.ulp_components.PosMethod; 33 import android.location.cts.asn1.supl2.ulp_components.QoP; 34 import android.location.cts.asn1.supl2.ulp_components.SLPAddress; 35 import android.location.cts.asn1.supl2.ulp_version_2_message_extensions.Ver2_SUPL_INIT_extension; 36 import com.google.common.collect.ImmutableList; 37 import java.util.Collection; 38 import javax.annotation.Nullable; 39 40 41 /** 42 */ 43 public class SUPLINIT extends Asn1Sequence { 44 // 45 46 private static final Asn1Tag TAG_SUPLINIT 47 = Asn1Tag.fromClassAndNumber(-1, -1); 48 49 public SUPLINIT() { 50 super(); 51 } 52 53 @Override 54 @Nullable 55 protected Asn1Tag getTag() { 56 return TAG_SUPLINIT; 57 } 58 59 @Override 60 protected boolean isTagImplicit() { 61 return true; 62 } 63 64 public static Collection<Asn1Tag> getPossibleFirstTags() { 65 if (TAG_SUPLINIT != null) { 66 return ImmutableList.of(TAG_SUPLINIT); 67 } else { 68 return Asn1Sequence.getPossibleFirstTags(); 69 } 70 } 71 72 /** 73 * Creates a new SUPLINIT from encoded stream. 74 */ 75 public static SUPLINIT fromPerUnaligned(byte[] encodedBytes) { 76 SUPLINIT result = new SUPLINIT(); 77 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 78 return result; 79 } 80 81 /** 82 * Creates a new SUPLINIT from encoded stream. 83 */ 84 public static SUPLINIT fromPerAligned(byte[] encodedBytes) { 85 SUPLINIT result = new SUPLINIT(); 86 result.decodePerAligned(new BitStreamReader(encodedBytes)); 87 return result; 88 } 89 90 91 92 @Override protected boolean isExtensible() { 93 return true; 94 } 95 96 @Override public boolean containsExtensionValues() { 97 for (SequenceComponent extensionComponent : getExtensionComponents()) { 98 if (extensionComponent.isExplicitlySet()) return true; 99 } 100 return false; 101 } 102 103 104 private PosMethod posMethod_; 105 public PosMethod getPosMethod() { 106 return posMethod_; 107 } 108 /** 109 * @throws ClassCastException if value is not a PosMethod 110 */ 111 public void setPosMethod(Asn1Object value) { 112 this.posMethod_ = (PosMethod) value; 113 } 114 public PosMethod setPosMethodToNewInstance() { 115 posMethod_ = new PosMethod(); 116 return posMethod_; 117 } 118 119 private Notification notification_; 120 public Notification getNotification() { 121 return notification_; 122 } 123 /** 124 * @throws ClassCastException if value is not a Notification 125 */ 126 public void setNotification(Asn1Object value) { 127 this.notification_ = (Notification) value; 128 } 129 public Notification setNotificationToNewInstance() { 130 notification_ = new Notification(); 131 return notification_; 132 } 133 134 private SLPAddress sLPAddress_; 135 public SLPAddress getSLPAddress() { 136 return sLPAddress_; 137 } 138 /** 139 * @throws ClassCastException if value is not a SLPAddress 140 */ 141 public void setSLPAddress(Asn1Object value) { 142 this.sLPAddress_ = (SLPAddress) value; 143 } 144 public SLPAddress setSLPAddressToNewInstance() { 145 sLPAddress_ = new SLPAddress(); 146 return sLPAddress_; 147 } 148 149 private QoP qoP_; 150 public QoP getQoP() { 151 return qoP_; 152 } 153 /** 154 * @throws ClassCastException if value is not a QoP 155 */ 156 public void setQoP(Asn1Object value) { 157 this.qoP_ = (QoP) value; 158 } 159 public QoP setQoPToNewInstance() { 160 qoP_ = new QoP(); 161 return qoP_; 162 } 163 164 private SLPMode sLPMode_; 165 public SLPMode getSLPMode() { 166 return sLPMode_; 167 } 168 /** 169 * @throws ClassCastException if value is not a SLPMode 170 */ 171 public void setSLPMode(Asn1Object value) { 172 this.sLPMode_ = (SLPMode) value; 173 } 174 public SLPMode setSLPModeToNewInstance() { 175 sLPMode_ = new SLPMode(); 176 return sLPMode_; 177 } 178 179 private MAC mAC_; 180 public MAC getMAC() { 181 return mAC_; 182 } 183 /** 184 * @throws ClassCastException if value is not a MAC 185 */ 186 public void setMAC(Asn1Object value) { 187 this.mAC_ = (MAC) value; 188 } 189 public MAC setMACToNewInstance() { 190 mAC_ = new MAC(); 191 return mAC_; 192 } 193 194 private KeyIdentity keyIdentity_; 195 public KeyIdentity getKeyIdentity() { 196 return keyIdentity_; 197 } 198 /** 199 * @throws ClassCastException if value is not a KeyIdentity 200 */ 201 public void setKeyIdentity(Asn1Object value) { 202 this.keyIdentity_ = (KeyIdentity) value; 203 } 204 public KeyIdentity setKeyIdentityToNewInstance() { 205 keyIdentity_ = new KeyIdentity(); 206 return keyIdentity_; 207 } 208 209 210 211 private Ver2_SUPL_INIT_extension extensionVer2_SUPL_INIT_extension; 212 public Ver2_SUPL_INIT_extension getExtensionVer2_SUPL_INIT_extension() { 213 return extensionVer2_SUPL_INIT_extension; 214 } 215 /** 216 * @throws ClassCastException if value is not a Ver2_SUPL_INIT_extension 217 */ 218 public void setExtensionVer2_SUPL_INIT_extension(Asn1Object value) { 219 extensionVer2_SUPL_INIT_extension = (Ver2_SUPL_INIT_extension) value; 220 } 221 public void setExtensionVer2_SUPL_INIT_extensionToNewInstance() { 222 extensionVer2_SUPL_INIT_extension = new Ver2_SUPL_INIT_extension(); 223 } 224 225 226 227 228 @Override public Iterable<? extends SequenceComponent> getComponents() { 229 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 230 231 builder.add(new SequenceComponent() { 232 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0); 233 234 @Override public boolean isExplicitlySet() { 235 return getPosMethod() != null; 236 } 237 238 @Override public boolean hasDefaultValue() { 239 return false; 240 } 241 242 @Override public boolean isOptional() { 243 return false; 244 } 245 246 @Override public Asn1Object getComponentValue() { 247 return getPosMethod(); 248 } 249 250 @Override public void setToNewInstance() { 251 setPosMethodToNewInstance(); 252 } 253 254 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 255 return tag == null ? PosMethod.getPossibleFirstTags() : ImmutableList.of(tag); 256 } 257 258 @Override 259 public Asn1Tag getTag() { 260 return tag; 261 } 262 263 @Override 264 public boolean isImplicitTagging() { 265 return true; 266 } 267 268 @Override public String toIndentedString(String indent) { 269 return "posMethod : " 270 + getPosMethod().toIndentedString(indent); 271 } 272 }); 273 274 builder.add(new SequenceComponent() { 275 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1); 276 277 @Override public boolean isExplicitlySet() { 278 return getNotification() != null; 279 } 280 281 @Override public boolean hasDefaultValue() { 282 return false; 283 } 284 285 @Override public boolean isOptional() { 286 return true; 287 } 288 289 @Override public Asn1Object getComponentValue() { 290 return getNotification(); 291 } 292 293 @Override public void setToNewInstance() { 294 setNotificationToNewInstance(); 295 } 296 297 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 298 return tag == null ? Notification.getPossibleFirstTags() : ImmutableList.of(tag); 299 } 300 301 @Override 302 public Asn1Tag getTag() { 303 return tag; 304 } 305 306 @Override 307 public boolean isImplicitTagging() { 308 return true; 309 } 310 311 @Override public String toIndentedString(String indent) { 312 return "notification : " 313 + getNotification().toIndentedString(indent); 314 } 315 }); 316 317 builder.add(new SequenceComponent() { 318 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 2); 319 320 @Override public boolean isExplicitlySet() { 321 return getSLPAddress() != null; 322 } 323 324 @Override public boolean hasDefaultValue() { 325 return false; 326 } 327 328 @Override public boolean isOptional() { 329 return true; 330 } 331 332 @Override public Asn1Object getComponentValue() { 333 return getSLPAddress(); 334 } 335 336 @Override public void setToNewInstance() { 337 setSLPAddressToNewInstance(); 338 } 339 340 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 341 return tag == null ? SLPAddress.getPossibleFirstTags() : ImmutableList.of(tag); 342 } 343 344 @Override 345 public Asn1Tag getTag() { 346 return tag; 347 } 348 349 @Override 350 public boolean isImplicitTagging() { 351 return true; 352 } 353 354 @Override public String toIndentedString(String indent) { 355 return "sLPAddress : " 356 + getSLPAddress().toIndentedString(indent); 357 } 358 }); 359 360 builder.add(new SequenceComponent() { 361 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 3); 362 363 @Override public boolean isExplicitlySet() { 364 return getQoP() != null; 365 } 366 367 @Override public boolean hasDefaultValue() { 368 return false; 369 } 370 371 @Override public boolean isOptional() { 372 return true; 373 } 374 375 @Override public Asn1Object getComponentValue() { 376 return getQoP(); 377 } 378 379 @Override public void setToNewInstance() { 380 setQoPToNewInstance(); 381 } 382 383 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 384 return tag == null ? QoP.getPossibleFirstTags() : ImmutableList.of(tag); 385 } 386 387 @Override 388 public Asn1Tag getTag() { 389 return tag; 390 } 391 392 @Override 393 public boolean isImplicitTagging() { 394 return true; 395 } 396 397 @Override public String toIndentedString(String indent) { 398 return "qoP : " 399 + getQoP().toIndentedString(indent); 400 } 401 }); 402 403 builder.add(new SequenceComponent() { 404 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 4); 405 406 @Override public boolean isExplicitlySet() { 407 return getSLPMode() != null; 408 } 409 410 @Override public boolean hasDefaultValue() { 411 return false; 412 } 413 414 @Override public boolean isOptional() { 415 return false; 416 } 417 418 @Override public Asn1Object getComponentValue() { 419 return getSLPMode(); 420 } 421 422 @Override public void setToNewInstance() { 423 setSLPModeToNewInstance(); 424 } 425 426 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 427 return tag == null ? SLPMode.getPossibleFirstTags() : ImmutableList.of(tag); 428 } 429 430 @Override 431 public Asn1Tag getTag() { 432 return tag; 433 } 434 435 @Override 436 public boolean isImplicitTagging() { 437 return true; 438 } 439 440 @Override public String toIndentedString(String indent) { 441 return "sLPMode : " 442 + getSLPMode().toIndentedString(indent); 443 } 444 }); 445 446 builder.add(new SequenceComponent() { 447 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 5); 448 449 @Override public boolean isExplicitlySet() { 450 return getMAC() != null; 451 } 452 453 @Override public boolean hasDefaultValue() { 454 return false; 455 } 456 457 @Override public boolean isOptional() { 458 return true; 459 } 460 461 @Override public Asn1Object getComponentValue() { 462 return getMAC(); 463 } 464 465 @Override public void setToNewInstance() { 466 setMACToNewInstance(); 467 } 468 469 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 470 return tag == null ? MAC.getPossibleFirstTags() : ImmutableList.of(tag); 471 } 472 473 @Override 474 public Asn1Tag getTag() { 475 return tag; 476 } 477 478 @Override 479 public boolean isImplicitTagging() { 480 return true; 481 } 482 483 @Override public String toIndentedString(String indent) { 484 return "mAC : " 485 + getMAC().toIndentedString(indent); 486 } 487 }); 488 489 builder.add(new SequenceComponent() { 490 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 6); 491 492 @Override public boolean isExplicitlySet() { 493 return getKeyIdentity() != null; 494 } 495 496 @Override public boolean hasDefaultValue() { 497 return false; 498 } 499 500 @Override public boolean isOptional() { 501 return true; 502 } 503 504 @Override public Asn1Object getComponentValue() { 505 return getKeyIdentity(); 506 } 507 508 @Override public void setToNewInstance() { 509 setKeyIdentityToNewInstance(); 510 } 511 512 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 513 return tag == null ? KeyIdentity.getPossibleFirstTags() : ImmutableList.of(tag); 514 } 515 516 @Override 517 public Asn1Tag getTag() { 518 return tag; 519 } 520 521 @Override 522 public boolean isImplicitTagging() { 523 return true; 524 } 525 526 @Override public String toIndentedString(String indent) { 527 return "keyIdentity : " 528 + getKeyIdentity().toIndentedString(indent); 529 } 530 }); 531 532 return builder.build(); 533 } 534 535 @Override public Iterable<? extends SequenceComponent> 536 getExtensionComponents() { 537 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 538 539 builder.add(new SequenceComponent() { 540 @Override public boolean isExplicitlySet() { 541 return getExtensionVer2_SUPL_INIT_extension() != null; 542 } 543 544 @Override public boolean hasDefaultValue() { 545 return false; 546 } 547 548 @Override public boolean isOptional() { 549 return true; 550 } 551 552 @Override public Asn1Object getComponentValue() { 553 return getExtensionVer2_SUPL_INIT_extension(); 554 } 555 556 @Override public void setToNewInstance() { 557 setExtensionVer2_SUPL_INIT_extensionToNewInstance(); 558 } 559 560 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 561 throw new UnsupportedOperationException( 562 "BER decoding not supported for extension elements"); 563 } 564 565 @Override 566 public Asn1Tag getTag() { 567 throw new UnsupportedOperationException( 568 "BER is not supported for extension elements"); 569 } 570 571 @Override 572 public boolean isImplicitTagging() { 573 throw new UnsupportedOperationException( 574 "BER is not supported for extension elements"); 575 } 576 577 @Override public String toIndentedString(String indent) { 578 return "ver2_SUPL_INIT_extension : " 579 + getExtensionVer2_SUPL_INIT_extension().toIndentedString(indent); 580 } 581 }); 582 583 return builder.build(); 584 } 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 @Override public Iterable<BitStream> encodePerUnaligned() { 607 return super.encodePerUnaligned(); 608 } 609 610 @Override public Iterable<BitStream> encodePerAligned() { 611 return super.encodePerAligned(); 612 } 613 614 @Override public void decodePerUnaligned(BitStreamReader reader) { 615 super.decodePerUnaligned(reader); 616 } 617 618 @Override public void decodePerAligned(BitStreamReader reader) { 619 super.decodePerAligned(reader); 620 } 621 622 @Override public String toString() { 623 return toIndentedString(""); 624 } 625 626 public String toIndentedString(String indent) { 627 StringBuilder builder = new StringBuilder(); 628 builder.append("SUPLINIT = {\n"); 629 final String internalIndent = indent + " "; 630 for (SequenceComponent component : getComponents()) { 631 if (component.isExplicitlySet()) { 632 builder.append(internalIndent) 633 .append(component.toIndentedString(internalIndent)); 634 } 635 } 636 if (isExtensible()) { 637 builder.append(internalIndent).append("...\n"); 638 for (SequenceComponent component : getExtensionComponents()) { 639 if (component.isExplicitlySet()) { 640 builder.append(internalIndent) 641 .append(component.toIndentedString(internalIndent)); 642 } 643 } 644 } 645 builder.append(indent).append("};\n"); 646 return builder.toString(); 647 } 648 } 649