620
606
sensor_array[typ].n++;
623
DEBUGMSGTL(("ucd-snmp/lmSensors",
609
DEBUGMSG(("ucd-snmp/lmSensors",
624
610
"sensor value read error code->%d\n",ec2));
627
DEBUGMSGTL(("ucd-snmp/lmSensors",
613
DEBUGMSG(("ucd-snmp/lmSensors",
628
614
"sensor lookup failed error code->%d\n",error_code));
633
process_sensors(int level, picl_nodehdl_t nodeh)
619
process_sensors(picl_nodehdl_t nodeh)
635
621
picl_nodehdl_t childh;
637
char propname[PICL_PROPNAMELEN_MAX];
638
char propclass[PICL_CLASSNAMELEN_MAX];
639
picl_errno_t error_code;
640
picl_prophdl_t prop_handle;
641
picl_propinfo_t prop_info;
646
DEBUGMSGTL(("ucd-snmp/lmSensors","Processing sensors level %d\n",level));
649
error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME, propclass,
650
(PICL_PROPNAMELEN_MAX-1));
622
picl_nodehdl_t nexth;
624
char propname[PICL_PROPNAMELEN_MAX];
625
char propclass[PICL_CLASSNAMELEN_MAX];
626
picl_errno_t error_code;
628
/* look up first child node */
629
error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
630
sizeof (picl_nodehdl_t));
651
631
if (error_code != PICL_SUCCESS) {
652
DEBUGMSG(("ucd-snmp/lmSensors","Couldn't get propclass\n"));
653
632
return (error_code);
656
error_code = picl_get_prop_by_name(nodeh, PICL_PROP_NAME, &prop_handle);
658
if (error_code != PICL_SUCCESS) {
659
DEBUGMSGTL(("ucd-snmp/lmSensors","Couldn't get prop_handle\n"));
664
error_code = picl_get_propinfo(prop_handle, &prop_info);
666
if (error_code != PICL_SUCCESS) {
667
DEBUGMSGTL(("ucd-snmp/lmSensors","Couldn't get prop information\n"));
672
error_code=picl_get_propval(prop_handle, propname, (PICL_PROPNAMELEN_MAX-1));
674
DEBUGMSGTL(("ucd-snmp/lmSensors","found propname %s of class %s\n",propname, propclass));
676
if (error_code != PICL_SUCCESS) {
677
DEBUGMSGTL(("ucd-snmp/lmSensors","Couldn't get prop handle by name\n"));
682
if (strstr(propclass,"flashprom"))
683
DEBUGMSGTL(("ucd-snmp/lmSensors","found a flashprom\n"));
684
if (strstr(propclass,"fan-tachometer"))
685
process_individual_fan(nodeh,propname);
686
if (strstr(propclass,"temperature-sensor"))
687
process_temperature_sensor(nodeh,propname);
688
if (strstr(propclass,"digital-sensor"))
689
process_digital_sensor(nodeh,propname);
690
if (strstr(propclass,"switch"))
691
process_switch(nodeh,propname);
692
if (strstr(propclass,"led"))
693
process_led(nodeh,propname);
694
if (strstr(propclass,"i2c"))
695
process_i2c(nodeh,propname);
635
/* step through child nodes, get the name first */
636
while (error_code == PICL_SUCCESS) {
637
error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME,
638
propname, (PICL_PROPNAMELEN_MAX - 1));
639
if (error_code != PICL_SUCCESS) { /*we found a node with no name. Impossible.! */
643
if (strcmp(propname,PICL_NODE_PLATFORM)==0){ /*end of the chain*/
647
error_code = picl_get_propval_by_name(childh, PICL_PROP_CLASSNAME,
648
propclass, sizeof (propclass));
649
if (error_code != PICL_SUCCESS) { /*we found a node with no class. Impossible.! */
653
/* DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass)); */
655
if (strstr(propclass,"fan-tachometer"))
656
process_individual_fan(childh,propname);
657
if (strstr(propclass,"temperature-sensor"))
658
process_temperature_sensor(childh,propname);
659
if (strstr(propclass,"digital-sensor"))
660
process_digital_sensor(childh,propname);
661
if (strstr(propclass,"switch"))
662
process_switch(childh,propname);
663
if (strstr(propclass,"led"))
664
process_led(childh,propname);
665
if (strstr(propclass,"i2c"))
666
process_i2c(childh,propname);
697
668
if (strstr(propclass,"gpio"))
698
process_gpio(prop_handle,propname);
669
process_gpio(childh,propname);
700
for (error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD,
701
&childh, sizeof (picl_nodehdl_t));
702
error_code != PICL_PROPNOTFOUND;
703
error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
704
&childh, sizeof (picl_nodehdl_t))) {
705
if (error_code != PICL_SUCCESS) {
673
/* look for children of children (note, this is recursive) */
675
if (process_sensors(childh) == PICL_SUCCESS) {
676
return (PICL_SUCCESS);
679
/* get next child node at this level*/
680
error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
681
&nexth, sizeof (picl_nodehdl_t));
682
if (error_code != PICL_SUCCESS) {/* no more children - buh bye*/
706
683
return (error_code);
709
/* call itself recursively */
711
error_code = process_sensors(level,childh);
713
if (error_code != PICL_SUCCESS)
718
return (PICL_SUCCESS);
721
690
} /* process sensors */
693
get_child(picl_nodehdl_t nodeh, char *cname, picl_nodehdl_t *resulth)
695
picl_nodehdl_t childh;
696
picl_nodehdl_t nexth;
698
char pname[PICL_PROPNAMELEN_MAX];
699
picl_errno_t error_code;
701
/* look up first child node */
702
error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
703
sizeof (picl_nodehdl_t));
704
if (error_code != PICL_SUCCESS) {
708
/* step through child nodes, get the name first */
709
while (error_code == PICL_SUCCESS) {
710
error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME,
711
pname, (PICL_PROPNAMELEN_MAX - 1));
712
if (error_code != PICL_SUCCESS) { /*we found a node with no name. Impossible.! */
716
if (strncmp(pname, cname,PICL_PROPNAMELEN_MAX) == 0){
718
return (PICL_SUCCESS);
722
/* look for children of children (note, this is recursive) */
724
if (get_child(childh,cname,resulth) == PICL_SUCCESS) {
725
return (PICL_SUCCESS);
728
/* get next child node at this level*/
730
error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
731
&nexth, sizeof (picl_nodehdl_t));
732
if (error_code != PICL_SUCCESS) {/* no more children - buh bye*/
724
743
/* ******** end of picld sensor procedures * */
761
/* try picld (if supported), then try kstat */
780
/* try picld (if supported), if that doesn't work, try kstat */
762
781
#ifdef HAVE_PICL_H
764
DEBUGMSGTL(("ucd-snmp/lmSensors","trying picld first\n"));
766
783
er_code = picl_initialize();
768
785
if (er_code == PICL_SUCCESS) {
770
DEBUGMSGTL(("ucd-snmp/lmSensors","Got into picld\n"));
772
787
error_code = picl_get_root(&rooth);
774
789
if (error_code != PICL_SUCCESS) {
775
DEBUGMSGTL(("ucd-snmp/lmSensors", "picld couldn't get root error code->%d\n",error_code));
790
DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get root error code->%d\n",error_code));
778
DEBUGMSGTL(("ucd-snmp/lmSensors", "found root\n"));
779
error_code = process_sensors(level, rooth);
793
error_code = get_child(rooth,sname,&plath);
795
if (error_code == PICL_SUCCESS){
796
error_code = process_sensors(plath);
798
if (error_code != 255)
800
DEBUGMSG(("ucd-snmp/lmSensors", "picld had an internal problem error code->%d\n",error_code));
801
} /* endif error_code */
803
DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get system tree error code->%d\n",error_code));
804
} /* end else error_code */
784
809
} /* end if err_code for picl_initialize */
786
DEBUGMSGTL(("ucd-snmp/lmSensors","No picld available\n"));
788
} /*end else picl_initialize */
811
else{ /* try kstat instead */
813
DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't initialize picld because error code->%d\n",er_code));
790
815
#endif /* end of picld section */
791
816
/* initialize kstat */
793
818
kc = kstat_open();
795
DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't open kstat\n"));
820
DEBUGMSG(("ucd-snmp/lmSensors", "couldn't open kstat"));
798
DEBUGMSGTL(("ucd-snmp/lmSensors", "Opened kstat - looking for sensors\n"));
799
823
kp = kstat_lookup(kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
801
825
DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't lookup fan kstat\n"));
802
826
} /* endif lookup fans */
804
828
if (kstat_read(kc, kp, 0) == -1) {
805
DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read fan kstat\n"));
829
DEBUGMSGTL(("ucd-snmp/lmSensors", "couldn't read fan kstat"));
806
830
} /* endif kstatread fan */
809
833
fan_info = (envctrl_fan_t *) kp->ks_data;
810
834
sensor_array[typ].n = kp->ks_ndata;
811
835
for (i=0; i < kp->ks_ndata; i++){
812
DEBUGMSGTL(("ucd-snmp/lmSensors", "found instance %d fan type %d speed %d OK %d bustedfan %d\n",
836
DEBUGMSG(("ucd-snmp/lmSensors", "found instance %d fan type %d speed %d OK %d bustedfan %d\n",
813
837
fan_info->instance, fan_info->type,fan_info->fanspeed,fan_info->fans_ok,fan_info->fanflt_num));
814
838
sensor_array[typ].sensor[i].value = fan_info->fanspeed;
815
839
snprintf(sensor_array[typ].sensor[i].name,(MAX_NAME - 1),