1 /* SPDX-License-Identifier: LGPL-2.1-only */ 2 /* 3 * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 4 */ 5 6 #ifndef _MEDIA_INFO_H 7 #define _MEDIA_INFO_H 8 9 #include <sys/stat.h> 10 11 enum media_type { 12 MEDIA_TYPE_CANT_STAT, 13 MEDIA_TYPE_UNKNOWN, 14 MEDIA_TYPE_VIDEO, 15 MEDIA_TYPE_VBI, 16 MEDIA_TYPE_RADIO, 17 MEDIA_TYPE_SDR, 18 MEDIA_TYPE_TOUCH, 19 MEDIA_TYPE_SUBDEV, 20 MEDIA_TYPE_DVB_FRONTEND, 21 MEDIA_TYPE_DVB_DEMUX, 22 MEDIA_TYPE_DVB_DVR, 23 MEDIA_TYPE_DVB_NET, 24 MEDIA_TYPE_DTV_CA, 25 MEDIA_TYPE_MEDIA, 26 }; 27 28 /* 29 * Detect what type the device is. 30 */ 31 media_type mi_media_detect_type(const char *device); 32 33 /* 34 * Return the device name given the major and minor numbers. 35 */ 36 std::string mi_media_get_device(__u32 major, __u32 minor); 37 38 /* 39 * For a given device fd retrieve the dev_t (major/minor) value. 40 * Returns 0 if successful (and fills in *dev) and -1 on failure. 41 */ 42 int mi_get_dev_t_from_fd(int fd, dev_t *dev); 43 44 /* 45 * For a given dev_t value (major/minor), find the corresponding 46 * device name. 47 * Returns the /dev/... path if successful, or an empty string on 48 * failure. 49 */ 50 std::string mi_get_devpath_from_dev_t(dev_t dev); 51 52 /* 53 * For a given device fd return the corresponding media device 54 * or -1 if there is none. 55 * 56 * If bus_info is not NULL, then find the media device that 57 * matches the given bus_info. 58 */ 59 int mi_get_media_fd(int fd, const char *bus_info = NULL); 60 61 /* Return entity flags description */ 62 std::string mi_entflags2s(__u32 flags); 63 64 /* Return interface flags description */ 65 std::string mi_ifacetype2s(__u32 type); 66 67 /* Return true if this function requires an interface */ 68 bool mi_func_requires_intf(__u32 function); 69 70 /* Return function description */ 71 std::string mi_entfunction2s(__u32 function, bool *is_invalid = NULL); 72 73 /* Return pad flags description */ 74 std::string mi_padflags2s(__u32 flags); 75 76 /* Return link flags description */ 77 std::string mi_linkflags2s(__u32 flags); 78 79 /* 80 * Show media controller information media_fd and (if >= 0) the 81 * corresponding entity/interface information for the fd. 82 * 83 * If is_invalid != NULL, then set it to true if errors are detected 84 * in the media information. 85 * 86 * If function != NULL, then set it to the function of the entity to 87 * which the interface is connected. 88 * 89 * Return 0 if the driver doesn't support MEDIA_IOC_G_TOPOLOGY. 90 * Return MEDIA_ENT_F_UNKNOWN if it does support this but there were 91 * errors reading the topology. Otherwise return the entity ID of fd. 92 */ 93 __u32 mi_media_info_for_fd(int media_fd, int fd, bool *is_invalid = NULL, __u32 *function = NULL); 94 95 #endif 96