mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 11:02:54 +00:00
- Move IMSI allocation logic to subscriber_imsi.go - Move authentication key generation (generateAuthKeys, getOperatorVariant, generateOPc) to subscriber_auth.go - Move eSIM profile operations (provisionESIMProfile, deactivateESIMProfile) to subscriber_esim.go - Keep core subscriber CRUD operations and session management in subscriber.go - Remove unused crypto/aes, crypto/rand, encoding/hex, and os imports from main
36 lines
988 B
Go
36 lines
988 B
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
|
)
|
|
|
|
// allocateIMSI allocates a new IMSI for a subscriber
|
|
func (s *SubscriberService) allocateIMSI(ctx context.Context) (models.IMSI, error) {
|
|
// Get current IMSI allocation
|
|
alloc, err := s.db.GetIMSIAllocation(ctx)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to get IMSI allocation: %w", err)
|
|
}
|
|
|
|
// Check if we've reached the maximum
|
|
if alloc.LastIMSI >= alloc.MaxIMSI {
|
|
return "", fmt.Errorf("IMSI range exhausted: max %d reached", alloc.MaxIMSI)
|
|
}
|
|
|
|
// Allocate next IMSI
|
|
nextIMSI := alloc.LastIMSI + 1
|
|
alloc.LastIMSI = nextIMSI
|
|
|
|
// Update allocation state
|
|
if err := s.db.UpdateIMSIAllocation(ctx, alloc); err != nil {
|
|
return "", fmt.Errorf("failed to update IMSI allocation: %w", err)
|
|
}
|
|
|
|
// Format IMSI: MCC (3) + MNC (2-3) + subscriber number
|
|
imsiStr := fmt.Sprintf("%s%010d", s.config.IMSI.Prefix, nextIMSI)
|
|
return models.IMSI(imsiStr), nil
|
|
}
|