t_std_error nas_mac_event_publish(cps_api_object_t obj){ cps_api_return_code_t rc; if((rc = cps_api_event_publish(handle,obj))!= cps_api_ret_code_OK){ cps_api_object_delete(obj); return (t_std_error)rc; } cps_api_object_delete(obj); return STD_ERR_OK; }
t_std_error nas_mirror_get_session_info(cps_api_object_list_t list, nas_mirror_id_t id){ std_mutex_simple_lock_guard lock(&nas_mirror_mutex); auto it = nas_mirror_table.find(id); if(it == nas_mirror_table.end()){ NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"No NAS Mirror session with Id %d exist",(int)id); return STD_ERR(MIRROR,NEXIST,0); } cps_api_object_t obj=cps_api_object_create(); if (obj==NULL) { NAS_MIRROR_LOG(ERR,0,"Failed to create a new object"); return STD_ERR(MIRROR,NOMEM,0); } if (!cps_api_object_list_append(list,obj)) { cps_api_object_delete(obj); NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Failed to append object to object list"); return STD_ERR(MIRROR,FAIL,0); } nas_mirror_fill_object(obj,it); return STD_ERR_OK; }
t_std_error nas_sflow_get_session_info(cps_api_object_list_t list,nas_sflow_id_t id){ std_mutex_simple_lock_guard lock(&nas_sflow_mutex); nas_sflow_map_it it = nas_sflow_table.find(id); if(it == nas_sflow_table.end()){ NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"No NAS sFlow session with Id %d exist",(int)id); return STD_ERR(SFLOW,NEXIST,0); } cps_api_object_t obj=cps_api_object_create(); if(obj == NULL){ NAS_SFLOW_LOG(ERR,0,"Failed to create new object"); return STD_ERR(SFLOW,NOMEM,0); } if (!cps_api_object_list_append(list,obj)) { cps_api_object_delete(obj); return STD_ERR(SFLOW,FAIL,0); } nas_sflow_fill_object(obj,it); return STD_ERR_OK; }
static cps_api_return_code_t get_interface( const char * name, cps_api_get_params_t *param, size_t *ix) { cps_api_object_t obj = cps_api_object_create(); uint_t ifix = cps_api_interface_name_to_if_index(name); cps_api_int_if_key_create(cps_api_object_key(obj),true,0,ifix); if (!cps_api_object_list_append(param->list,obj)) { cps_api_object_delete(obj); return cps_api_ret_code_ERR; } cps_api_object_attr_add(obj,cps_api_if_STRUCT_A_NAME,name,strlen(name)+1); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IFINDEX,ifix); unsigned int mtu; if (nas_os_util_int_mtu_get(name,&mtu)!=STD_ERR_OK) return cps_api_ret_code_ERR; cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_MTU,mtu); db_interface_state_t astate; db_interface_operational_state_t ostate; if (nas_os_util_int_admin_state_get(name,&astate,&ostate)!=STD_ERR_OK) return cps_api_ret_code_ERR; cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_ADMIN_STATE,astate); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_OPER_STATE,ostate); hal_mac_addr_t mac; if (nas_os_util_int_mac_addr_get(name,&mac)!=STD_ERR_OK) return cps_api_ret_code_ERR; cps_api_object_attr_add(obj,cps_api_if_STRUCT_A_IF_MACADDR,&mac,sizeof(mac)); return cps_api_ret_code_OK; }
bool get_netlink_data(int rt_msg_type, struct nlmsghdr *hdr, void *data) { cps_api_object_t obj=cps_api_object_create(); if (!nl_get_if_info(rt_msg_type,hdr,obj)) return false; cps_api_object_attr_t attr = cps_api_object_attr_get(obj,cps_api_if_STRUCT_A_NAME); if (attr==CPS_API_ATTR_NULL) return false; char buff[1024]; printf("OID = %s\n",cps_api_key_print(cps_api_object_key(obj),buff,sizeof(buff))); printf("Name:%s \n", (char*)cps_api_object_attr_data_bin(attr)); cps_api_object_delete(obj); return true; }
static bool process_route_and_add_to_list(int rt_msg_type, struct nlmsghdr *nh, void *context) { cps_api_object_list_t *list = (cps_api_object_list_t*) context; cps_api_object_t obj=cps_api_object_create(); if (!cps_api_object_list_append(*list,obj)) { cps_api_object_delete(obj); return false; } if (!nl_to_route_info(nh->nlmsg_type,nh,obj)) { return false; } return true; }
t_std_error nas_sflow_get_all_info(cps_api_object_list_t list){ std_mutex_simple_lock_guard lock(&nas_sflow_mutex); nas_sflow_map_it it = nas_sflow_table.begin(); for ( ; it != nas_sflow_table.end() ; ++it){ cps_api_object_t obj=cps_api_object_create(); if(obj == NULL){ NAS_SFLOW_LOG(ERR,0,"Failed to create new object"); return STD_ERR(SFLOW,NOMEM,0); } if (!cps_api_object_list_append(list,obj)) { cps_api_object_delete(obj); return STD_ERR(SFLOW,FAIL,0); } nas_sflow_fill_object(obj,it); } return STD_ERR_OK; }
static cps_api_return_code_t _write_function(void * context, cps_api_transaction_params_t * param,size_t ix) { cps_api_object_t obj = cps_api_object_list_get(param->change_list,ix); if (obj==NULL) return cps_api_ret_code_ERR; cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj)); cps_api_object_t prev = cps_api_object_create(); if (prev==NULL) return cps_api_ret_code_ERR; if (!cps_api_object_list_append(param->prev,prev)) { cps_api_object_delete(prev); return cps_api_ret_code_ERR; } cps_api_key_t _local_key; cps_api_key_init(&_local_key,cps_api_qualifier_TARGET,cps_api_obj_cat_ROUTE,cps_api_route_obj_EVENT,0); if (cps_api_key_matches(&_local_key,cps_api_object_key(obj),true)) { os_send_refresh(nas_nl_sock_T_ROUTE); } else { return _op(op,context,obj,prev); } return cps_api_ret_code_OK; }
t_std_error nas_mirror_get_all_info(cps_api_object_list_t list){ std_mutex_simple_lock_guard lock(&nas_mirror_mutex); auto it = nas_mirror_table.begin(); for ( ; it != nas_mirror_table.end() ; ++it){ cps_api_object_t obj=cps_api_object_create(); if (obj==NULL) { NAS_MIRROR_LOG(ERR,0,"Failed to create a new object"); return STD_ERR(MIRROR,NOMEM,0); } if (!cps_api_object_list_append(list,obj)) { cps_api_object_delete(obj); NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Failed to append object to object list"); return STD_ERR(MIRROR,FAIL,0); } nas_mirror_fill_object(obj,it); } return STD_ERR_OK; }
PyObject * py_cps_get(PyObject *self, PyObject *args) { PyObject * param_list; cps_api_get_params_t gr; if (cps_api_get_request_init (&gr)==cps_api_ret_code_ERR) { py_set_error_string("Failed to initialize the get req"); return nullptr; } cps_api_get_request_guard rg(&gr); PyObject *res_obj; if (! PyArg_ParseTuple( args, "O!O", &PyList_Type, ¶m_list,&res_obj)) { py_set_error_string("Failed to parse input args."); return nullptr; } PyObject * lst = NULL; if (PyDict_Check(res_obj)) { PyObject *l = PyList_New(0); PyRef _l(l); if (l==NULL) { py_set_error_string("Can not create a list."); return nullptr; } PyObject *_prev = PyDict_GetItemString(res_obj,"list"); if (_prev!=NULL) { PyDict_DelItemString(res_obj,"list"); } if (!py_cps_util_set_item_to_dict(res_obj,"list",l)) { py_set_error_string("Can not create a list."); return nullptr; } lst = l; } if (PyList_Check(res_obj)) { lst = res_obj; } if (lst==NULL) { py_set_error_string("The return args are invalid."); return nullptr; } Py_ssize_t str_keys = PyList_Size(param_list); { Py_ssize_t ix = 0; for ( ;ix < str_keys ; ++ix ) { PyObject *strObj = PyList_GetItem(param_list, ix); if (PyString_Check(strObj)) { // cps_api_object_t o = cps_api_object_list_create_obj_and_append(gr.filters); if (o==NULL) { py_set_error_string("Memory allocation error."); return nullptr; } if (!cps_api_key_from_string(cps_api_object_key(o),PyString_AsString(strObj))) { py_set_error_string("Memory allocation error."); return nullptr; } } if (PyDict_Check(strObj)) { cps_api_object_t o = dict_to_cps_obj(strObj); if (o==NULL) { py_set_error_string("Can't convert from a python to internal object"); return nullptr; } if (!cps_api_object_list_append(gr.filters,o)) { cps_api_object_delete(o); py_set_error_string("Memory allocation error."); return nullptr; } } } } gr.keys = NULL; gr.key_count = 0; cps_api_return_code_t rc; { NonBlockingPythonContext l; rc = cps_api_get(&gr); } if (rc!=cps_api_ret_code_OK) { Py_RETURN_FALSE; } size_t ix = 0; size_t mx = cps_api_object_list_size(gr.list); for ( ; ix < mx ; ++ix) { cps_api_object_t obj = cps_api_object_list_get(gr.list,ix); PyObject *d = cps_obj_to_dict(obj); PyRef r(d); if (d==NULL) { py_set_error_string("Memory allocation error."); return nullptr; } if (PyList_Append(lst,d)) { py_set_error_string("Memory allocation error."); return nullptr; } } Py_RETURN_TRUE; }
static t_std_error dn_pas_psu_get1( cps_api_get_params_t *param, cps_api_qualifier_t qual, uint_t slot ) { cps_api_key_t rec_key[1]; pas_psu_t *rec; cps_api_object_t resp_obj; /* Look up object in cache */ cps_api_key_init(rec_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_PSU_OBJ, 1, slot ); rec = (pas_psu_t *) dn_pas_res_get(rec_key); if (rec == 0) { /* Not found */ return (STD_ERR(PAS, NEXIST, 0)); } /* Compose respose object */ resp_obj = cps_api_object_create(); if (resp_obj == CPS_API_OBJECT_NULL) { EV_LOG_ERR(ev_log_t_PAS, 3, "PAS", "%s, allocate response object failed\n", __FUNCTION__); return (STD_ERR(PAS, NOMEM, 0)); } dn_pas_obj_key_psu_set(resp_obj, qual, true, slot); dn_pas_lock(); if ((!rec->valid || qual == cps_api_qualifier_REALTIME) && !dn_pald_diag_mode_get()) { /* Cache not valid or realtime object requested => Update cache from hardware */ dn_entity_poll(rec->parent, true); } if (rec->parent->present) { /* Add result attributes to response object */ cps_api_object_attr_add_u8(resp_obj, BASE_PAS_PSU_INPUT_TYPE, rec->input_type ); cps_api_object_attr_add_u8(resp_obj, BASE_PAS_PSU_FAN_AIRFLOW_TYPE, rec->fan_airflow_type ); } dn_pas_unlock(); /* Add response object to get response */ if (!cps_api_object_list_append(param->list, resp_obj)) { cps_api_object_delete(resp_obj); return (STD_ERR(PAS, FAIL, 0)); } return (STD_ERR_OK); }
extern "C" bool nl_get_ip_info (int rt_msg_type, struct nlmsghdr *hdr, cps_api_object_t obj) { struct ifaddrmsg *ifmsg = (struct ifaddrmsg *)NLMSG_DATA(hdr); if(hdr->nlmsg_len < NLMSG_LENGTH(sizeof(*ifmsg))) return false; typedef enum { IP_KEY, IFINDEX, PREFIX, ADDRESS, IFNAME } attr_t ; static const std::map<uint32_t, std::map<int,cps_api_attr_id_t>> _ipmap = { {AF_INET, { {IP_KEY, BASE_IP_IPV4_OBJ}, {IFINDEX, BASE_IP_IPV4_IFINDEX}, {PREFIX, BASE_IP_IPV4_ADDRESS_PREFIX_LENGTH}, {ADDRESS, BASE_IP_IPV4_ADDRESS_IP}, {IFNAME, BASE_IP_IPV4_NAME} }}, {AF_INET6, { {IP_KEY, BASE_IP_IPV6_OBJ}, {IFINDEX, BASE_IP_IPV6_IFINDEX}, {PREFIX, BASE_IP_IPV6_ADDRESS_PREFIX_LENGTH}, {ADDRESS, BASE_IP_IPV6_ADDRESS_IP}, {IFNAME, BASE_IP_IPV6_NAME} }} }; cps_api_key_from_attr_with_qual(cps_api_object_key(obj),_ipmap.at(ifmsg->ifa_family).at(IP_KEY), cps_api_qualifier_TARGET); cps_api_set_key_data(obj,_ipmap.at(ifmsg->ifa_family).at(IFINDEX), cps_api_object_ATTR_T_U32, &ifmsg->ifa_index,sizeof(ifmsg->ifa_index)); cps_api_object_attr_add_u32(obj, _ipmap.at(ifmsg->ifa_family).at(IFINDEX), ifmsg->ifa_index); cps_api_object_attr_add_u32(obj, _ipmap.at(ifmsg->ifa_family).at(PREFIX), ifmsg->ifa_prefixlen); int nla_len = nlmsg_attrlen(hdr,sizeof(*ifmsg)); struct nlattr *head = nlmsg_attrdata(hdr, sizeof(struct ifaddrmsg)); struct nlattr *attrs[__IFLA_MAX]; memset(attrs,0,sizeof(attrs)); if (nla_parse(attrs,__IFLA_MAX,head,nla_len)!=0) { EV_LOG_TRACE(ev_log_t_NAS_OS,ev_log_s_WARNING,"IP-NL-PARSE","Failed to parse attributes"); cps_api_object_delete(obj); return false; } if(attrs[IFA_ADDRESS]!=NULL) { rta_add_ip((struct nlattr*)ifmsg, ifmsg->ifa_family, obj, _ipmap.at(ifmsg->ifa_family).at(ADDRESS)); } if(attrs[IFA_LABEL]!=NULL) { rta_add_name(attrs[IFA_LABEL], obj, _ipmap.at(ifmsg->ifa_family).at(IFNAME)); } if (rt_msg_type == RTM_NEWADDR) { cps_api_object_set_type_operation(cps_api_object_key(obj),cps_api_oper_CREATE); } else if (rt_msg_type == RTM_DELADDR) { cps_api_object_set_type_operation(cps_api_object_key(obj),cps_api_oper_DELETE); } else { cps_api_object_set_type_operation(cps_api_object_key(obj),cps_api_oper_SET); } return true; }
//db_if_event_t bool nl_get_if_info (int rt_msg_type, struct nlmsghdr *hdr, cps_api_object_t obj) { struct ifinfomsg *ifmsg = (struct ifinfomsg *)NLMSG_DATA(hdr); if(hdr->nlmsg_len < NLMSG_LENGTH(sizeof(*ifmsg))) return false; db_if_type_t _type = DB_IF_TYPE_PHYS_INTER; uint_t ifindex = ifmsg->ifi_index; uint32_t op = 0; EV_LOG(INFO, NAS_OS, 3, "NET-MAIN", "nl_get_if_info msgType %d, ifindex %d change %x\n", rt_msg_type, ifindex, ifmsg->ifi_change); if (rt_msg_type ==RTM_NEWLINK) { op = DB_INTERFACE_OP_CREATE; } else if (rt_msg_type ==RTM_DELLINK) { op = DB_INTERFACE_OP_DELETE; } else { op = DB_INTERFACE_OP_SET; } cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_OPERATION,op); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_FLAGS, ifmsg->ifi_flags); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IFINDEX,ifindex); if(ifmsg->ifi_flags & IFF_UP) { cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_ADMIN_STATE,DB_ADMIN_STATE_UP); } else { cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_ADMIN_STATE,DB_ADMIN_STATE_DN); } int nla_len = nlmsg_attrlen(hdr,sizeof(*ifmsg)); struct nlattr *head = nlmsg_attrdata(hdr, sizeof(struct ifinfomsg)); struct nlattr *attrs[__IFLA_MAX]; memset(attrs,0,sizeof(attrs)); if (nla_parse(attrs,__IFLA_MAX,head,nla_len)!=0) { EV_LOG(ERR,NAS_OS,0,"NL-PARSE","Failed to parse attributes"); cps_api_object_delete(obj); return false; } if (attrs[IFLA_ADDRESS]!=NULL) { rta_add_mac(attrs[IFLA_ADDRESS],obj,cps_api_if_STRUCT_A_IF_MACADDR); } if(attrs[IFLA_IFNAME]!=NULL) { rta_add_name(attrs[IFLA_IFNAME],obj,cps_api_if_STRUCT_A_NAME); } if(attrs[IFLA_MTU]!=NULL) { int *mtu = (int *) nla_data(attrs[IFLA_MTU]); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_MTU,(*mtu + NAS_LINK_MTU_HDR_SIZE)); } if(attrs[IFLA_MASTER]!=NULL) { /* This gives us the bridge index, which should be sent to * NAS for correlation */ EV_LOG(INFO, NAS_OS, 3, "NET-MAIN", "Rcvd master index %d", *(int *)nla_data(attrs[IFLA_MASTER])); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_MASTER, *(int *)nla_data(attrs[IFLA_MASTER])); if(op == DB_INTERFACE_OP_DELETE) { /* With Dell offering VLAN data structures use port index instead of * vlan interface */ int phy_ifindex = 0; nas_os_physical_to_vlan_ifindex(ifindex, 0, false, &phy_ifindex); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IFINDEX, phy_ifindex); cps_api_object_attr_add_u32(obj, cps_api_if_STRUCT_A_VLAN_PORT_INDEX, ifindex); _type = DB_IF_TYPE_VLAN_INTER; } } struct nlattr *linkinfo[IFLA_INFO_MAX]; struct nlattr *vlan[IFLA_VLAN_MAX]; char *info_kind; if (attrs[IFLA_LINKINFO]) { memset(linkinfo,0,sizeof(linkinfo)); nla_parse_nested(linkinfo,IFLA_INFO_MAX,attrs[IFLA_LINKINFO]); if(linkinfo[IFLA_INFO_KIND]) { info_kind = (char *)nla_data(linkinfo[IFLA_INFO_KIND]); EV_LOG(INFO, NAS_OS, 3, "NET-MAIN", "In IFLA_INFO_KIND for %s index %d", info_kind, ifindex); if(!strncmp(info_kind, "vlan", 4)) { if(attrs[IFLA_MASTER]!=NULL) { if (linkinfo[IFLA_INFO_DATA]) { memset(vlan,0,sizeof(vlan)); nla_parse_nested(vlan,IFLA_VLAN_MAX,linkinfo[IFLA_INFO_DATA]); if (vlan[IFLA_VLAN_ID]) { EV_LOG(INFO, NAS_OS, 3, "NET-MAIN", "Received VLAN %d", ifindex); cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_VLAN_ID, *(uint16_t*)nla_data(vlan[IFLA_VLAN_ID])); _type = DB_IF_TYPE_VLAN_INTER; if (attrs[IFLA_LINK]) { //port that is added to vlan uint32_t portIndex = *(uint32_t*)nla_data(attrs[IFLA_LINK]); if (op == DB_INTERFACE_OP_DELETE) { cps_api_object_attr_add_u32(obj, cps_api_if_STRUCT_A_VLAN_PORT_INDEX, ifindex); } else { cps_api_object_attr_add_u32(obj, cps_api_if_STRUCT_A_VLAN_PORT_INDEX, portIndex); } } //IFLA_LINK } //IFLA_VLAN_ID }//IFLA_INFO_DATA }// IFLA_MASTER } // vlan interface else if(!strncmp(info_kind, "tun", 3)) { /* TODO : Revisit this and introduce a logical interface type */ if(attrs[IFLA_MASTER]!=NULL) { EV_LOG(INFO, NAS_OS,3, "NET-MAIN", "Received tun %d", ifindex); _type = DB_IF_TYPE_VLAN_INTER; cps_api_object_attr_add_u32(obj, cps_api_if_STRUCT_A_VLAN_PORT_INDEX, ifindex); } if(ifmsg->ifi_flags & IFF_SLAVE) { EV_LOG(INFO, NAS_OS,3, "NET-MAIN", "Received tun %d and state IFF_UP", ifindex,ifmsg->ifi_flags); _type = DB_IF_TYPE_LAG_INTER; } } else if(!strncmp(info_kind, "bridge", 6)) { EV_LOG(INFO,NAS_OS,3, "NET-MAIN", "Bridge intf index is %d ", ifindex); _type = DB_IF_TYPE_BRIDGE_INTER; } /* bridge interface */ else if(!strncmp(info_kind, "bond", 4)) { EV_LOG(INFO, NAS_OS,3, "NET-MAIN", "Bond interface index is %d ", ifindex); _type = DB_IF_TYPE_LAG_INTER; if(attrs[IFLA_MASTER]!=NULL) { EV_LOG(INFO, NAS_OS,3, "NET-MAIN", "Received bond %d with master set %d", ifindex, *(int *)nla_data(attrs[IFLA_MASTER])); /* Bond with master set, means configured in a bridge * Pass the master index as the ifindex for vlan processing to continue */ _type = DB_IF_TYPE_VLAN_INTER; cps_api_object_attr_add_u32(obj, cps_api_if_STRUCT_A_VLAN_PORT_INDEX, ifindex); if (op == DB_INTERFACE_OP_DELETE ) { cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IFINDEX, *(int *)nla_data(attrs[IFLA_MASTER])); } } } // bond interface } } if(attrs[IFLA_OPERSTATE]!=NULL) { int *link = (int *) nla_data(attrs[IFLA_OPERSTATE]); if (*link==IF_OPER_UP) { cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_OPER_STATE,DB_OPER_STATE_UP); } else if (*link==IF_OPER_DOWN) { cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_OPER_STATE,DB_OPER_STATE_DN); } } cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IF_TYPE,_type); cps_api_int_if_key_create(cps_api_object_key(obj),true,0,ifindex); return true; }
static t_std_error dn_pas_fan_get1( cps_api_get_params_t *param, cps_api_qualifier_t qual, uint_t entity_type, uint_t slot, uint_t fan_idx ) { cps_api_key_t rec_key[1]; pas_fan_t *rec; cps_api_object_t resp_obj; /* Look up object in cache */ cps_api_key_init(rec_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_FAN_OBJ, 3, entity_type, slot, fan_idx ); rec = (pas_fan_t *) dn_pas_res_get(rec_key); if (rec == 0) { /* Not found */ return (STD_ERR(PAS, NEXIST, 0)); } /* Compose respose object */ resp_obj = cps_api_object_create(); if (resp_obj == CPS_API_OBJECT_NULL) { EV_LOG_ERR(ev_log_t_PAS, 3, "PAS", "%s, allocate response object failed\n", __FUNCTION__); return (STD_ERR(PAS, NOMEM, 0)); } dn_pas_obj_key_fan_set(resp_obj, qual, true, entity_type, true, slot, true, fan_idx ); dn_pas_lock(); if ((!rec->valid || qual == cps_api_qualifier_REALTIME) && !dn_pald_diag_mode_get()) { /* Cache not valid or realtime object requested => Update cache from hardware */ dn_entity_poll(rec->parent, true); } if (rec->parent->present) { /* Add result attributes to response object */ if (qual == cps_api_qualifier_TARGET) { cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_SPEED, rec->targ_speed ); } else { cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_OPER_STATUS, rec->oper_fault_state->oper_status ); cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_FAULT_TYPE, rec->oper_fault_state->fault_type ); cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_SPEED, rec->obs_speed ); cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_SPEED_PCT, rec->max_speed != 0 ? (100 * rec->obs_speed) / rec->max_speed : 0 ); cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_MAX_SPEED, rec->max_speed ); } } dn_pas_unlock(); /* Add response object to get response */ if (!cps_api_object_list_append(param->list, resp_obj)) { cps_api_object_delete(resp_obj); return (STD_ERR(PAS, FAIL, 0)); } return (STD_ERR_OK); }
static t_std_error dn_pas_fan_set1( cps_api_transaction_params_t *param, cps_api_qualifier_t qual, uint_t entity_type, uint_t slot, uint_t fan_idx, bool speed_valid, uint_t speed, bool speed_pct_valid, uint_t speed_pct ) { cps_api_key_t rec_key[1]; pas_fan_t *rec; cps_api_object_t old_obj; pas_oper_fault_state_t prev_oper_fault_state[1]; t_std_error rc = STD_ERR_OK; uint_t targ_speed = 0; bool notif = false; /* Look up object in cache */ cps_api_key_init(rec_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_FAN_OBJ, 3, entity_type, slot, fan_idx ); rec = (pas_fan_t *) dn_pas_res_get(rec_key); if (rec == 0) { /* Not found */ return (STD_ERR(PAS, NEXIST, 0)); } *prev_oper_fault_state = *rec->oper_fault_state; old_obj = cps_api_object_create(); if (old_obj == CPS_API_OBJECT_NULL) return (STD_ERR(PAS, NOMEM, 0)); dn_pas_obj_key_fan_set(old_obj, qual, true, entity_type, true, slot, true, fan_idx ); cps_api_object_attr_add_u16(old_obj, BASE_PAS_FAN_SPEED, rec->targ_speed ); if (!cps_api_object_list_append(param->prev, old_obj)) { cps_api_object_delete(old_obj); return (STD_ERR(PAS, FAIL, 0)); } old_obj = CPS_API_OBJECT_NULL; /* No longer owned */ targ_speed = rec->targ_speed; if (speed_pct_valid) { targ_speed = (speed_pct * rec->max_speed) / 100; } if (speed_valid) targ_speed = speed; if (targ_speed == rec->targ_speed) return rc; dn_pas_lock(); if(!dn_pald_diag_mode_get()) { rc = sdi_fan_speed_set(rec->sdi_resource_hdl, targ_speed); } dn_pas_unlock(); if (STD_IS_ERR(rc)) { dn_pas_oper_fault_state_update(rec->oper_fault_state, PLATFORM_FAULT_TYPE_EHW ); } else { rec->targ_speed = targ_speed; } if (rec->oper_fault_state->oper_status != prev_oper_fault_state->oper_status) { notif = true; } if (notif) dn_fan_notify(rec); return (rc); }