Source for file docsis_config.php

Documentation is available at docsis_config.php

  1. <?php
  2. /**
  3. * DOCSIS Config Writer
  4. *
  5. * @author David Eder <david@eder.us>
  6. * @copyright 2004 David Eder
  7. * @package docsis_config
  8. * @version .1
  9. */
  10.  
  11. error_reporting(E_ALL);
  12.  
  13. /**
  14. */
  15. require_once('docsis_common.php');
  16. require_once('docsis_class_of_service.php');
  17. require_once('docsis_classifier.php');
  18. require_once('docsis_phs.php');
  19. require_once('docsis_capabilities.php');
  20. require_once('docsis_flow.php');
  21. require_once('docsis_telephone.php');
  22. require_once('docsis_snmp_v3.php');
  23. require_once('docsis_baseline_privacy.php');
  24. require_once('docsis_vendor.php');
  25.  
  26. define('DOCSIS_DOWNSTREAM_FREQUENCY', 1);
  27. define('DOCSIS_UPSTREAM_CHANNEL_ID', 2);
  28. define('DOCSIS_NETWORK_ACCESS', 3);
  29. define('DOCSIS_CM_MIC', 6);
  30. define('DOCSIS_CMTS_MIC', 7);
  31. define('DOCSIS_SOFTWARE_UPGRADE_FILENAME', 9);
  32. define('DOCSIS_SNMP_WRITE_CONTROL', 10);
  33. define('DOCSIS_SNMP_MIB_OBJECT', 11);
  34. define('DOCSIS_MODEM_ADDRESS', 12);
  35. define('DOCSIS_SERVICES_NOT_AVAILABLE', 13);
  36. define('DOCSIS_CPE_ETHERNET', 14);
  37. define('DOCSIS_MAX_CPES', 18);
  38. define('DOCSIS_TFTP_TIMESTAMP', 19);
  39. define('DOCSIS_TFTP_ADDRESS', 20);
  40. define('DOCSIS_SOFTWARE_TFTP_ADDRESS', 21);
  41. define('DOCSIS_HMAC_DIGEST', 27);
  42. define('DOCSIS_MAX_CLASSIFIERS', 28);
  43. define('DOCSIS_PRIVACY_ENABLE', 29);
  44. define('DOCSIS_AUTHORIZATION_BLOCK', 30);
  45. define('DOCSIS_KEY_SEQUENCE', 31);
  46. define('DOCSIS_MFG_CVC_DATA', 32);
  47. define('DOCSIS_COS_CVC_DATA', 33);
  48. define('DOCSIS_MTA_CONFIG_DELIMITER', 254);
  49. define('DOCSIS_SUBSCRIBER_MANAGEMENT', 35);
  50. define('DOCSIS_SUBSCRIBER_MANAGEMENT_CPE_IP', 36);
  51. define('DOCSIS_SUBSCRIBER_MANAGEMENT_FILTER', 37);
  52. define('DOCSIS_COSIGNER_CODE_CERTIFICATE', 33);
  53. define('DOCSIS_2_ENABLE', 39);
  54.  
  55. /**
  56. * DOCSIS Config Writer
  57. *
  58. * @package docsis_config
  59. */
  60. class docsis_config extends docsis_encoder_complex
  61. {
  62. /**
  63. * Constructor
  64. *
  65. * @param int $code docsis code
  66. * @param array predefined values
  67. */
  68. function docsis_config($code=0, $value=array())
  69. {
  70. parent::docsis_encoder_complex($code, $value);
  71. $this->set_network_access(1);
  72. }
  73.  
  74. /**
  75. * Set Downstream Frequency Configuration
  76. *
  77. * The receive frequency to be used by the CM. It is an override for the channel selected during scanning.
  78. *
  79. * @param int $value in Hz must be a multiple of 62500.
  80. */
  81. function set_downstream_frequency($value)
  82. {
  83. if($value < 88000000 || $value > 860000000) trigger_error('Downstream Frequency must be 88000000 to 860000000', E_USER_WARNING);
  84. if($value % 62500 != 0) trigger_error('Downstream Frequency must be a multiple of 62500', E_USER_WARNING);
  85. $this->value[DOCSIS_DOWNSTREAM_FREQUENCY] = new docsis_encoder_uint(DOCSIS_DOWNSTREAM_FREQUENCY, $value);
  86. }
  87.  
  88. /**
  89. * Set Upstream Channel ID
  90. *
  91. * The upstream channel ID which the CM must use. The CM must listen on the defined downstream channel until an upstream channel description
  92. * message with this ID is found. It is an override for the channel selected during initialization.
  93. *
  94. * @param int $value channel ID
  95. */
  96. function set_upstream_channel_id($value)
  97. {
  98. $this->value[DOCSIS_UPSTREAM_CHANNEL_ID] = new docsis_encoder_uchar(DOCSIS_UPSTREAM_CHANNEL_ID, $value);
  99. }
  100.  
  101. /**
  102. * Set Network Access
  103. *
  104. * If $value is 1, CPE attached to this CM are allowed to access the network, based on CM provisioning. If the value is 0, the CM must not forward
  105. * traffic from attached CPE to the RF MAC network, but must continue to accept and generate traffic from the CM itself. The value of this field
  106. * does not affect CMTS service flow operation and does not affect CMTS data forwarding operation.
  107. *
  108. * Note: The intent of "NACO=0" is that the CM does not forward traffic from any attached CPE onto the cable network. (A CPE is any client device
  109. * attached to the CM, regardless of how the attachment is implemented.) However, with "NACO=0", management traffic to the CM is not restricted.
  110. * Specifically, with NACO off, the CM remains manageable, including sending/receiving management traffice such as (but not limited to):
  111. *
  112. * <ul>
  113. * <li>ARP: allow the modem to resolve IP addresses, so it can respond to queries or send traps.</li>
  114. * <li>DHCP: allow the modem to renew its IP address lease.</li>
  115. * <li>ICPM: allow network troubleshooting for tools such as "ping" and "traceroute."</li>
  116. * <li>ToD: allow the modem to continue to synchronize its clock after boot.</li>
  117. * <li>TFTP: allow the modem to download either a new configuration file or a new software image.</li>
  118. * <li>SYSLOG: allow the modem to report network events.</li>
  119. * <li>SNMP: allow management activity.</li>
  120. * </ul>
  121. *
  122. * In DOCSIS v1.1, with NACO off, the primary upstream and primary downstream service flows of the CM remain operational only for management
  123. * traffic to and from the CM. With respect to DOCSIS v1.1 provisioning, a CMTS should ignore the NACO value and allocate any service flows
  124. * that have been authorized by the provisioning server.
  125. *
  126. * @param boolean $value
  127. */
  128. function set_network_access($value)
  129. {
  130. if($value < 0 || $value > 1) trigger_error('Network Access must be 0 or 1', E_USER_WARNING);
  131. $this->value[DOCSIS_NETWORK_ACCESS] = new docsis_encoder_uchar(DOCSIS_NETWORK_ACCESS, $value);
  132. }
  133.  
  134. /**
  135. * Add a Class of Service
  136. *
  137. * @param docis_class_of_service $value
  138. */
  139. function add_class_of_service($value)
  140. {
  141. // todo: must be a docis_class_of_service
  142. $this->value[DOCSIS_CLASS_OF_SERVICE][] = $value;
  143. }
  144.  
  145. /**
  146. * Maximum Number of CPEs
  147. *
  148. * The maximum number of CPEs that can be granted access through a CM during a CM epoch. The CM epoch is the time between startup and hard reset
  149. * of the modem. The maximum number of CPEs must be enforced by the CM.
  150. *
  151. * Note: This parameter should not be confused with the number of CPE addresses a CM may learn. A modem may learn Ethernet MAC addresses up to
  152. * its maximum number of CPE addresses. The maximum number of CPEs that are granted access through the modemis governed by this configuration
  153. * setting.
  154. *
  155. * The non-existance, or the value 0, must be intrepreted as the default value of 1.
  156. */
  157. function set_max_cpes($value)
  158. {
  159. if($value < 1 || $value > 254) trigger_error('Max CPEs must be 1 to 254', E_USER_WARNING);
  160. $this->value[DOCSIS_MAX_CPES] = new docsis_encoder_uchar(DOCSIS_MAX_CPES, $value);
  161. }
  162.  
  163. /**
  164. * Set TFTP Server Timestamp
  165. *
  166. * The sending time of the configuration file in seconds. The purpose of this parameter is to prevent replay attacks with old configuation files.
  167. *
  168. * @param int $value in seconds
  169. */
  170. function set_tftp_timestamp($value)
  171. {
  172. $this->value[DOCSIS_TFTP_TIMESTAMP] = new docsis_encoder_uint(DOCSIS_TFTP_TIMESTAMP, $value);
  173. }
  174.  
  175. /**
  176. * Set TFTP Server Provisioned Modem Address
  177. *
  178. * The IP address of the modem requesting the configuration. The purpose of this parameter is to prevent IP spoofing during registration.
  179. *
  180. * @param string $value ip address of modem
  181. */
  182. function set_tftp_address($value)
  183. {
  184. $this->value[DOCSIS_TFTP_ADDRESS] = new docsis_encoder_ip(DOCSIS_TFTP_ADDRESS, $value);
  185. }
  186.  
  187. /**
  188. * Set Upstream Packet Classifier
  189. *
  190. * @param docsis_packet_classifier $value
  191. */
  192. function set_upstream_packet_classifier($value)
  193. {
  194. // todo: must be a docsis_packet_classifier
  195. $this->value[DOCSIS_UPSTREAM_PACKET_CLASSIFIER] = $value;
  196. }
  197.  
  198. /**
  199. * Set Downstream Packet Classifier
  200. *
  201. * @param docsis_packet_classifier $value
  202. */
  203. function set_downstream_packet_classifier($value)
  204. {
  205. // todo: must be a docsis_packet_classifier
  206. $this->value[DOCSIS_DOWNSTREAM_PACKET_CLASSIFIER] = $value;
  207. }
  208.  
  209. /**
  210. * Set Upstream Service Flow
  211. *
  212. * @param docsis_flow_up $value
  213. */
  214. function set_upstream_flow($value)
  215. {
  216. // todo: must be a docsis_flow_up
  217. $this->value[DOCSIS_FLOW_UP] = $value;
  218. }
  219.  
  220. /**
  221. * Set Downstream Service Flow
  222. *
  223. * @param docsis_flow_down $value
  224. */
  225. function set_downstream_flow($value)
  226. {
  227. // todo: must be a docsis_flow_down
  228. $this->value[DOCSIS_FLOW_DOWN] = $value;
  229. }
  230.  
  231. /**
  232. * Set Payload Header Suppression
  233. *
  234. * @param docsis_payload_header_suppression $value
  235. */
  236. function set_payload_header_suppression($value)
  237. {
  238. // todo: must be a docsis_payload_header_suppression
  239. $this->value[DOCSIS_PAYLOAD_HEADER_SUPPRESSION] = $value;
  240. }
  241.  
  242. /**
  243. * Set Maximum Number of Classifiers
  244. *
  245. * This is the maximum number of Classifiers associated with admitted or active upstream Service Flows that the CM is allowed to have. Both
  246. * active and inactive Classifiers are included in this count.
  247. *
  248. * This is useful when using deferred activation of provisioned resources. The number of provisioned Service Flows may be high and each
  249. * Service Flow might support multiple Classifiers. Provisioning represents the set of Service Flows the CM can choose between. The CMTS
  250. * can control the QoS resources committed to the CM by limiting the number of Service Flows that are admitted. However, it may still be
  251. * desirable to limit the number of Classifiers associated with the committed QoS resources. This parameter provides that limit.
  252. *
  253. * @param int $value
  254. */
  255. function set_max_classifiers($value)
  256. {
  257. $this->value[DOCSIS_MAX_CLASSIFIERS] = new docsis_encoder_ushort(DOCSIS_MAX_CLASSIFIERS, $value);
  258. }
  259.  
  260. /**
  261. * Set Privacy Enable
  262. *
  263. * This configuation setting enables/disables Baseline Privacy on the Primary Service Flow and all other Service Flows for this CM. If a
  264. * DOCSIS 1.1 CM receives this setting in a configuration file, the CM is required to forward this setting as part of the registration
  265. * request regardless of whether the configuration file is DOCSIS 1.1-style or not while this setting is usually contained only in a
  266. * DOCSIS 1.1 Service Flow TLVs.
  267. */
  268. function set_privacy_enable($value)
  269. {
  270. if($value < 0 || $value > 1) trigger_error('Privacy must be 0 or 1', E_USER_WARNING);
  271. $this->value[DOCSIS_PRIVACY_ENABLE] = new docsis_encoder_uchar(DOCSIS_PRIVACY_ENABLE, $value);
  272. }
  273.  
  274. /**
  275. * Add Vendor-Specific Information
  276. *
  277. * @param docsis_vendor $value
  278. */
  279. function add_vendor($value)
  280. {
  281. // todo: must be a docsis_vendor
  282. $this->value[DOCSIS_VENDOR][] = $value;
  283. }
  284.  
  285. /**
  286. * Set Subscriber Management Control
  287. *
  288. * @param int $max_cpe number of IP addresses permitted behind the CM.
  289. * @param boolean $active
  290. * @param boolean $learnable
  291. */
  292. function set_subscriber_management_control($max_cpe, $active, $learnable)
  293. {
  294. if($max_cpe < 0 || $max_cpe > 1023) trigger_error('MAX CPE must be 0 to 1023', E_USER_WARNING);
  295. if($active < 0 || $active > 1) trigger_error('Active must be 0 or 1', E_USER_WARNING);
  296. if($learnable < 0 || $learnable > 1) trigger_error('Learnable must be 0 or 1', E_USER_WARNING);
  297. $this->value[DOCSIS_SUBSCRIBER_MANAGEMENT] = new docsis_encoder_string(chr($max_cpe / 256) . chr($max_cpe % 256) . chr($active+2*$learnable));
  298. }
  299.  
  300. /**
  301. * Set Subscriber Management CPE IP Table
  302. *
  303. * @param array $value IP addresses
  304. */
  305. function set_subscriber_management_cpe_list($value)
  306. {
  307. $content = '';
  308. foreach($value as $ip)
  309. {
  310. foreach(explode('.', $ip) as $ch)
  311. $content .= chr($ch);
  312. }
  313. $this->value[DOCSIS_SUBSCRIBER_MANAGEMENT_CPE_IP] = new docsis_encoder_string(DOCSIS_SUBSCRIBER_MANAGEMENT_CPE_IP, $content);
  314. }
  315.  
  316. /**
  317. * Set Subscriber Management Filter Groups
  318. *
  319. * The Subscriber Management MIB allows filter groups to be assigned to a CM and CPE attached to that CM. These include two CM filter groups,
  320. * upstream and downstream, and two CPE filter groups, upstream and downstream.
  321. *
  322. * @param int $subfilter_down
  323. * @param int $subfilter_up
  324. * @param int $cmfilter_down
  325. * @param int $cmfilter_up
  326. */
  327. function set_subscriber_management_filter($subfilter_down, $subfilter_up, $cmfilter_down, $cmfilter_up)
  328. {
  329. $a = intval($subfilter_down / 256);
  330. $b = $subfilter_down - $a * 256;
  331. $value = chr($a) . chr($b);
  332.  
  333. $a = intval($subfilter_up / 256);
  334. $b = $subfilter_up - $a * 256;
  335. $value .= chr($a) . chr($b);
  336.  
  337. $a = intval($cmfilter_down / 256);
  338. $b = $cmfilter_down - $a * 256;
  339. $value .= chr($a) . chr($b);
  340.  
  341. $a = intval($cmfilter_up / 256);
  342. $b = $cmfilter_up - $a * 256;
  343. $value .= chr($a) . chr($b);
  344.  
  345. $this->value[DOCSIS_SUBSCRIBER_MANAGEMENT_FILTER] = new docsis_encoder_string(DOCSIS_SUBSCRIBER_MANAGEMENT_FILTER, $value);
  346. }
  347.  
  348. /**
  349. * Set Software Upgrade Filename
  350. *
  351. * @param string $value the fully qualified diretory-path name on the TFTP server.
  352. */
  353. function set_software_upgrade_filename($value)
  354. {
  355. $this->value[DOCSIS_SOFTWARE_UPGRADE_FILENAME] = new docsis_encoder_string(DOCSIS_SOFTWARE_UPGRADE_FILENAME, $value);
  356. }
  357.  
  358. /**
  359. * Add SNMP Write-Access Control
  360. *
  361. * This object makes it possible to disable SNMP "Set" access to individual MIB objets. Each instance of this object controls access to all of
  362. * the writeable MIB objects whose Object ID (OID) prefix matches.
  363. *
  364. * Any OID prefix may be used. The Null OID 0.0 may be used to control access to all MIB objects. (The OID 1.3.6.1 wil have the same effect.)
  365. *
  366. * @param string $oid
  367. * @param boolean $control
  368. */
  369. function add_snmp_write_control($oid, $control)
  370. {
  371. if($value < 0 || $value > 1) trigger_error('Control must be 0 or 1', E_USER_WARNING);
  372. $oid = new docsis_encoder_oid($oid);
  373. $oid = substr($oid->encode(), 2);
  374. $this->value[DOCSIS_SNMP_WRITE_CONTROL][] = chr(DOCSIS_SNMP_WRITE_CONTROL) . chr(strlen($oid) + 1) . $oid . chr($control);
  375. }
  376.  
  377. /**
  378. * Add SNMP MIB Object
  379. *
  380. * This object allows arbtrary SNMP MIB objects to be Set via the TFTP-Registration process.
  381. *
  382. * The cable modem must treat this object as if it were part of an SNMP Set Request with the following caveats:
  383. * <ul>
  384. * <li>The CM must treat the request as fully authorized (it cannot refuse the request for lack of privilege).</li>
  385. * <li>SNMP Write-Control provisions do not apply</li>
  386. * <li>No SNMP response is generated by the CM.</li>
  387. * </ul>
  388. *
  389. * All such Sets must be treated as simultaneous.
  390. *
  391. * Example values:
  392. * <ul>
  393. * <li>$value = new rfc1155_Integer($value);</li>
  394. * <li>$value = new rfc1155_Counter($value);</li>
  395. * <li>$value = new rfc1155_Guage($value);</li>
  396. * <li>$value = new rfc1155_TimeTicks($value);</li>
  397. * <li>$value = new rfc1155_OctetString(hexbin($value)); // hex string</li>
  398. * <li>$value = new rfc1155_OctetString($value);</li>
  399. * <li>$value = new rfc1155_IPAddress($value);</li>
  400. * <li>$value = new rfc1155_ObjectID($value);</li>
  401. * </ul>
  402. *
  403. * @param string $oid
  404. * @param rfc1155_Asn1Object $value
  405. */
  406. function add_snmp_object($oid, $value)
  407. {
  408. // must be a rfc1157_VarBind
  409. $varbind = new rfc1157_VarBind(new rfc1155_ObjectID($oid), $value);
  410. // $magic = ''; //chr(0x30) . chr(0x82) . chr(0x00);
  411. // $encoded = $magic . substr($varbind->encode(), 1);
  412. $encoded = $varbind->encode();
  413. $this->value[DOCSIS_SNMP_MIB_OBJECT][] = new docsis_encoder_string(DOCSIS_SNMP_MIB_OBJECT, $encoded);
  414. }
  415.  
  416. /**
  417. * Add CPE Ethernet MAC Address
  418. *
  419. * @param string $value
  420. */
  421. function add_cpe_ethernet($value)
  422. {
  423. $this->value[DOCSIS_CPE_ETHERNET][] = new docsis_encoder_mac(DOCSIS_CPE_ETHERNET, $value);
  424. }
  425.  
  426. /**
  427. * Set Software Upgrade TFTP Server
  428. *
  429. * @param string $ip address of the TFTP server, on which the software upgrade file for the CM resides.
  430. */
  431. function set_tftp_upgrade_address($ip)
  432. {
  433. $this->value[DOCSIS_SOFTWARE_TFTP_ADDRESS] = new docsis_encoder_ip(DOCSIS_SOFTWARE_TFTP_ADDRESS, $ip);
  434. }
  435.  
  436. /**
  437. * Set SNMP V3 Kickstart
  438. *
  439. * @param docsis_snmp_v3_kickstart $value
  440. */
  441. function set_snmp_v3_kickstart($value)
  442. {
  443. // todo: must be a docsis_snmp_v3_kickstart
  444. $this->value[DOCSIS_SNMP_V3_KICKSTART] = $value;
  445. }
  446.  
  447. /**
  448. * Add Manufacturer Code Verification Certificate
  449. *
  450. * The Manufaturer's Code Verification Cerrificat (M-CVC) for Secure Software Downloading. The CM config must contain this M-CVC and/or C-CVC
  451. * in order to allow 1.1 compliant CM to download the code file from TFTP server regardless the CM is provisioned to run with BPI,BPI+, or
  452. * none of them.
  453. *
  454. * @param string $value
  455. */
  456. function add_mfg_cvc_data($value)
  457. {
  458. $this->value[DOCSIS_MFG_CVC_DATA] = new docsis_encoder_hex_string(DOCSIS_MFG_CVC_DATA, $value);
  459. }
  460.  
  461. /**
  462. * Add Co-signer Code Verification Certificate
  463. *
  464. * The Co-signer's Code Verification Cerrificat (C-CVC) for Secure Software Downloading. The CM config must contain this C-CVC and/or M-CVC
  465. * in order to allow 1.1 compliant CM to download the code file from TFTP server regardless the CM is provisioned to run with BPI,BPI+, or
  466. * none of them.
  467. *
  468. * @param string $value
  469. */
  470. function add_cos_cvc_data($value)
  471. {
  472. $this->value[DOCSIS_COS_CVC_DATA] = new docsis_encoder_hex_string(DOCSIS_COS_CVC_DATA, $value);
  473. }
  474.  
  475. /**
  476. * Add SNMP v3 Trap (Notification Receiver)
  477. *
  478. * @param docsis_snmp_v3_trap $value
  479. */
  480. function set_snmp_v3_trap($value)
  481. {
  482. // todo: must be a docsis_snmp_v3_trap
  483. $this->value[DOCSIS_SNMP_V3_TRAP] = $value;
  484. }
  485.  
  486. /**
  487. * Set Modem Capabilities
  488. *
  489. * @param docis_capabilities $value
  490. */
  491. function set_modem_capabilities($value)
  492. {
  493. // todo: must be a docis_capabilities
  494. $this->value[DOCSIS_CAPABILITIES] = $value;
  495. }
  496.  
  497. /**
  498. * Set Modem IP Address
  499. *
  500. * For backwards compatibility with DOCSIS v1.0. Replace by 'TFTP Server Provisioned Modem Address'.
  501. *
  502. * @param string $ip
  503. */
  504. function set_modem_address($ip)
  505. {
  506. $this->value[DOCSIS_MODEM_ADDRESS] = new docsis_encoder_ip(DOCSIS_MODEM_ADDRESS, $ip);
  507. }
  508.  
  509. /**
  510. * Add Service Not Available Response
  511. *
  512. * This configuration setting must be included in the Registration Response message if the CMTS is unable or unwilling to grant any of the
  513. * requested classes of service that appeared in the Registration Request. Although the value applies only to the failed service class,
  514. * the entire Registration Request must be considered to have failed (none of the class-of-service configuration settings are granted).
  515. *
  516. * Confirmation codes:
  517. * <ul>
  518. * <li><b>reject-major-service-flow-error (200)</b> indicates that the REQ message did not have either SFR or SFID in a service flow
  519. * encoding, and that service flow major errors were the only major errors.</li>
  520. * <li><b>reject-major-classifier-error (201)</b> indicates that the REQ message did not hava a classifier refernece, or did not have
  521. * both a classifier ID and a Service Flow ID, and that the classifier major errors were the only major errors.</li>
  522. * <li><b>reject-major-PHS-rule-error (202)</b> indicates that the REQ message did not have both a Service Flow Reference/Identifier
  523. * and a Classifier Reference/Identifier, and that PHS rule major errors where the only major errors.</li>
  524. * <li><b>reject-mulitple-major-errors (203)</b> indicates that the REQ message contained multiple major errors of type 200, 201, 202.</li>
  525. * <li><b>reject-message-syntax-error (204)</b> indicates that the REQ message contained syntax errors resulting in a parsing failture.</li>
  526. * <li><b>reject-primary-service-flow-error (205)</b> indicates that a REG-REQ or REG-RSP message did not define a required primary
  527. * Service Flow, or a required primary Service Flow was not activated.</li>
  528. * <li><b>reject-message-too-big (206)</b> is used when the length of the message needed to respond exceeds the maximum allowed
  529. * message size.</li>
  530. * <li><b>reject-invalid-modem-capabilities (207)</b> indicates that the REG-REQ contained either that an invalid combination of modem
  531. * capabilities or modem capabilities that are inconsistent with the services in REG-REQ.</li>
  532. * </ul>
  533. *
  534. * @param int $class_id the class-of-service from the request which is not available.
  535. * @param int $type the specified class-of-service object within the class which caused the request to be rejected.
  536. * @param int $code the confirmation code.
  537. */
  538. function add_service_na($class_id, $type, $code)
  539. {
  540. if($class_id < 0 || $class_id > 255) trigger_error('Class ID must be 0 to 255', E_USER_WARNING);
  541. if($type < 0 || $type > 255) trigger_error('Type must be 0 to 255', E_USER_WARNING);
  542. if($code < 0 || $code > 255) trigger_error('Code must be 0 to 255', E_USER_WARNING);
  543. $this->value[DOCSIS_SERVICES_NOT_AVAILABLE][] = new docsis_encoder_string(DOCSIS_SERVICES_NOT_AVAILABLE, chr($class_id) . chr($type) . chr($code));
  544. }
  545.  
  546. /**
  547. * Set HMAC-Digest
  548. *
  549. * The HMAC-Digest setting is a keyed message digest. If privacy is enabled, the HMAC-Digents Attribute must be the final Attribute in the
  550. * Dynamic Service message's Attribute list. The message digest is performed over all of the Dynamic Service parameters (starting
  551. * immediately after the MAC Management Message Header and up to, but not including the HMAC Digest setting), other than the HMAC-Digest, in
  552. * the order in which they appear within the packet.
  553. *
  554. * This parameter contains a keyed hash used for message authentication. The HMAC algorithm is defined in RFC2104. The HMAC algorithm is specified
  555. * using a cryptographic hash algorithm. Baseline Privacy uses a particular version of HMAC that employs the Secure Hash Algorithm (SHA-1).
  556. *
  557. * @param string $value
  558. */
  559. function set_hmac_digest($value)
  560. {
  561. $this->value[DOCSIS_HMAC_DIGEST] = new docsis_encoder_hex_string(DOCSIS_HMAC_DIGEST, $value);
  562. }
  563.  
  564. /**
  565. * Set Authorization Block
  566. *
  567. * @param string $value
  568. */
  569. function set_auth_block($value)
  570. {
  571. $this->value[DOCSIS_AUTHORIZATION_BLOCK] = new docsis_encoder_hex_string(DOCSIS_AUTHORIZATION_BLOCK, $value);
  572. }
  573.  
  574. /**
  575. * Key Sequence Number
  576. *
  577. * This value shows the key sequence number of the BPI+ Authorizaion Key which is used to calculate the HMAC-Digest in case that the
  578. * Privacy is enabled.
  579. *
  580. * @param string $value
  581. */
  582. function set_key_sequence($value)
  583. {
  584. if($value < 0 || $value > 15) trigger_error('Key Sequence must be 0 to 15', E_USER_WARNING);
  585. $this->value[DOCSIS_HMAC_DIGEST] = new docsis_encoder_uchar(DOCSIS_HMAC_DIGEST, $value);
  586. }
  587.  
  588. /* Set Telephone Settings
  589. *
  590. * @param docsis_telephone $value
  591. */
  592. function set_telephone($value)
  593. {
  594. // todo: must be a docsis_telephone
  595. $this->value[DOCSIS_TELEPHONE] = $value;
  596. }
  597.  
  598. /* Set Baseline Privacy Settings
  599. *
  600. * @param docsis_baseline_privacy $value
  601. */
  602. function set_baseline_privacy($value)
  603. {
  604. // todo: must be a docsis_baseline_privacy
  605. $this->value[DOCSIS_BASELINE_PRIVACY] = $value;
  606. }
  607.  
  608. function set_mta_config_delimiter($value)
  609. {
  610. if($value < 1 || $value > 255) trigger_error('MTA Config Delimiter must be 1 to 255', E_USER_WARNING);
  611. $this->value[DOCSIS_MTA_CONFIG_DELIMITER] = new docsis_encoder_uchar(DOCSIS_MTA_CONFIG_DELIMITER, $value);
  612. }
  613.  
  614. function set_docsis_2_enable($value)
  615. {
  616. if($value < 0 || $value > 1) trigger_error('DOCSIS 2 Enable must be 0 or 1', E_USER_WARNING);
  617. $this->value[DOCSIS_2_ENABLE] = new docsis_encoder_uchar(DOCSIS_2_ENABLE, $value);
  618. }
  619.  
  620. function encode($key='')
  621. {
  622. if(isset($this->value[DOCSIS_CM_MIC])) unset($this->value[DOCSIS_CM_MIC]);
  623. if(isset($this->value[DOCSIS_CMTS_MIC])) unset($this->value[DOCSIS_CMTS_MIC]);
  624.  
  625. $binary = substr(parent::encode(), 2);
  626. $cm_mic = $this->get_cm_mic();
  627. $cmts_mic = $this->get_cmts_mic($key);
  628. $binary = $binary . $cm_mic->encode() . $cmts_mic->encode() . chr(255);
  629. if(strlen($binary) % 4)
  630. $binary .= str_repeat(chr(0), 4 - (strlen($binary) % 4));
  631. return $binary;
  632. }
  633.  
  634. function get_cm_mic()
  635. {
  636. if(isset($this->value[DOCSIS_CM_MIC])) unset($this->value[DOCSIS_CM_MIC]);
  637. if(isset($this->value[DOCSIS_CMTS_MIC])) unset($this->value[DOCSIS_CMTS_MIC]);
  638.  
  639. $this->value[DOCSIS_CM_MIC] = new docsis_encoder_hex_string(DOCSIS_CM_MIC, md5(substr(parent::encode(), 2)));
  640. return $this->value[DOCSIS_CM_MIC];
  641. }
  642.  
  643. function get_cmts_mic($key)
  644. {
  645. $this->get_cm_mic();
  646.  
  647. $content = '';
  648. foreach(array(DOCSIS_DOWNSTREAM_FREQUENCY, DOCSIS_UPSTREAM_CHANNEL_ID, DOCSIS_NETWORK_ACCESS, DOCSIS_CLASS_OF_SERVICE,
  649. DOCSIS_BASELINE_PRIVACY, DOCSIS_VENDOR, DOCSIS_CM_MIC, DOCSIS_MAX_CPES, DOCSIS_TFTP_TIMESTAMP, DOCSIS_TFTP_ADDRESS,
  650. DOCSIS_UPSTREAM_PACKET_CLASSIFIER, DOCSIS_DOWNSTREAM_PACKET_CLASSIFIER, DOCSIS_FLOW_UP,
  651. DOCSIS_FLOW_DOWN, DOCSIS_MAX_CLASSIFIERS, DOCSIS_PRIVACY_ENABLE, DOCSIS_PAYLOAD_HEADER_SUPPRESSION,
  652. DOCSIS_SUBSCRIBER_MANAGEMENT, DOCSIS_SUBSCRIBER_MANAGEMENT_CPE_IP, DOCSIS_SUBSCRIBER_MANAGEMENT_FILTER) as $code)
  653. {
  654. if(isset($this->value[$code]))
  655. {
  656. $obj = $this->value[$code];
  657. if(is_array($obj))
  658. {
  659. foreach($obj as $o)
  660. $content .= $o->encode();
  661. }
  662. else
  663. $content .= $obj->encode();
  664. }
  665. }
  666.  
  667. $this->value[DOCSIS_CMTS_MIC] = new docsis_encoder_hex_string(DOCSIS_CMTS_MIC, $this->keyedMD5($content, $key));
  668. return $this->value[DOCSIS_CMTS_MIC];
  669. }
  670.  
  671. function keyedMD5($data, $key) // rfc 2104
  672. {
  673. $innerText = str_pad($key, 64, chr(0)) ^ str_repeat(chr(0x36), 64);
  674. $innerHash = pack('H*', md5($innerText . $data));
  675. return md5((str_pad($key, 64, chr(0)) ^ str_repeat(chr(0x5c), 64)) . $innerHash);
  676. }
  677. }
  678. ?>

Documentation generated on Mon, 14 Nov 2005 18:00:11 -0700 by phpDocumentor 1.3.0RC3