@@ -106,6 +106,36 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk)
return container_of(sk, struct qrtr_sock, sk);
}
+int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id)
+{
+ struct cmsghdr *cmsg;
+ u32 endpoint_id = 0;
+
+ for_each_cmsghdr(cmsg, msg) {
+ if (!CMSG_OK(msg, cmsg))
+ return -EINVAL;
+
+ if (cmsg->cmsg_level != SOL_QRTR)
+ continue;
+
+ if (cmsg->cmsg_type != QRTR_ENDPOINT)
+ return -EINVAL;
+
+ if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
+ return -EINVAL;
+
+ /* Endpoint ids start at 1 */
+ endpoint_id = *(u32 *)CMSG_DATA(cmsg);
+ if (!endpoint_id)
+ return -EINVAL;
+ }
+
+ if (out_endpoint_id)
+ *out_endpoint_id = endpoint_id;