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

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