1 // SPDX-License-Identifier: LGPL-2.1+
9 #include "thermal_nl.h"
11 static int handle_thermal_sample(struct nl_msg *n, void *arg)
13 struct nlmsghdr *nlh = nlmsg_hdr(n);
14 struct genlmsghdr *genlhdr = genlmsg_hdr(nlh);
15 struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1];
16 struct thermal_handler_param *thp = arg;
17 struct thermal_handler *th = thp->th;
19 genlmsg_parse(nlh, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL);
21 switch (genlhdr->cmd) {
23 case THERMAL_GENL_SAMPLING_TEMP:
24 return th->ops->sampling.tz_temp(
25 nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]),
26 nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TEMP]), arg);
32 thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg)
34 struct thermal_handler_param thp = { .th = th, .arg = arg };
39 if (nl_cb_set(th->cb_sampling, NL_CB_VALID, NL_CB_CUSTOM,
40 handle_thermal_sample, &thp))
43 return nl_recvmsgs(th->sk_sampling, th->cb_sampling);
46 int thermal_sampling_fd(struct thermal_handler *th)
51 return nl_socket_get_fd(th->sk_sampling);
54 thermal_error_t thermal_sampling_exit(struct thermal_handler *th)
56 if (nl_unsubscribe_thermal(th->sk_sampling, th->cb_sampling,
57 THERMAL_GENL_SAMPLING_GROUP_NAME))
60 nl_thermal_disconnect(th->sk_sampling, th->cb_sampling);
62 return THERMAL_SUCCESS;
65 thermal_error_t thermal_sampling_init(struct thermal_handler *th)
67 if (nl_thermal_connect(&th->sk_sampling, &th->cb_sampling))
70 if (nl_subscribe_thermal(th->sk_sampling, th->cb_sampling,
71 THERMAL_GENL_SAMPLING_GROUP_NAME))
74 return THERMAL_SUCCESS;