Skip to content

SIM Card Management

Overview

The SIM Card Management API provides comprehensive capabilities for managing physical SIM cards and eSIMs in mobile networks. This includes profile management, subscription control, and OTA (Over-The-Air) updates.

Implementation

interface SimProfile {
  id: string;
  iccid: string;  // Integrated Circuit Card Identifier
  imsi: string;   // International Mobile Subscriber Identity
  msisdn?: string; // Mobile Station International Subscriber Directory Number
  status: 'ACTIVE' | 'INACTIVE' | 'BLOCKED' | 'EXPIRED';
  type: 'PHYSICAL' | 'ESIM';
  capabilities: {
    voice: boolean;
    sms: boolean;
    data: boolean;
    cat: boolean;  // Card Application Toolkit support
  };
  securityDomain: {
    mcc: string;   // Mobile Country Code
    mnc: string;   // Mobile Network Code
    keySet: number;
    algorithm: 'MILENAGE' | 'COMP128' | 'TUAK';
  };
  subscriptionInfo: {
    activationDate: string;
    expiryDate?: string;
    serviceClass: string;
    ratingGroup: number;
  };
}

interface EsimProfile extends SimProfile {
  eid: string;     // eUICC Identifier
  profileState: 'DOWNLOADED' | 'ENABLED' | 'DISABLED' | 'DELETED';
  smdsAddress: string;  // Subscription Manager Data Preparation address
  profileClass: 'OPERATIONAL' | 'PROVISIONING' | 'TESTING';
  profileNickname?: string;
}

interface SimOperation {
  id: string;
  type: 'ENABLE' | 'DISABLE' | 'DELETE' | 'UPDATE' | 'DOWNLOAD';
  status: 'PENDING' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED';
  timestamp: string;
  targetIccid: string;
  result?: {
    success: boolean;
    errorCode?: string;
    errorMessage?: string;
  };
}

Profile Management

Physical SIM Operations

class PhysicalSimManager {
  async activateProfile(iccid: string): Promise<SimOperation> {
    // Activate SIM profile
    // Send OTA commands
    // Update HLR/HSS records
  }

  async blockProfile(iccid: string, reason: string): Promise<SimOperation> {
    // Block SIM profile
    // Update security status
    // Notify network elements
  }

  async updateSubscription(iccid: string, updates: Partial<SimProfile>): Promise<SimOperation> {
    // Update subscription parameters
    // Send OTA updates
    // Sync with billing system
  }
}

eSIM Operations

class EsimManager {
  async downloadProfile(eid: string, profileData: Partial<EsimProfile>): Promise<SimOperation> {
    // Connect to SM-DP+
    // Initiate profile download
    // Monitor download status
  }

  async enableProfile(eid: string, iccid: string): Promise<SimOperation> {
    // Enable specific profile on eUICC
    // Update network registrations
    // Verify profile status
  }

  async deleteProfile(eid: string, iccid: string): Promise<SimOperation> {
    // Delete profile from eUICC
    // Clean up network registrations
    // Update profile inventory
  }
}

OTA Management

interface OtaCommand {
  id: string;
  type: 'STK' | 'RAM' | 'RFM';
  command: string;
  security: {
    kic: string;  // Key for Integrity and Confidentiality
    kid: string;  // Key for ICV Derivation
    spi: number;  // Security Parameter Indicator
  };
  targetIccid: string;
}

class OtaManager {
  async sendCommand(command: OtaCommand): Promise<SimOperation> {
    // Format OTA command
    // Apply security
    // Send through SMS or CAT_TP
    // Monitor delivery status
  }

  async updateKeys(iccid: string, keySet: number): Promise<SimOperation> {
    // Generate new key set
    // Send key update command
    // Verify key installation
  }
}

Error Handling

enum SimError {
  PROFILE_NOT_FOUND = 'PROFILE_NOT_FOUND',
  INVALID_STATE = 'INVALID_STATE',
  SECURITY_ERROR = 'SECURITY_ERROR',
  NETWORK_ERROR = 'NETWORK_ERROR',
  INCOMPATIBLE_DEVICE = 'INCOMPATIBLE_DEVICE',
  OPERATION_NOT_ALLOWED = 'OPERATION_NOT_ALLOWED'
}

interface SimErrorResponse {
  error: SimError;
  message: string;
  iccid?: string;
  eid?: string;
  operation?: string;
  timestamp: string;
  details?: {
    failureReason: string;
    recommendedAction?: string;
  };
}

Best Practices

  1. Profile Security
  2. Implement secure key storage
  3. Use strong authentication
  4. Regular security audits
  5. Monitor for suspicious activities

  6. eSIM Management

  7. Follow GSMA specifications
  8. Implement proper error handling
  9. Maintain profile state consistency
  10. Regular backup of profile data

  11. OTA Operations

  12. Validate commands before sending
  13. Monitor delivery status
  14. Implement retry mechanisms
  15. Handle partial updates

Monitoring

Key Metrics

  • Profile activation success rate
  • OTA command delivery rate
  • Profile download success rate
  • Operation latency
  • Error rates by type

Performance Indicators

  • Command execution time
  • Profile download time
  • Network registration time
  • Security verification time

Implementation Example

class SimCardService {
  constructor(
    private physicalManager: PhysicalSimManager,
    private esimManager: EsimManager,
    private otaManager: OtaManager
  ) {}

  async provisionNewSubscriber(subscriberData: {
    type: 'PHYSICAL' | 'ESIM',
    msisdn: string,
    serviceClass: string
  }): Promise<SimProfile> {
    try {
      if (subscriberData.type === 'PHYSICAL') {
        // Provision physical SIM
        const profile = await this.physicalManager.activateProfile(/* ... */);
        await this.otaManager.sendCommand(/* initial setup command */);
        return profile;
      } else {
        // Provision eSIM
        const profile = await this.esimManager.downloadProfile(/* ... */);
        await this.esimManager.enableProfile(/* ... */);
        return profile;
      }
    } catch (error) {
      throw this.handleError(error);
    }
  }

  async updateSubscriberServices(iccid: string, services: string[]): Promise<void> {
    // Update subscriber services
    // Send OTA updates if needed
    // Update network elements
  }

  async handleProfileLifecycle(iccid: string, action: 'SUSPEND' | 'RESUME' | 'TERMINATE'): Promise<void> {
    // Handle profile lifecycle events
    // Update network registrations
    // Manage billing status
  }
}

References

  1. 3GPP TS 31.102: Characteristics of the Universal Subscriber Identity Module (USIM) application
  2. GSMA SGP.22: RSP Technical Specification
  3. ETSI TS 102 225: Secured packet structure for UICC based applications
  4. 3GPP TS 23.048: Security mechanisms for (U)SIM application toolkit