// @ts-nocheck — fichier copié de cwmp-connector (papaye)
import { Cwmp_1_0, FaultStruct } from './cwmp-1-0.js'
import { Cwmp_1_1, AutonomousTransferComplete as AutonomousTransferComplete_1_1 } from './cwmp-1-1.js'
/**
* CWMP Version 1.2 Protocol Classes
*
* Extends CWMP 1.1 with:
* - ScheduleDownload / ScheduleDownloadResponse
* - CancelTransfer / CancelTransferResponse
* - ChangeDUState / ChangeDUStateResponse
* - DUStateChangeComplete / DUStateChangeCompleteResponse
* - AutonomousDUStateChangeComplete / AutonomousDUStateChangeCompleteResponse
* - TimeWindow structures and Software Module Management structures
*/
export class Cwmp_1_2 extends Cwmp_1_1 {
public '@class' = '.Cwmp_1_2'
// New RPCs
public ScheduleDownload?: ScheduleDownload
public ScheduleDownloadResponse?: ScheduleDownloadResponse
public CancelTransfer?: CancelTransfer
public CancelTransferResponse?: CancelTransferResponse
public ChangeDUState?: ChangeDUState
public ChangeDUStateResponse?: ChangeDUStateResponse
public DUStateChangeComplete?: DUStateChangeComplete
public DUStateChangeCompleteResponse?: DUStateChangeCompleteResponse
public AutonomousDUStateChangeComplete?: AutonomousDUStateChangeComplete
public AutonomousDUStateChangeCompleteResponse?: AutonomousDUStateChangeCompleteResponse
// Override AutonomousTransferComplete to use TransferCompleteFaultStruct
public AutonomousTransferComplete?: AutonomousTransferComplete
constructor(props: any = {}) {
super(props)
this.ScheduleDownload = props.ScheduleDownload ? new ScheduleDownload(props.ScheduleDownload) : undefined
this.ScheduleDownloadResponse = props.ScheduleDownloadResponse ? new ScheduleDownloadResponse(props.ScheduleDownloadResponse) : undefined
this.CancelTransfer = props.CancelTransfer ? new CancelTransfer(props.CancelTransfer) : undefined
this.CancelTransferResponse = props.CancelTransferResponse ? new CancelTransferResponse(props.CancelTransferResponse) : undefined
this.ChangeDUState = props.ChangeDUState ? new ChangeDUState(props.ChangeDUState) : undefined
this.ChangeDUStateResponse = props.ChangeDUStateResponse ? new ChangeDUStateResponse(props.ChangeDUStateResponse) : undefined
this.DUStateChangeComplete = props.DUStateChangeComplete ? new DUStateChangeComplete(props.DUStateChangeComplete) : undefined
this.DUStateChangeCompleteResponse = props.DUStateChangeCompleteResponse ? new DUStateChangeCompleteResponse(props.DUStateChangeCompleteResponse) : undefined
this.AutonomousDUStateChangeComplete = props.AutonomousDUStateChangeComplete ? new AutonomousDUStateChangeComplete(props.AutonomousDUStateChangeComplete) : undefined
this.AutonomousDUStateChangeCompleteResponse = props.AutonomousDUStateChangeCompleteResponse ? new AutonomousDUStateChangeCompleteResponse(props.AutonomousDUStateChangeCompleteResponse) : undefined
// Override from 1.1 when provided
this.AutonomousTransferComplete = props.AutonomousTransferComplete ? new AutonomousTransferComplete(props.AutonomousTransferComplete) : this.AutonomousTransferComplete
}
}
// New/extended Event Codes for 1.2
export enum EventCode_1_2 {
BOOTSTRAP = '0 BOOTSTRAP',
BOOT = '1 BOOT',
PERIODIC = '2 PERIODIC',
SCHEDULED = '3 SCHEDULED',
VALUE_CHANGE = '4 VALUE CHANGE',
KICKED = '5 KICKED',
CONNECTION_REQUEST = '6 CONNECTION REQUEST',
TRANSFER_COMPLETE = '7 TRANSFER COMPLETE',
DIAGNOSTICS_COMPLETE = '8 DIAGNOSTICS COMPLETE',
REQUEST_DOWNLOAD = '9 REQUEST DOWNLOAD',
AUTONOMOUS_TRANSFER_COMPLETE = '10 AUTONOMOUS TRANSFER COMPLETE',
DU_STATE_CHANGE_COMPLETE = '11 DU STATE CHANGE COMPLETE',
AUTONOMOUS_DU_STATE_CHANGE_COMPLETE = '12 AUTONOMOUS DU STATE CHANGE COMPLETE',
REBOOT = 'M Reboot',
SCHEDULE_INFORM = 'M ScheduleInform',
DOWNLOAD = 'M Download',
SCHEDULE_DOWNLOAD = 'M ScheduleDownload',
UPLOAD = 'M Upload',
CHANGE_DU_STATE = 'M ChangeDUState',
X_METHOD = 'M X_',
X_PATTERN = 'X [0-9A-F]{6} .*',
}
// Time window types used by ScheduleDownload
export class TimeWindowStruct {
public '@class' = '.TimeWindowStruct'
public WindowStart: number
public WindowEnd: number
public WindowMode: string
public UserMessage: string
public MaxRetries: number
constructor(props: any = {}) {
this.WindowStart = props.WindowStart ?? 0
this.WindowEnd = props.WindowEnd ?? 0
this.WindowMode = props.WindowMode ?? ''
this.UserMessage = props.UserMessage ?? ''
this.MaxRetries = props.MaxRetries ?? 0
}
}
export class TimeWindowList {
public '@class' = '.TimeWindowList'
public TimeWindowStruct: TimeWindowStruct[] = []
constructor(props: any = {}) {
this.TimeWindowStruct = (props.TimeWindowStruct || []).map((tw: any) => new TimeWindowStruct(tw))
}
}
// ScheduleDownload RPC
export class ScheduleDownload {
public '@class' = '.ScheduleDownload'
public CommandKey: string
public FileType: string
public URL: string
public Username?: string
public Password?: string
public FileSize?: number
public TargetFileName?: string
public TimeWindowList: TimeWindowList
constructor(props: any = {}) {
this.CommandKey = props.CommandKey || ''
this.FileType = props.FileType || ''
this.URL = props.URL || ''
this.Username = props.Username
this.Password = props.Password
this.FileSize = props.FileSize
this.TargetFileName = props.TargetFileName
this.TimeWindowList = new TimeWindowList(props.TimeWindowList || {})
}
getXml() {
const tw = this.TimeWindowList?.TimeWindowStruct || []
const twXml = tw
.map(
(w) => `
${w.WindowStart}
${w.WindowEnd}
${w.WindowMode}
${w.UserMessage}
${w.MaxRetries}
`
)
.join('')
return `
${this.CommandKey}
${this.FileType}
${this.URL}
${this.Username || ''}
${this.Password || ''}
${this.FileSize ?? 0}
${this.TargetFileName || ''}
${twXml}
`
}
}
export class ScheduleDownloadResponse {
public '@class' = '.ScheduleDownloadResponse'
constructor(props: any = {}) {}
getXml() {
return ``
}
}
// CancelTransfer RPC
export class CancelTransfer {
public '@class' = '.CancelTransfer'
public CommandKey: string
constructor(props: any = {}) {
this.CommandKey = props.CommandKey || ''
}
getXml() {
return `
${this.CommandKey}
`
}
}
export class CancelTransferResponse {
public '@class' = '.CancelTransferResponse'
constructor(props: any = {}) {}
getXml() {
return ``
}
}
// Software Module Management types
export type DeploymentUnitState = 'Installed' | 'Uninstalled' | 'Failed'
export class OperationStruct { // abstract base
public '@class' = '.OperationStruct'
}
export class InstallOpStruct extends OperationStruct {
public '@class' = '.InstallOpStruct'
public URL: string
public UUID?: string
public Username?: string
public Password?: string
public ExecutionEnvRef?: string
constructor(props: any = {}) {
super()
this.URL = props.URL || ''
this.UUID = props.UUID
this.Username = props.Username
this.Password = props.Password
this.ExecutionEnvRef = props.ExecutionEnvRef
}
}
export class UpdateOpStruct extends OperationStruct {
public '@class' = '.UpdateOpStruct'
public UUID?: string
public Version?: string
public URL?: string
public Username?: string
public Password?: string
constructor(props: any = {}) {
super()
this.UUID = props.UUID
this.Version = props.Version
this.URL = props.URL
this.Username = props.Username
this.Password = props.Password
}
}
export class UninstallOpStruct extends OperationStruct {
public '@class' = '.UninstallOpStruct'
public UUID: string
public Version?: string
public ExecutionEnvRef?: string
constructor(props: any = {}) {
super()
this.UUID = props.UUID || ''
this.Version = props.Version
this.ExecutionEnvRef = props.ExecutionEnvRef
}
}
export class DeploymentUnitFaultStruct {
public '@class' = '.DeploymentUnitFaultStruct'
public FaultCode: number
public FaultString?: string
constructor(props: any = {}) {
this.FaultCode = props.FaultCode ?? 0
this.FaultString = props.FaultString
}
}
export class OpResultStruct {
public '@class' = '.OpResultStruct'
public UUID: string
public DeploymentUnitRef: string
public Version: string
public CurrentState: DeploymentUnitState
public Resolved: boolean
public ExecutionUnitRefList: string
public StartTime: Date
public CompleteTime: Date
public Fault: DeploymentUnitFaultStruct
constructor(props: any = {}) {
this.UUID = props.UUID || ''
this.DeploymentUnitRef = props.DeploymentUnitRef || ''
this.Version = props.Version || ''
this.CurrentState = props.CurrentState || 'Installed'
this.Resolved = !!props.Resolved
this.ExecutionUnitRefList = props.ExecutionUnitRefList || ''
this.StartTime = props.StartTime ? new Date(props.StartTime) : new Date()
this.CompleteTime = props.CompleteTime ? new Date(props.CompleteTime) : new Date()
this.Fault = new DeploymentUnitFaultStruct(props.Fault || {})
}
}
export class AutonOpResultStruct extends OpResultStruct {
public '@class' = '.AutonOpResultStruct'
public OperationPerformed: string
constructor(props: any = {}) {
super(props)
this.OperationPerformed = props.OperationPerformed || ''
}
}
// ChangeDUState RPC
export class ChangeDUState {
public '@class' = '.ChangeDUState'
public Operations: OperationStruct[] = []
public CommandKey?: string
constructor(props: any = {}) {
this.Operations = (props.Operations || []).map((op: any) => {
const type = op?.['@class'] || op?.type
if (type === 'InstallOpStruct' || op?.URL) return new InstallOpStruct(op)
if (type === 'UpdateOpStruct' || op?.Version || (op?.UUID && !op?.ExecutionEnvRef)) return new UpdateOpStruct(op)
if (type === 'UninstallOpStruct' || op?.ExecutionEnvRef || (op?.UUID && !op?.URL && !op?.Version)) return new UninstallOpStruct(op)
return new OperationStruct()
})
this.CommandKey = props.CommandKey
}
getXml() {
const opsXml = this.Operations
.map((op) => {
if (op instanceof InstallOpStruct) {
return `
${op.URL}
${op.UUID ? `${op.UUID}` : ''}
${op.Username ? `${op.Username}` : ''}
${op.Password ? `${op.Password}` : ''}
${op.ExecutionEnvRef ? `${op.ExecutionEnvRef}` : ''}
`
}
if (op instanceof UpdateOpStruct) {
return `
${op.UUID ? `${op.UUID}` : ''}
${op.Version ? `${op.Version}` : ''}
${op.URL ? `${op.URL}` : ''}
${op.Username ? `${op.Username}` : ''}
${op.Password ? `${op.Password}` : ''}
`
}
if (op instanceof UninstallOpStruct) {
return `
${op.UUID}
${op.Version ? `${op.Version}` : ''}
${op.ExecutionEnvRef ? `${op.ExecutionEnvRef}` : ''}
`
}
return ''
})
.join('')
return `
${opsXml}
${this.CommandKey ? `${this.CommandKey}` : ''}
`
}
}
export class ChangeDUStateResponse {
public '@class' = '.ChangeDUStateResponse'
constructor(props: any = {}) {}
getXml() {
return ``
}
}
// DUStateChangeComplete RPCs
export class DUStateChangeComplete {
public '@class' = '.DUStateChangeComplete'
public Results: OpResultStruct[]
public CommandKey?: string
constructor(props: any = {}) {
this.Results = (props.Results || []).map((r: any) => new OpResultStruct(r))
this.CommandKey = props.CommandKey
}
getXml() {
const resultsXml = this.Results
.map(
(r) => `
${r.UUID}
${r.DeploymentUnitRef}
${r.Version}
${r.CurrentState}
${r.Resolved ? 1 : 0}
${r.ExecutionUnitRefList}
${r.StartTime.toISOString()}
${r.CompleteTime.toISOString()}
${r.Fault.FaultCode}
${r.Fault.FaultString ? `${r.Fault.FaultString}` : ''}
`
)
.join('')
return `
${resultsXml}
${this.CommandKey ? `${this.CommandKey}` : ''}
`
}
}
export class DUStateChangeCompleteResponse {
public '@class' = '.DUStateChangeCompleteResponse'
constructor(props: any = {}) {}
getXml() {
return ``
}
}
export class AutonomousDUStateChangeComplete {
public '@class' = '.AutonomousDUStateChangeComplete'
public Results: AutonOpResultStruct[]
constructor(props: any = {}) {
this.Results = (props.Results || []).map((r: any) => new AutonOpResultStruct(r))
}
getXml() {
const resultsXml = this.Results
.map(
(r) => `
${r.UUID}
${r.DeploymentUnitRef}
${r.Version}
${r.CurrentState}
${r.Resolved ? 1 : 0}
${r.ExecutionUnitRefList}
${r.StartTime.toISOString()}
${r.CompleteTime.toISOString()}
${r.Fault.FaultCode}
${r.Fault.FaultString ? `${r.Fault.FaultString}` : ''}
${r.OperationPerformed}
`
)
.join('')
return `
${resultsXml}
`
}
}
export class AutonomousDUStateChangeCompleteResponse {
public '@class' = '.AutonomousDUStateChangeCompleteResponse'
constructor(props: any = {}) {}
getXml() {
return ``
}
}
// TransferComplete-specific fault struct for 1.2
export class TransferCompleteFaultStruct {
public '@class' = '.TransferCompleteFaultStruct'
public FaultCode: number
public FaultString: string
constructor(props: any = {}) {
this.FaultCode = props.FaultCode ?? 0
this.FaultString = props.FaultString || ''
}
}
// Override of 1.1 AutonomousTransferComplete to use TransferCompleteFaultStruct
export class AutonomousTransferComplete extends AutonomousTransferComplete_1_1 {
public '@class' = '.AutonomousTransferComplete'
public FaultStruct: TransferCompleteFaultStruct
constructor(props: any = {}) {
super(props)
this.FaultStruct = new TransferCompleteFaultStruct(props.FaultStruct || {})
}
getXml() {
return `
${this.AnnounceURL}
${this.TransferURL}
${this.IsDownload ? 1 : 0}
${this.FileType}
${this.FileSize}
${this.TargetFileName}
${this.FaultStruct.FaultCode}
${this.FaultStruct.FaultString}
${this.StartTime.toISOString()}
${this.CompleteTime.toISOString()}
`
}
}