libeuicc

package module
v0.0.0-...-8e174df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: LGPL-2.1 Imports: 16 Imported by: 2

README

Libeuicc Go bindings

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/damonto/libeuicc-go"
	"github.com/damonto/libeuicc-go/driver/pcsc"
)

func main() {
	pcscReader, err := pcsc.New()
	if err != nil {
		fmt.Println(err)
		return
	}
	euicc, err := libeuicc.New(pcscReader, libeuicc.NewDefaultLogger(libeuicc.LogErrorLevel))
	if err != nil {
		fmt.Println(err)
		return
	}
	defer euicc.Close()

	fmt.Println(euicc.GetEid())

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
	err = euicc.DownloadProfile(ctx, &libeuicc.ActivationCode{
		SMDP:       "rsp.septs.app",
		MatchingId: "123413231",
	}, &libeuicc.DownloadOption{
		ProgressBar: func(progress libeuicc.DownloadProgress) {
			// If you want to download, please remove this line.
			if progress == libeuicc.DownloadProgressGetBoundProfile {
				cancel()
			}
			fmt.Println(progress)
		},
		ConfirmationCodeFunc: func() string {
			fmt.Println("Please input confirmation code:")
			return ""
		},
		ConfirmFunc: func(metadata *libeuicc.ProfileMetadata) bool {
			fmt.Println(metadata)
			return false
		},
	})

	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Download profile success")
}

Documentation

Index

Constants

View Source
const (
	ProfileStateEnabled  ProfileState = "enabled"
	ProfileStateDisabled ProfileState = "disabled"

	ProfileIconTypeNone ProfileIconType = "none"
	ProfileIconTypeJPG  ProfileIconType = "jpeg"
	ProfileIconTypePNG  ProfileIconType = "png"

	ProfileClassOperational  ProfilceClass = "operational"
	ProfileClassTest         ProfilceClass = "test"
	ProfileClassProvisioning ProfilceClass = "provisioning"

	DownloadProgressGetChallenge             DownloadProgress = 1
	DownloadProgressInitiateAuthentication   DownloadProgress = 2
	DownloadProgressAuthenticateServer       DownloadProgress = 3
	DownloadProgressAuthenticateClient       DownloadProgress = 4
	DownloadProgressConfirmationCodeRequired DownloadProgress = 5
	DownloadProgressConfirmDownload          DownloadProgress = 6
	DownloadProgressPrepareDownload          DownloadProgress = 7
	DownloadProgressGetBoundProfile          DownloadProgress = 9
	DownloadProgressLoadBoundProfile         DownloadProgress = 10

	NotificationProfileManagementOperationDisable NotificationProfileManagementOperation = "disable"
	NotificationProfileManagementOperationEnable  NotificationProfileManagementOperation = "enable"
	NotificationProfileManagementOperationInstall NotificationProfileManagementOperation = "install"
	NotificationProfileManagementOperationDelete  NotificationProfileManagementOperation = "delete"

	CError   C.int = -1
	CSuccess C.int = 0
)
View Source
const (
	LogDebugLevel slog.Level = slog.LevelDebug
	LogInfoLevel  slog.Level = slog.LevelInfo
	LogWarnLevel  slog.Level = slog.LevelWarn
	LogErrorLevel slog.Level = slog.LevelError
)
View Source
const APDUMTU = 240

Variables

View Source
var (
	ErrDownloadCanceled         = errors.New("download canceled")
	ErrConfirmationCodeRequired = errors.New("confirmation code required")
)
View Source
var (
	ErrEuiccInitFailed = errors.New("euicc_init failed")
	ErrNotEnoughMemory = errors.New("not enough memory")
)

Functions

func GoStrings

func GoStrings(cStrings **C.char) []string

Types

type APDU

type APDU interface {
	// Connect connects to the APDU interface. This is called before any other APDU operation.
	Connect() error
	// Disconnect disconnects from the APDU interface. This is called after the command execution is completed.
	Disconnect() error
	// Transmit sends the command to the APDU interface and returns the response.
	Transmit(command []byte) ([]byte, error)
	// OpenLogicalChannel opens a logical channel with the given AID and returns the channel number.
	OpenLogicalChannel(aid []byte) (int, error)
	// CloseLogicalChannel closes the logical channel with the given channel number.
	CloseLogicalChannel(channel int) error
}

type ActivationCode

type ActivationCode struct {
	// SMDP is the address of the SM-DP+ server.
	SMDP string
	// MatchingId is the matching ID. (Optional)
	MatchingId string
	// ConfirmationCode is the confirmation code. (Optional)
	ConfirmationCode string
	// IMEI is the IMEI of the device. (Optional)
	IMEI string
}

type ConfiguredAddresses

type ConfiguredAddresses struct {
	DefaultDPAddress string
	RootDSAddress    string
}

type DefaultLogger

type DefaultLogger struct {
	// contains filtered or unexported fields
}

func (*DefaultLogger) Debug

func (l *DefaultLogger) Debug(format string, args ...any)

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(format string, err error, args ...any)

func (*DefaultLogger) Info

func (l *DefaultLogger) Info(format string, args ...any)

func (*DefaultLogger) Warn

func (l *DefaultLogger) Warn(format string, args ...any)

type DownloadOption

type DownloadOption struct {
	// ProgressBar is the callback function to handle the download progress.
	ProgressBar func(progress DownloadProgress)

	// ConfirmFunc is the callback function to confirm the download.
	// If it is not set, the download will be confirmed automatically.
	// If the function returns false, the download will be canceled.
	ConfirmFunc func(metadata *ProfileMetadata) bool

	// ConfirmationCodeFunc is the callback function to get the confirmation code.
	// If you do not set it and a confirmation code is required, the download will be canceled.
	ConfirmationCodeFunc func() string
}

type DownloadProgress

type DownloadProgress int

type EuiccInfo2

type EuiccInfo2 struct {
	SasAccreditationNumber string
	ProfileVersion         string
	FirmwareVersion        string
	ExtCardResource        ExtCardResource
	CiPKIdForSigning       []string
}

type ExtCardResource

type ExtCardResource struct {
	FreeNonVolatileMemory int
	FreeVolatileMemory    int
}

type Libeuicc

type Libeuicc struct {
	// contains filtered or unexported fields
}

func New

func New(apdu APDU, customLogger Logger) (*Libeuicc, error)

New creates a new Libeuicc instance.

func (*Libeuicc) Close

func (e *Libeuicc) Close()

Close closes the Libeuicc instance. It must be called when the instance is no longer needed.

func (*Libeuicc) DeleteNotification

func (e *Libeuicc) DeleteNotification(seqNumber int) error

DeleteNotification deletes the notification with the given sequence number.

func (*Libeuicc) DeleteProfile

func (e *Libeuicc) DeleteProfile(iccid string) error

DeleteProfile deletes the profile with the given ICCID. Once a profile is deleted, it cannot be recovered, and you must send the delete notification via `ProcessNotification` to the SM-DP+ server. otherwise, you may can't install it on another one of your devices.

func (*Libeuicc) DisableProfile

func (e *Libeuicc) DisableProfile(iccid string, refresh bool) error

DisableProfile disables the profile with the given ICCID. It's recommanded to send a disable notification via `ProcessNotification` to the SM-DP+ server. Some eUICC chips may require a refresh flag. See the GSMA SGP.22 v2.2.2 for more information.

func (*Libeuicc) Discover

func (e *Libeuicc) Discover(smds string, imei string) ([]*RspServerAddress, error)

Discover discovers the RSP server address. If SM-DS is empty, it will try to discover the RSP server address from the default SM-DS servers.

func (*Libeuicc) DownloadProfile

func (e *Libeuicc) DownloadProfile(ctx context.Context, activationCode *ActivationCode, downloadOption *DownloadOption) error

DownloadProfile downloads the eSIM profile from the SM-DP+ server.

func (*Libeuicc) EnableProfile

func (e *Libeuicc) EnableProfile(iccid string, refresh bool) error

EnableProfile enables the profile with the given ICCID. It's recommended to send an enable notification via `ProcessNotification` to the SM-DP+ server. Some eUICC chips may require a refresh flag. See the GSMA SGP.22 v2.2.2 for more information.

func (*Libeuicc) GetConfiguredAddresses

func (e *Libeuicc) GetConfiguredAddresses() (*ConfiguredAddresses, error)

GetConfiguredAddresses returns the configured addresses of the eUICC. It includes the default SM-DP+ address and root SM-DS address.

func (*Libeuicc) GetEid

func (e *Libeuicc) GetEid() (string, error)

GetEid returns the EID of the eUICC.

func (*Libeuicc) GetEuiccInfo2

func (e *Libeuicc) GetEuiccInfo2() (*EuiccInfo2, error)

GetEuiccInfo2 returns the eUICC information. It includes the SAS accreditation number, profile version, firmware version, card resource, and CI PKI ID list for signing.

func (*Libeuicc) GetNotifications

func (e *Libeuicc) GetNotifications() ([]*Notification, error)

GetNotifications returns the list of notifications.

func (*Libeuicc) GetProfiles

func (e *Libeuicc) GetProfiles() ([]*Profile, error)

GetProfiles returns the installed profiles.

func (*Libeuicc) ProcessNotification

func (e *Libeuicc) ProcessNotification(seqNumber int, remove bool) error

ProcessNotification processes the notification with the given sequence number. If remove is true, the notification will be removed from the eUICC.

func (*Libeuicc) Reset

func (e *Libeuicc) Reset() error

Reset resets the eUICC memory. Attention: This operation will erase all the data on the eUICC.

func (*Libeuicc) SetDefaultSMDPAddress

func (e *Libeuicc) SetDefaultSMDPAddress(address string) error

SetDefaultSMDPAddress sets the default SM-DP+ address of the eUICC.

func (*Libeuicc) SetNickname

func (e *Libeuicc) SetNickname(iccid, nickname string) error

SetNickname sets the nickname of the profile with the given ICCID. The nickname cannot be longer than 64 UTF-8 bytes.

type Logger

type Logger interface {
	Debug(format string, args ...any)
	Info(format string, args ...any)
	Warn(format string, args ...any)
	Error(format string, err error, args ...any)
}

func NewDefaultLogger

func NewDefaultLogger(level slog.Level) Logger

type Notification

type Notification struct {
	SeqNumber                  int
	ProfileManagementOperation NotificationProfileManagementOperation
	NotificationAddress        string
	Iccid                      string
}

type NotificationProfileManagementOperation

type NotificationProfileManagementOperation string

type ProfilceClass

type ProfilceClass string

type Profile

type Profile struct {
	Iccid        string
	IsdpAid      string
	State        ProfileState
	Nickname     string
	ProviderName string
	ProfileName  string
	IconType     ProfileIconType
	Icon         string
	Class        ProfilceClass
}

type ProfileIconType

type ProfileIconType string

type ProfileMetadata

type ProfileMetadata struct {
	Iccid        string
	Nickname     string
	ProviderName string
	ProfileName  string
	IconType     ProfileIconType
	Icon         string
}

type ProfileState

type ProfileState string

type RspServerAddress

type RspServerAddress struct {
	// RspServerAddress is the provisioned RSP server address. You can use this address to download the eSIM profile.
	RspServerAddress string
}

Directories

Path Synopsis
driver
pcsc Module
qmi Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL