blob: 221c49fb8481a7435afac8c125d42c009fac69c2 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6from spyne.model import ComplexModel
7from spyne.model.complex import XmlAttribute, XmlData
8from spyne.model.primitive import (
9 Boolean,
10 DateTime,
11 Integer,
12 String,
13 UnsignedInteger,
14)
15from spyne.util.odict import odict
16
17# Namespaces
18XSI_NS = 'http://www.w3.org/2001/XMLSchema-instance'
19SOAP_ENV = 'http://schemas.xmlsoap.org/soap/envelope/'
20SOAP_ENC = 'http://schemas.xmlsoap.org/soap/encoding/'
21CWMP_NS = 'urn:dslforum-org:cwmp-1-0'
22
23
24class Tr069ComplexModel(ComplexModel):
25 """ Base class for TR-069 models, to set common attributes. Does not appear
26 in CWMP XSD file. """
27 __namespace__ = CWMP_NS
28
29
30class anySimpleType(Tr069ComplexModel):
31 """ Type used to transfer simple data of various types. Data type is
32 defined in 'type' XML attribute. Data is handled as a string. """
33 _type_info = odict()
34 _type_info["type"] = XmlAttribute(String, ns=XSI_NS)
35 _type_info["Data"] = XmlData(String)
36
37 def __repr__(self):
38 """For types we can't resolve only print the datum"""
39 return self.Data
40
41
42# SOAP Header Elements
43
44
45class ID(Tr069ComplexModel):
46 # Note: for some reason, XmlAttribute/XmlData pairs MUST be ordered, with
47 # XmlAttribute coming first. This appears to be a spyne bug (something to do
48 # with spyne.interface._base.add_class())
49 _type_info = odict()
50 _type_info["mustUnderstand"] = XmlAttribute(String, ns=SOAP_ENV)
51 _type_info["Data"] = XmlData(String)
52
53
54class HoldRequests(Tr069ComplexModel):
55 _type_info = odict()
56 _type_info["mustUnderstand"] = XmlAttribute(String, ns=SOAP_ENV)
57 _type_info["Data"] = XmlData(Boolean)
58
59
60# SOAP Fault Extensions
61
62
63class SetParameterValuesFault(Tr069ComplexModel):
64 _type_info = odict()
65 _type_info["ParameterName"] = String
66 _type_info["FaultCode"] = UnsignedInteger
67 _type_info["FaultString"] = String
68
69
70class Fault(Tr069ComplexModel):
71 _type_info = odict()
72 _type_info["FaultCode"] = UnsignedInteger
73 _type_info["FaultString"] = String
74 _type_info["SetParameterValuesFault"] = SetParameterValuesFault.customize(
75 max_occurs='unbounded',
76 )
77
78
79# Type definitions used in messages
80
81
82class MethodList(Tr069ComplexModel):
83 _type_info = odict()
84 _type_info["string"] = String(max_length=64, max_occurs='unbounded')
85 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
86
87
88class FaultStruct(Tr069ComplexModel):
89 _type_info = odict()
90 _type_info["FaultCode"] = Integer
91 _type_info["FaultString"] = String(max_length=256)
92
93
94class DeviceIdStruct(Tr069ComplexModel):
95 _type_info = odict()
96 _type_info["Manufacturer"] = String(max_length=64)
97 _type_info["OUI"] = String(length=6)
98 _type_info["ProductClass"] = String(max_length=64)
99 _type_info["SerialNumber"] = String(max_length=64)
100
101
102class EventStruct(Tr069ComplexModel):
103 _type_info = odict()
104 _type_info["EventCode"] = String(max_length=64)
105 _type_info["CommandKey"] = String(max_length=32)
106
107
108class EventList(Tr069ComplexModel):
109 _type_info = odict()
110 _type_info["EventStruct"] = EventStruct.customize(max_occurs='unbounded')
111 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
112
113
114class ParameterValueStruct(Tr069ComplexModel):
115 _type_info = odict()
116 _type_info["Name"] = String
117 _type_info["Value"] = anySimpleType
118
119
120class ParameterValueList(Tr069ComplexModel):
121 _type_info = odict()
122 _type_info["ParameterValueStruct"] = ParameterValueStruct.customize(
123 max_occurs='unbounded',
124 )
125 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
126
127
128class ParameterInfoStruct(Tr069ComplexModel):
129 _type_info = odict()
130 _type_info["Name"] = String(max_length=256)
131 _type_info["Writable"] = Boolean
132
133
134class ParameterInfoList(Tr069ComplexModel):
135 _type_info = odict()
136 _type_info["ParameterInfoStruct"] = ParameterInfoStruct.customize(max_occurs='unbounded')
137 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
138
139
140class ParameterNames(Tr069ComplexModel):
141 _type_info = odict()
142 _type_info["string"] = String.customize(max_occurs='unbounded', max_length=256)
143 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
144
145
146class ParameterKeyType(anySimpleType):
147 pass
148
149
150class AccessList(Tr069ComplexModel):
151 _type_info = odict()
152 _type_info["string"] = String.customize(max_occurs='unbounded', max_length=64)
153 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
154
155
156class SetParameterAttributesStruct(Tr069ComplexModel):
157 _type_info = odict()
158 _type_info["Name"] = String(max_length=256)
159 _type_info["NotificationChange"] = Boolean
160 _type_info["Notification"] = Integer
161 _type_info["AccessListChange"] = Boolean
162 _type_info["AccessList"] = AccessList
163
164
165class SetParameterAttributesList(Tr069ComplexModel):
166 _type_info = odict()
167 _type_info["SetParameterAttributesStruct"] = SetParameterAttributesStruct.customize(
168 max_occurs='unbounded',
169 )
170 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
171
172
173class ParameterAttributeStruct(Tr069ComplexModel):
174 _type_info = odict()
175 _type_info["Name"] = String(max_length=256)
176 _type_info["Notification"] = Integer
177 _type_info["AccessList"] = AccessList
178
179
180class ParameterAttributeList(Tr069ComplexModel):
181 _type_info = odict()
182 _type_info["ParameterValueStruct"] = ParameterAttributeStruct.customize(
183 max_occurs='unbounded',
184 )
185 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
186
187
188class CommandKeyType(String.customize(max_length=32)):
189 pass
190
191
192class ObjectNameType(String.customize(max_length=256)):
193 pass
194
195
196# CPE messages
197
198
199class SetParameterValues(Tr069ComplexModel):
200 _type_info = odict()
201 _type_info["ParameterList"] = ParameterValueList
202 _type_info["ParameterKey"] = ParameterKeyType
203
204
205class SetParameterValuesResponse(Tr069ComplexModel):
206 _type_info = odict()
207 _type_info["Status"] = Integer
208
209
210class GetParameterValues(Tr069ComplexModel):
211 _type_info = odict()
212 _type_info["ParameterNames"] = ParameterNames
213
214
215class GetParameterValuesResponse(Tr069ComplexModel):
216 _type_info = odict()
217 _type_info["ParameterList"] = ParameterValueList
218
219
220class GetParameterNames(Tr069ComplexModel):
221 _type_info = odict()
222 _type_info["ParameterPath"] = String.customize(max_length=256)
223 _type_info["NextLevel"] = Boolean
224
225
226class GetParameterNamesResponse(Tr069ComplexModel):
227 _type_info = odict()
228 _type_info["ParameterList"] = ParameterInfoList
229
230
231class SetParameterAttributes(Tr069ComplexModel):
232 _type_info = odict()
233 _type_info["ParameterList"] = SetParameterAttributesList
234
235
236class SetParameterAttributesResponse(Tr069ComplexModel):
237 # Dummy field required because spyne does not allow 'bare' RPC function with
238 # no input parameters. This field is never sent by CPE.
239 _type_info = odict()
240 _type_info["DummyField"] = UnsignedInteger
241
242
243class GetParameterAttributes(Tr069ComplexModel):
244 _type_info = odict()
245 _type_info["ParameterNames"] = ParameterNames
246
247
248class GetParameterAttributesResponse(Tr069ComplexModel):
249 _type_info = odict()
250 _type_info["ParameterList"] = ParameterAttributeList
251
252
253class AddObject(Tr069ComplexModel):
254 _type_info = odict()
255 _type_info["ObjectName"] = ObjectNameType
256 _type_info["ParameterKey"] = ParameterKeyType
257
258
259class AddObjectResponse(Tr069ComplexModel):
260 _type_info = odict()
261 _type_info["InstanceNumber"] = UnsignedInteger
262 _type_info["Status"] = Integer
263
264
265class DeleteObject(Tr069ComplexModel):
266 _type_info = odict()
267 _type_info["ObjectName"] = ObjectNameType
268 _type_info["ParameterKey"] = ParameterKeyType
269
270
271class DeleteObjectResponse(Tr069ComplexModel):
272 _type_info = odict()
273 _type_info["Status"] = Integer
274
275
276class Download(Tr069ComplexModel):
277 _type_info = odict()
278 _type_info["CommandKey"] = CommandKeyType
279 _type_info["FileType"] = String(max_length=64)
280 _type_info["URL"] = String(max_length=256)
281 _type_info["Username"] = String(max_length=256)
282 _type_info["Password"] = String(max_length=256)
283 _type_info["FileSize"] = UnsignedInteger
284 _type_info["TargetFileName"] = String(max_length=256)
285 _type_info["DelaySeconds"] = UnsignedInteger
286 _type_info["SuccessURL"] = String(max_length=256)
287 _type_info["FailureURL"] = String(max_length=256)
288
289
290class DownloadResponse(Tr069ComplexModel):
291 _type_info = odict()
292 _type_info["Status"] = Integer
293 _type_info["StartTime"] = DateTime
294 _type_info["CompleteTime"] = DateTime
295
296
297class Reboot(Tr069ComplexModel):
298 _type_info = odict()
299 _type_info["CommandKey"] = CommandKeyType
300
301
302class RebootResponse(Tr069ComplexModel):
303 # Dummy field required because spyne does not allow 'bare' RPC function with
304 # no input parameters. This field is never sent by CPE.
305 _type_info = odict()
306 _type_info["DummyField"] = UnsignedInteger
307
308
309# ACS messages
310
311
312class Inform(Tr069ComplexModel):
313 _type_info = odict()
314 _type_info["DeviceId"] = DeviceIdStruct
315 _type_info["Event"] = EventList
316 _type_info["MaxEnvelopes"] = UnsignedInteger
317 _type_info["CurrentTime"] = DateTime
318 _type_info["RetryCount"] = UnsignedInteger
319 _type_info["ParameterList"] = ParameterValueList
320
321
322class InformResponse(Tr069ComplexModel):
323 _type_info = odict()
324 _type_info["MaxEnvelopes"] = UnsignedInteger
325
326
327class TransferComplete(Tr069ComplexModel):
328 _type_info = odict()
329 _type_info["CommandKey"] = CommandKeyType
330 _type_info["FaultStruct"] = FaultStruct
331 _type_info["StartTime"] = DateTime
332 _type_info["CompleteTime"] = DateTime
333
334
335class TransferCompleteResponse(Tr069ComplexModel):
336 # Dummy field required because spyne does not allow 'bare' RPC function with
337 # no input parameters. This field is never sent by ACS.
338 _type_info = odict()
339 _type_info["DummyField"] = UnsignedInteger
340
341
342class GetRPCMethods(Tr069ComplexModel):
343 _type_info = odict()
344 _type_info["DummyField"] = UnsignedInteger
345
346
347class GetRPCMethodsResponse(Tr069ComplexModel):
348 _type_info = odict()
349 _type_info["MethodList"] = MethodList
350
351
352#
353# Miscellaneous
354#
355
356class ParameterListUnion(Tr069ComplexModel):
357 """ Union of structures that get instantiated as 'ParameterList' in ACS->CPE
358 messages. This is required because AcsToCpeRequests can only have one
359 parameter named 'ParameterList', so that must also be a union """
360 _type_info = odict()
361
362 # Fields from ParameterValueList
363 _type_info["ParameterValueStruct"] = ParameterValueStruct.customize(
364 max_occurs='unbounded',
365 )
366 _type_info["arrayType"] = XmlAttribute(String, ns=SOAP_ENC)
367
368 # Fields from SetParameterAttributesList
369 _type_info["SetParameterAttributesStruct"] = \
370 SetParameterAttributesStruct.customize(max_occurs='unbounded')
371 # arrayType = XmlAttribute(String, ns=SOAP_ENC) - Already covered above
372
373
374class AcsToCpeRequests(Tr069ComplexModel):
375 """ Union of all ACS->CPE requests. Only fields for one request is populated
376 per message instance """
377 _type_info = odict()
378
379 # Fields for SetParameterValues
380 _type_info["ParameterList"] = ParameterListUnion # See ParameterListUnion for explanation
381 _type_info["ParameterKey"] = ParameterKeyType
382
383 # Fields for GetParameterValues
384 # _type_info["ParameterList"] = ParameterValueList - Already covered above
385
386 # Fields for GetParameterNames
387 _type_info["ParameterPath"] = String.customize(max_length=256)
388 _type_info["NextLevel"] = Boolean
389
390 # Fields for SetParameterAttributes
391 # _type_info["ParameterList"] = SetParameterAttributesList - Already covered above
392
393 # Fields for GetParameterAttributes
394 _type_info["ParameterNames"] = ParameterNames
395
396 # Fields for AddObject
397 _type_info["ObjectName"] = ObjectNameType
398 _type_info["ParameterKey"] = ParameterKeyType
399
400 # Fields for DeleteObject
401 # _type_info["ObjectName"] = ObjectNameType - Already covered above
402 # _type_info["ParameterKey"] = ParameterKeyType - Already covered above
403
404 # Fields for Download
405 _type_info["CommandKey"] = CommandKeyType
406 _type_info["FileType"] = String(max_length=64)
407 _type_info["URL"] = String(max_length=256)
408 _type_info["Username"] = String(max_length=256)
409 _type_info["Password"] = String(max_length=256)
410 _type_info["FileSize"] = UnsignedInteger
411 _type_info["TargetFileName"] = String(max_length=256)
412 _type_info["DelaySeconds"] = UnsignedInteger
413 _type_info["SuccessURL"] = String(max_length=256)
414 _type_info["FailureURL"] = String(max_length=256)
415
416 # Fields for Reboot
417 # _type_info["CommandKey"] = CommandKeyType - Already covered above
418
419
420class DummyInput(Tr069ComplexModel):
421 """ Dummy complex model. Used for 'EmptyHttp' function, because spyne Does
422 not handle 'bare' function with no inputs """
423 _type_info = odict()
424 _type_info["DummyField"] = UnsignedInteger