Beispiel #1
0
bool dn_cache_init_fan_tray(void)
{
    uint_t         slot, n;
    cps_api_key_t  key[1];
    pas_entity_t   *parent;
    pas_fan_tray_t *data;

    for (slot = 1, n = sdi_entity_count_get(SDI_ENTITY_FAN_TRAY);
         n;
         --n, ++slot
         ) {
        cps_api_key_init(key,
                         cps_api_qualifier_OBSERVED,
                         cps_api_obj_CAT_BASE_PAS, 
                         BASE_PAS_ENTITY_OBJ,
                         2,
                         PLATFORM_ENTITY_TYPE_FAN_TRAY,
                         slot
                         );
        parent = dn_pas_res_get(key);
        if (parent == 0) {
            return (false);
        }

        cps_api_key_init(key,
                         cps_api_qualifier_OBSERVED,
                         cps_api_obj_CAT_BASE_PAS, 
                         BASE_PAS_FAN_TRAY_OBJ,
                         1,
                         slot
                         );
        
        data = CALLOC_T(pas_fan_tray_t, 1);
        if (data == 0) {
            return (false);
        }

        data->parent = parent;

        if (!dn_pas_res_insert(key, data)) {
            free(data);

            return (false);
        }
    }

    return (true);
}
Beispiel #2
0
void dn_led_res_key_name(
    char     *buf,
    unsigned bufsize,
    uint_t   entity_type,
    uint_t   slot,
    char     *led_name,
    unsigned led_name_len
                            )
{
    cps_api_key_t key[1];
    uint_t        n;

    cps_api_key_init(key,
                     cps_api_qualifier_OBSERVED,
                     cps_api_obj_CAT_BASE_PAS, 
                     BASE_PAS_LED_OBJ,
                     2,
                     entity_type,
                     slot
                     );

    cps_api_key_print(key, buf, bufsize);

    n = strlen(buf);
    memcpy(buf + n, led_name, led_name_len);
    buf[n + led_name_len] = 0;
}
Beispiel #3
0
void dn_cache_del_led(pas_entity_t *parent)
{
    char          ckey[PAS_CPS_KEY_STR_LEN];
    cps_api_key_t cps_key[1];
    uint_t        led_idx;
    pas_led_t     *rec;

    for (led_idx = 1; led_idx <= parent->num_leds; ++led_idx) {
        cps_api_key_init(cps_key,
                         cps_api_qualifier_OBSERVED,
                         cps_api_obj_CAT_BASE_PAS, 
                         BASE_PAS_LED_OBJ,
                         3,
                         parent->entity_type,
                         parent->slot,
                         led_idx
                         );

        rec = dn_pas_res_remove(cps_key);

        dn_led_res_key_name(ckey, sizeof(ckey), 
                            parent->entity_type,
                            parent->slot,
                            rec->name,
                            rec->name_len
                            );
        
        dn_pas_res_removec(ckey);

        free(rec);
    }
}
t_std_error ds_api_linux_route_init(cps_api_operation_handle_t handle) {
    cps_api_registration_functions_t f;
    memset(&f,0,sizeof(f));
    f.handle = handle;
    f._read_function = db_read_function;
    f._write_function = _write_function;

    cps_api_key_init(&f.key,cps_api_qualifier_TARGET,cps_api_obj_cat_ROUTE,cps_api_route_obj_ROUTE,0);
    cps_api_return_code_t rc = cps_api_register(&f);
    if (rc!=cps_api_ret_code_OK) {
        return STD_ERR(INTERFACE,FAIL,rc);
    }

    f._read_function = NULL;
    cps_api_key_init(&f.key,cps_api_qualifier_TARGET,cps_api_obj_cat_ROUTE,cps_api_route_obj_EVENT,0);
    rc = cps_api_register(&f);

    return STD_ERR_OK_IF_TRUE(rc==cps_api_ret_code_OK,STD_ERR(INTERFACE,FAIL,rc));
}
t_std_error ds_api_linux_interface_init(cps_api_operation_handle_t handle) {
    cps_api_registration_functions_t f;
    memset(&f,0,sizeof(f));
    f.handle = handle;
    f._read_function = ds_api_linux_interface_get_function;
    f._write_function = ds_api_linux_interface_set_function;
    cps_api_key_init(&f.key,cps_api_qualifier_TARGET,cps_api_obj_cat_INTERFACE,0,0);

    cps_api_return_code_t rc = cps_api_register(&f);
    return STD_ERR_OK_IF_TRUE(rc==cps_api_ret_code_OK,STD_ERR(INTERFACE,FAIL,rc));
}
void key_add(size_t *_k_data, size_t pos, size_t mx) {
    if (pos >= 5) return;
    for (int a = 0, _a = 10; a < _a ; ++a ) {
        _k_data[pos] = a;
        key_add(_k_data,pos+1,mx);
        if ((pos+1) == 4) {
            cps_api_key_t *key = (cps_api_key_t*)calloc(1,sizeof(cps_api_key_t));
            cps_api_key_init(key,(cps_api_qualifier_t)(_k_data[0]+1),_k_data[1]+1,_k_data[2]+1,2,_k_data[3],_k_data[4]);

            char b1[100];
            printf("Adding for test.. %s\n",cps_api_key_print(key,b1,sizeof(b1)));
            lst.push_back(key);
        }
    }
}
static cps_api_return_code_t db_read_function (void * context, cps_api_get_params_t * param, size_t key_ix) {
    cps_api_return_code_t rc = cps_api_ret_code_OK;
    cps_api_key_t key;
    cps_api_key_init(&key,cps_api_qualifier_TARGET,
            cps_api_obj_cat_ROUTE, cps_api_route_obj_ROUTE, 0);
    if (cps_api_key_matches(&param->keys[key_ix], &key,false)!=0) {
        return cps_api_ret_code_OK;
    }

    route_filter_t rf;
    memset(&rf,0,sizeof(rf));
    //!TODO need to handle the filter requests (using the received key)
    read_all_routes(param->list,&rf);

    return rc;
}
Beispiel #8
0
pas_led_t *dn_pas_led_rec_get_idx(
    uint_t entity_type,
    uint_t slot,
    uint_t led_idx
                                                         )
{
    cps_api_key_t rec_key[1];

    cps_api_key_init(rec_key,
                     cps_api_qualifier_OBSERVED,
                     cps_api_obj_CAT_BASE_PAS, 
                     BASE_PAS_LED_OBJ,
                     3,
                     entity_type,
                     slot,
                     led_idx
                     );

    return ((pas_led_t *) dn_pas_res_get(rec_key));
}
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;
}
static t_std_error _cps_init ()
{
    cps_api_operation_handle_t       handle;
    cps_api_return_code_t            rc;
    cps_api_registration_functions_t f;

    rc = cps_api_operation_subsystem_init (&handle,1);

    if (rc != cps_api_ret_code_OK) {
        NAS_ACL_LOG_ERR ("NAS ACL CPS Subsystem Init failed");
        return STD_ERR(QOS, FAIL, rc);
    }

    memset (&f, 0, sizeof(f));

    f.handle             = handle;
    f._read_function     = nas_acl_cps_api_read;
    f._write_function    = nas_acl_cps_api_write;
    f._rollback_function = nas_acl_cps_api_rollback;

    /*
     * Register all ACL objects
     * TODO: Need to check with CPS app teams, if ACL needs to register for
     * OBSERVED state.
     */
    cps_api_key_init (&f.key,
                      cps_api_qualifier_TARGET,
                      cps_api_obj_CAT_BASE_ACL,
                      0, /* register all sub-categories */
                      0);

    rc = cps_api_register (&f);

    if (rc != cps_api_ret_code_OK) {
        NAS_ACL_LOG_ERR ("NAS ACL CPS object Register failed");
        return STD_ERR(QOS, FAIL, rc);
    }

    return STD_ERR_OK;
}
Beispiel #11
0
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);
}
Beispiel #12
0
static t_std_error nas_os_publish_route(int rt_msg_type, cps_api_object_t obj)
{
    static char buff[MAX_CPS_MSG_SIZE];

    cps_api_object_t new_obj = cps_api_object_init(buff,sizeof(buff));
    cps_api_key_init(cps_api_object_key(new_obj),cps_api_qualifier_TARGET,
            cps_api_obj_cat_ROUTE,cps_api_route_obj_ROUTE,0 );

    cps_api_object_attr_t prefix   = cps_api_object_attr_get(obj, BASE_ROUTE_OBJ_ENTRY_ROUTE_PREFIX);
    cps_api_object_attr_t af       = cps_api_object_attr_get(obj, BASE_ROUTE_OBJ_ENTRY_AF);
    cps_api_object_attr_t pref_len = cps_api_object_attr_get(obj, BASE_ROUTE_OBJ_ENTRY_PREFIX_LEN);
    cps_api_object_attr_t nh_count = cps_api_object_attr_get(obj, BASE_ROUTE_OBJ_ENTRY_NH_COUNT);

    if(rt_msg_type == RTM_NEWROUTE) {
        cps_api_object_attr_add_u32(new_obj, cps_api_if_ROUTE_A_MSG_TYPE,ROUTE_ADD);
    } else if(rt_msg_type == RTM_DELROUTE) {
        cps_api_object_attr_add_u32(new_obj, cps_api_if_ROUTE_A_MSG_TYPE,ROUTE_DEL);
    } else {
        return false;
    }

    cps_api_object_attr_add_u32(new_obj,cps_api_if_ROUTE_A_FAMILY,
            cps_api_object_attr_data_u32(af));

    uint32_t addr_len;
    hal_ip_addr_t ip;
    if(cps_api_object_attr_data_u32(af) == AF_INET) {
        struct in_addr *inp = (struct in_addr *) cps_api_object_attr_data_bin(prefix);
        std_ip_from_inet(&ip,inp);
        addr_len = HAL_INET4_LEN;
    } else {
        struct in6_addr *inp6 = (struct in6_addr *) cps_api_object_attr_data_bin(prefix);
        std_ip_from_inet6(&ip,inp6);
        addr_len = HAL_INET6_LEN;
    }

    cps_api_attr_id_t attr = cps_api_if_ROUTE_A_PREFIX;
    cps_api_object_e_add(new_obj, &attr, 1, cps_api_object_ATTR_T_BIN, &ip, sizeof(ip));

    cps_api_object_attr_add_u32(new_obj,cps_api_if_ROUTE_A_PREFIX_LEN,
            cps_api_object_attr_data_u32(pref_len));

    uint32_t nhc = 0;
    if (nh_count != CPS_API_ATTR_NULL) nhc = cps_api_object_attr_data_u32(nh_count);

    if (nhc == 1) {
        cps_api_object_attr_add_u32(new_obj,cps_api_if_ROUTE_A_HOP_COUNT,nhc);

        cps_api_attr_id_t ids[3] = { BASE_ROUTE_OBJ_ENTRY_NH_LIST,
                                 0, BASE_ROUTE_OBJ_ENTRY_NH_LIST_NH_ADDR};
        const int ids_len = sizeof(ids)/sizeof(*ids);

        cps_api_object_attr_t gw = cps_api_object_e_get(obj,ids,ids_len);

        ids[2] = BASE_ROUTE_OBJ_ENTRY_NH_LIST_IFINDEX;
        cps_api_object_attr_t gwix = cps_api_object_e_get(obj,ids,ids_len);

        cps_api_attr_id_t new_ids[3];
        new_ids[0] = cps_api_if_ROUTE_A_NH;
        new_ids[1] = 0;

        if (gw != CPS_API_ATTR_NULL) {
            new_ids[2] = cps_api_if_ROUTE_A_NEXT_HOP_ADDR;

            hal_ip_addr_t ip;
            if(addr_len == HAL_INET4_LEN) {
                ip.af_index = AF_INET;
                memcpy(&(ip.u.v4_addr), cps_api_object_attr_data_bin(gw),addr_len);
            } else {
                ip.af_index = AF_INET6;
                memcpy(&(ip.u.v6_addr), cps_api_object_attr_data_bin(gw),addr_len);
            }
            cps_api_object_e_add(new_obj, new_ids, ids_len, cps_api_object_ATTR_T_BIN,
                    &ip,sizeof(ip));
        }

        if (gwix != CPS_API_ATTR_NULL) {
            new_ids[2] = cps_api_if_ROUTE_A_NH_IFINDEX;
            uint32_t gw_idx = cps_api_object_attr_data_u32(gwix);
            cps_api_object_e_add(new_obj,new_ids,ids_len,cps_api_object_ATTR_T_U32,
                     (void *)&gw_idx, sizeof(uint32_t));
        }
    }

    EV_LOG(INFO, NAS_OS, 2,"ROUTE-UPD","Publishing object");

    net_publish_event(new_obj);

    return STD_ERR_OK;
}
Beispiel #13
0
void dn_cache_init_led(
    sdi_resource_hdl_t sdi_resource_hdl,
    void               *data
                       )
{
    pas_entity_t  *parent = (pas_entity_t *) data;
    const char    *led_name;
    char          ckey[PAS_CPS_KEY_STR_LEN];
    cps_api_key_t cps_key[1];
    pas_led_t     *rec;

    ++parent->num_leds;

    rec = CALLOC_T(pas_led_t, 1);
    if (rec == 0)  return;

    led_name = sdi_resource_alias_get(sdi_resource_hdl);

    rec->parent           = parent;
    rec->led_idx          = parent->num_leds;
    STRLCPY(rec->name, led_name);
    rec->name_len         = strlen(rec->name);
    rec->sdi_resource_hdl = sdi_resource_hdl;

    dn_pas_oper_fault_state_init(rec->oper_fault_state);

    dn_led_res_key_name(ckey, sizeof(ckey), 
                        parent->entity_type,
                        parent->slot,
                        rec->name,
                        rec->name_len
                        );

    if (!dn_pas_res_insertc(ckey, rec)) {
        free(rec);

        return;
    }

    cps_api_key_init(cps_key,
                     cps_api_qualifier_OBSERVED,
                     cps_api_obj_CAT_BASE_PAS, 
                     BASE_PAS_LED_OBJ,
                     3,
                     parent->entity_type,
                     parent->slot,
                     rec->led_idx
                     );

    if (!dn_pas_res_insert(cps_key, rec)) {
        dn_pas_res_removec(ckey);
        free(rec);

        return;
    }

    /* Set LED to default */

    struct pas_config_led *cfg = dn_pas_config_led_get(parent->entity_type, rec->name);
    (*(cfg != 0 && cfg->deflt ? sdi_led_on : sdi_led_off))(sdi_resource_hdl);
}
//db_route_t
bool nl_to_route_info(int rt_msg_type, struct nlmsghdr *hdr, cps_api_object_t obj) {

    struct rtmsg    *rtmsg = (struct rtmsg *)NLMSG_DATA(hdr);
    char            addr_str[INET6_ADDRSTRLEN];

    if(hdr->nlmsg_len < NLMSG_LENGTH(sizeof(*rtmsg)))
        return false;

    if(rt_msg_type == RTM_NEWROUTE) {
        cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_MSG_TYPE,ROUTE_ADD);
    } else if(rt_msg_type == RTM_DELROUTE) {
        cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_MSG_TYPE,ROUTE_DEL);
    } else {
        return false;
    }

    cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_PROTOCOL,rtmsg->rtm_protocol);

    cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_FAMILY,rtmsg->rtm_family);


    int attr_len = nlmsg_attrlen(hdr,sizeof(*rtmsg));
    struct nlattr *head = nlmsg_attrdata(hdr, sizeof(struct rtmsg));

    struct nlattr *attrs[__IFLA_MAX];
    memset(attrs,0,sizeof(attrs));

    if (nla_parse(attrs,__IFLA_MAX,head,attr_len)!=0) {
        EV_LOG(ERR,ROUTE,0,"NL-ROUTE-PARSE","Failed to parse attributes");
        return false;
    }

    cps_api_key_init(cps_api_object_key(obj),cps_api_qualifier_TARGET,
            cps_api_obj_cat_ROUTE,cps_api_route_obj_ROUTE,0 );

    if(attrs[RTA_DST]!=NULL) {
        rta_add_ip((struct nlattr*)attrs[RTA_DST],rtmsg->rtm_family,
                obj,cps_api_if_ROUTE_A_PREFIX);
    }

    if((rtmsg->rtm_flags & RTM_F_CLONED) && (rtmsg->rtm_family == AF_INET6)) {
        // Skip cloned route updates
        char addr_str[INET6_ADDRSTRLEN];
        EV_LOG(INFO, NETLINK,3,"ROUTE-EVENT","Cache entry %s",
                (attrs[RTA_DST]!=NULL)?(inet_ntop(rtmsg->rtm_family,
                ((struct in6_addr *) nla_data((struct nlattr*)attrs[RTA_DST])),
                addr_str, INET6_ADDRSTRLEN)):"");
        return false;
    }

    cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_PREFIX_LEN,rtmsg->rtm_dst_len);
    size_t hop_count = 0;

    cps_api_attr_id_t ids[3];

    const int ids_len = sizeof(ids)/sizeof(*ids);
    ids[0] = cps_api_if_ROUTE_A_NH;
    ids[1] = hop_count;

    if (attrs[RTA_GATEWAY]!=NULL) {
        ids[2] = cps_api_if_ROUTE_A_NEXT_HOP_ADDR;
        rta_add_e_ip((struct nlattr*)attrs[RTA_GATEWAY],
                rtmsg->rtm_family,obj, ids,ids_len);

        rta_add_ip((struct nlattr*)attrs[RTA_GATEWAY],rtmsg->rtm_family,obj,
                cps_api_if_ROUTE_A_NEXT_HOP_ADDR);
    }

    if (attrs[RTA_OIF]!=NULL) {
        ids[2] = cps_api_if_ROUTE_A_NH_IFINDEX;
        unsigned int *x = (unsigned int *) nla_data(attrs[RTA_OIF]);

        cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,
                nla_data(attrs[RTA_OIF]),sizeof(uint32_t));

        cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_NH_IFINDEX,*x);
    }
    nas_os_log_route_info(rt_msg_type, rtmsg, attrs);
    if (attrs[RTA_MULTIPATH]) {
        //array of next hops
        struct rtnexthop * rtnh = (struct rtnexthop * )nla_data(attrs[RTA_MULTIPATH]);
        int remaining = nla_len(attrs[RTA_MULTIPATH]);
        while (RTNH_OK(rtnh, remaining)) {
            ids[1] = hop_count;
            ids[2] = cps_api_if_ROUTE_A_NH_IFINDEX;
            uint32_t _int = rtnh->rtnh_ifindex;
            cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,
                    &rtnh->rtnh_ifindex,sizeof(uint32_t));

            _int = rtnh->rtnh_flags;
            ids[2] = cps_api_if_ROUTE_A_NEXT_HOP_FLAGS;
            cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,
                    &_int,sizeof(uint32_t));

            ids[2] = cps_api_if_ROUTE_A_NEXT_HOP_WEIGHT;
            _int = rtnh->rtnh_hops;
            cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,
                    &_int,sizeof(uint32_t));

            struct nlattr *nhattr[__RTA_MAX];
            memset(nhattr,0,sizeof(nhattr));
            nhrt_parse(nhattr,__IFLA_MAX,rtnh);
            if (nhattr[RTA_GATEWAY]) {
                ids[2] = cps_api_if_ROUTE_A_NEXT_HOP_ADDR;
                rta_add_e_ip((struct nlattr*)nhattr[RTA_GATEWAY],
                             rtmsg->rtm_family,obj, ids,ids_len);
                EV_LOG(INFO, NETLINK,3,"ROUTE-EVENT","MultiPath nh-cnt:%d gateway:%s ifIndex:%d nh-flags:0x%x weight:%d",
                       hop_count,
                       ((rtmsg->rtm_family == AF_INET) ?
                        (inet_ntop(rtmsg->rtm_family, ((struct in_addr *) nla_data((struct nlattr*)nhattr[RTA_GATEWAY])), addr_str,
                                   INET_ADDRSTRLEN)) :
                        (inet_ntop(rtmsg->rtm_family, ((struct in6_addr *) nla_data((struct nlattr*)nhattr[RTA_GATEWAY])),
                                   addr_str, INET6_ADDRSTRLEN))),
                        rtnh->rtnh_ifindex, rtnh->rtnh_flags, rtnh->rtnh_hops);
            } else {
                EV_LOG(INFO, NETLINK,3,"ROUTE-EVENT","MultiPath nh-cnt:%d ifIndex:%d nh-flags:0x%x weight:%d",
                       hop_count, rtnh->rtnh_ifindex, rtnh->rtnh_flags, rtnh->rtnh_hops);
            }
            rtnh = rtnh_next(rtnh,&remaining);
            ++hop_count;
        }

    } else {
        ++hop_count;
    }
    cps_api_object_attr_add_u32(obj,cps_api_if_ROUTE_A_HOP_COUNT,hop_count);

    return true;
}
Beispiel #15
0
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);
}
Beispiel #16
0
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);
}