devices.c revision 0dd7ca6e87abb689700c5e3a816a949b03b1154b
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <errno.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22
23#include <fcntl.h>
24#include <dirent.h>
25#include <unistd.h>
26#include <string.h>
27
28#include <sys/socket.h>
29#include <sys/un.h>
30#include <linux/netlink.h>
31#include <private/android_filesystem_config.h>
32#include <sys/time.h>
33#include <asm/page.h>
34
35#include "init.h"
36#include "devices.h"
37
38#define CMDLINE_PREFIX  "/dev"
39#define SYSFS_PREFIX    "/sys"
40#define FIRMWARE_DIR    "/etc/firmware"
41#define MAX_QEMU_PERM 6
42
43static int device_fd = -1;
44
45struct uevent {
46    const char *action;
47    const char *path;
48    const char *subsystem;
49    const char *firmware;
50    int major;
51    int minor;
52};
53
54static int open_uevent_socket(void)
55{
56    struct sockaddr_nl addr;
57    int sz = 64*1024; // XXX larger? udev uses 16MB!
58    int s;
59
60    memset(&addr, 0, sizeof(addr));
61    addr.nl_family = AF_NETLINK;
62    addr.nl_pid = getpid();
63    addr.nl_groups = 0xffffffff;
64
65    s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
66    if(s < 0)
67        return -1;
68
69    setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
70
71    if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
72        close(s);
73        return -1;
74    }
75
76    return s;
77}
78
79struct perms_ {
80    char *name;
81    mode_t perm;
82    unsigned int uid;
83    unsigned int gid;
84    unsigned short prefix;
85};
86static struct perms_ devperms[] = {
87    { "/dev/null",          0666,   AID_ROOT,       AID_ROOT,       0 },
88    { "/dev/zero",          0666,   AID_ROOT,       AID_ROOT,       0 },
89    { "/dev/full",          0666,   AID_ROOT,       AID_ROOT,       0 },
90    { "/dev/ptmx",          0666,   AID_ROOT,       AID_ROOT,       0 },
91    { "/dev/tty",           0666,   AID_ROOT,       AID_ROOT,       0 },
92    { "/dev/random",        0666,   AID_ROOT,       AID_ROOT,       0 },
93    { "/dev/urandom",       0666,   AID_ROOT,       AID_ROOT,       0 },
94    { "/dev/ashmem",        0666,   AID_ROOT,       AID_ROOT,       0 },
95    { "/dev/binder",        0666,   AID_ROOT,       AID_ROOT,       0 },
96
97	    /* logger should be world writable (for logging) but not readable */
98    { "/dev/log/",          0662,   AID_ROOT,       AID_LOG,        1 },
99
100    /* the msm hw3d client device node is world writable/readable. */
101    { "/dev/msm_hw3dc",     0666,   AID_ROOT,       AID_ROOT,       0 },
102
103    /* gpu driver for adreno200 is globally accessible */
104    { "/dev/kgsl",          0666,   AID_ROOT,       AID_ROOT,       0 },
105
106        /* these should not be world writable */
107    { "/dev/diag",          0660,   AID_RADIO,      AID_RADIO,        0 },
108    { "/dev/diag_arm9",     0660,   AID_RADIO,      AID_RADIO,        0 },
109    { "/dev/android_adb",   0660,   AID_ADB,        AID_ADB,        0 },
110    { "/dev/android_adb_enable",   0660,   AID_ADB,        AID_ADB,        0 },
111    { "/dev/ttyMSM0",       0600,   AID_BLUETOOTH,  AID_BLUETOOTH,  0 },
112    { "/dev/ttyHS0",        0600,   AID_BLUETOOTH,  AID_BLUETOOTH,  0 },
113    { "/dev/uinput",        0660,   AID_SYSTEM,     AID_BLUETOOTH,  0 },
114    { "/dev/alarm",         0664,   AID_SYSTEM,     AID_RADIO,      0 },
115    { "/dev/tty0",          0660,   AID_ROOT,       AID_SYSTEM,     0 },
116    { "/dev/graphics/",     0660,   AID_ROOT,       AID_GRAPHICS,   1 },
117    { "/dev/msm_hw3dm",     0660,   AID_SYSTEM,     AID_GRAPHICS,   0 },
118    { "/dev/input/",        0660,   AID_ROOT,       AID_INPUT,      1 },
119    { "/dev/eac",           0660,   AID_ROOT,       AID_AUDIO,      0 },
120    { "/dev/cam",           0660,   AID_ROOT,       AID_CAMERA,     0 },
121    { "/dev/pmem",          0660,   AID_SYSTEM,     AID_GRAPHICS,   0 },
122    { "/dev/pmem_adsp",     0660,   AID_SYSTEM,     AID_AUDIO,      1 },
123    { "/dev/pmem_camera",   0660,   AID_SYSTEM,     AID_CAMERA,     1 },
124    { "/dev/oncrpc/",       0660,   AID_ROOT,       AID_SYSTEM,     1 },
125    { "/dev/adsp/",         0660,   AID_SYSTEM,     AID_AUDIO,      1 },
126    { "/dev/snd/",          0660,   AID_SYSTEM,     AID_AUDIO,      1 },
127    { "/dev/mt9t013",       0660,   AID_SYSTEM,     AID_SYSTEM,     0 },
128    { "/dev/msm_camera/",   0660,   AID_SYSTEM,     AID_SYSTEM,     1 },
129    { "/dev/akm8976_daemon",0640,   AID_COMPASS,    AID_SYSTEM,     0 },
130    { "/dev/akm8976_aot",   0640,   AID_COMPASS,    AID_SYSTEM,     0 },
131    { "/dev/akm8973_daemon",0640,   AID_COMPASS,    AID_SYSTEM,     0 },
132    { "/dev/akm8973_aot",   0640,   AID_COMPASS,    AID_SYSTEM,     0 },
133    { "/dev/bma150",        0640,   AID_COMPASS,    AID_SYSTEM,     0 },
134    { "/dev/cm3602",        0640,   AID_COMPASS,    AID_SYSTEM,     0 },
135    { "/dev/akm8976_pffd",  0640,   AID_COMPASS,    AID_SYSTEM,     0 },
136    { "/dev/lightsensor",   0640,   AID_SYSTEM,     AID_SYSTEM,     0 },
137    { "/dev/msm_pcm_out",   0660,   AID_SYSTEM,     AID_AUDIO,      1 },
138    { "/dev/msm_pcm_in",    0660,   AID_SYSTEM,     AID_AUDIO,      1 },
139    { "/dev/msm_pcm_ctl",   0660,   AID_SYSTEM,     AID_AUDIO,      1 },
140    { "/dev/msm_snd",       0660,   AID_SYSTEM,     AID_AUDIO,      1 },
141    { "/dev/msm_mp3",       0660,   AID_SYSTEM,     AID_AUDIO,      1 },
142    { "/dev/audience_a1026", 0660,   AID_SYSTEM,     AID_AUDIO,      1 },
143    { "/dev/tpa2018d1",     0660,   AID_SYSTEM,     AID_AUDIO,      1 },
144    { "/dev/msm_audpre",    0660,   AID_SYSTEM,     AID_AUDIO,      0 },
145    { "/dev/msm_audio_ctl", 0660,   AID_SYSTEM,     AID_AUDIO,      0 },
146    { "/dev/htc-acoustic",  0660,   AID_SYSTEM,     AID_AUDIO,      0 },
147    { "/dev/vdec",          0660,   AID_SYSTEM,     AID_AUDIO,      0 },
148    { "/dev/q6venc",        0660,   AID_SYSTEM,     AID_AUDIO,      0 },
149    { "/dev/snd/dsp",       0660,   AID_SYSTEM,     AID_AUDIO,      0 },
150    { "/dev/snd/dsp1",      0660,   AID_SYSTEM,     AID_AUDIO,      0 },
151    { "/dev/snd/mixer",     0660,   AID_SYSTEM,     AID_AUDIO,      0 },
152    { "/dev/smd0",          0640,   AID_RADIO,      AID_RADIO,      0 },
153    { "/dev/qemu_trace",    0666,   AID_SYSTEM,     AID_SYSTEM,     0 },
154    { "/dev/qmi",           0640,   AID_RADIO,      AID_RADIO,      0 },
155    { "/dev/qmi0",          0640,   AID_RADIO,      AID_RADIO,      0 },
156    { "/dev/qmi1",          0640,   AID_RADIO,      AID_RADIO,      0 },
157    { "/dev/qmi2",          0640,   AID_RADIO,      AID_RADIO,      0 },
158        /* CDMA radio interface MUX */
159    { "/dev/ts0710mux",     0640,   AID_RADIO,      AID_RADIO,      1 },
160    { "/dev/ppp",           0660,   AID_RADIO,      AID_VPN,        0 },
161    { "/dev/tun",           0640,   AID_VPN,        AID_VPN,        0 },
162    { NULL, 0, 0, 0, 0 },
163};
164
165/* devperms_partners list and perm_node are for hardware specific /dev entries */
166struct perm_node {
167    struct perms_ dp;
168    struct listnode plist;
169};
170list_declare(devperms_partners);
171
172/*
173 * Permission override when in emulator mode, must be parsed before
174 * system properties is initalized.
175 */
176static int qemu_perm_count;
177static struct perms_ qemu_perms[MAX_QEMU_PERM + 1];
178
179int add_devperms_partners(const char *name, mode_t perm, unsigned int uid,
180                        unsigned int gid, unsigned short prefix) {
181    int size;
182    struct perm_node *node = malloc(sizeof (struct perm_node));
183    if (!node)
184        return -ENOMEM;
185
186    size = strlen(name) + 1;
187    if ((node->dp.name = malloc(size)) == NULL)
188        return -ENOMEM;
189
190    memcpy(node->dp.name, name, size);
191    node->dp.perm = perm;
192    node->dp.uid = uid;
193    node->dp.gid = gid;
194    node->dp.prefix = prefix;
195
196    list_add_tail(&devperms_partners, &node->plist);
197    return 0;
198}
199
200void qemu_init(void) {
201    qemu_perm_count = 0;
202    memset(&qemu_perms, 0, sizeof(qemu_perms));
203}
204
205static int qemu_perm(const char* name, mode_t perm, unsigned int uid,
206                         unsigned int gid, unsigned short prefix)
207{
208    char *buf;
209    if (qemu_perm_count == MAX_QEMU_PERM)
210        return -ENOSPC;
211
212    buf = malloc(strlen(name) + 1);
213    if (!buf)
214        return -errno;
215
216    strlcpy(buf, name, strlen(name) + 1);
217    qemu_perms[qemu_perm_count].name = buf;
218    qemu_perms[qemu_perm_count].perm = perm;
219    qemu_perms[qemu_perm_count].uid = uid;
220    qemu_perms[qemu_perm_count].gid = gid;
221    qemu_perms[qemu_perm_count].prefix = prefix;
222
223    qemu_perm_count++;
224    return 0;
225}
226
227/* Permission overrides for emulator that are parsed from /proc/cmdline. */
228void qemu_cmdline(const char* name, const char *value)
229{
230    char *buf;
231    if (!strcmp(name, "android.ril")) {
232        /* cmd line params currently assume /dev/ prefix */
233        if (asprintf(&buf, CMDLINE_PREFIX"/%s", value) == -1) {
234            return;
235        }
236        INFO("nani- buf:: %s\n", buf);
237        qemu_perm(buf, 0660, AID_RADIO, AID_ROOT, 0);
238    }
239}
240
241static int get_device_perm_inner(struct perms_ *perms, const char *path,
242                                    unsigned *uid, unsigned *gid, mode_t *perm)
243{
244    int i;
245    for(i = 0; perms[i].name; i++) {
246
247        if(perms[i].prefix) {
248            if(strncmp(path, perms[i].name, strlen(perms[i].name)))
249                continue;
250        } else {
251            if(strcmp(path, perms[i].name))
252                continue;
253        }
254        *uid = perms[i].uid;
255        *gid = perms[i].gid;
256        *perm = perms[i].perm;
257        return 0;
258    }
259    return -1;
260}
261
262/* First checks for emulator specific permissions specified in /proc/cmdline. */
263static mode_t get_device_perm(const char *path, unsigned *uid, unsigned *gid)
264{
265    mode_t perm;
266
267    if (get_device_perm_inner(qemu_perms, path, uid, gid, &perm) == 0) {
268        return perm;
269    } else if (get_device_perm_inner(devperms, path, uid, gid, &perm) == 0) {
270        return perm;
271    } else {
272        struct listnode *node;
273        struct perm_node *perm_node;
274        struct perms_ *dp;
275
276        /* Check partners list. */
277        list_for_each(node, &devperms_partners) {
278            perm_node = node_to_item(node, struct perm_node, plist);
279            dp = &perm_node->dp;
280
281            if (dp->prefix) {
282                if (strncmp(path, dp->name, strlen(dp->name)))
283                    continue;
284            } else {
285                if (strcmp(path, dp->name))
286                    continue;
287            }
288            /* Found perm in partner list. */
289            *uid = dp->uid;
290            *gid = dp->gid;
291            return dp->perm;
292        }
293        /* Default if nothing found. */
294        *uid = 0;
295        *gid = 0;
296        return 0600;
297    }
298}
299
300static void make_device(const char *path, int block, int major, int minor)
301{
302    unsigned uid;
303    unsigned gid;
304    mode_t mode;
305    dev_t dev;
306
307    if(major > 255 || minor > 255)
308        return;
309
310    mode = get_device_perm(path, &uid, &gid) | (block ? S_IFBLK : S_IFCHR);
311    dev = (major << 8) | minor;
312    /* Temporarily change egid to avoid race condition setting the gid of the
313     * device node. Unforunately changing the euid would prevent creation of
314     * some device nodes, so the uid has to be set with chown() and is still
315     * racy. Fixing the gid race at least fixed the issue with system_server
316     * opening dynamic input devices under the AID_INPUT gid. */
317    setegid(gid);
318    mknod(path, mode, dev);
319    chown(path, uid, -1);
320    setegid(AID_ROOT);
321}
322
323#if LOG_UEVENTS
324
325static inline suseconds_t get_usecs(void)
326{
327    struct timeval tv;
328    gettimeofday(&tv, 0);
329    return tv.tv_sec * (suseconds_t) 1000000 + tv.tv_usec;
330}
331
332#define log_event_print(x...) INFO(x)
333
334#else
335
336#define log_event_print(fmt, args...)   do { } while (0)
337#define get_usecs()                     0
338
339#endif
340
341static void parse_event(const char *msg, struct uevent *uevent)
342{
343    uevent->action = "";
344    uevent->path = "";
345    uevent->subsystem = "";
346    uevent->firmware = "";
347    uevent->major = -1;
348    uevent->minor = -1;
349
350        /* currently ignoring SEQNUM */
351    while(*msg) {
352        if(!strncmp(msg, "ACTION=", 7)) {
353            msg += 7;
354            uevent->action = msg;
355        } else if(!strncmp(msg, "DEVPATH=", 8)) {
356            msg += 8;
357            uevent->path = msg;
358        } else if(!strncmp(msg, "SUBSYSTEM=", 10)) {
359            msg += 10;
360            uevent->subsystem = msg;
361        } else if(!strncmp(msg, "FIRMWARE=", 9)) {
362            msg += 9;
363            uevent->firmware = msg;
364        } else if(!strncmp(msg, "MAJOR=", 6)) {
365            msg += 6;
366            uevent->major = atoi(msg);
367        } else if(!strncmp(msg, "MINOR=", 6)) {
368            msg += 6;
369            uevent->minor = atoi(msg);
370        }
371
372            /* advance to after the next \0 */
373        while(*msg++)
374            ;
375    }
376
377    log_event_print("event { '%s', '%s', '%s', '%s', %d, %d }\n",
378                    uevent->action, uevent->path, uevent->subsystem,
379                    uevent->firmware, uevent->major, uevent->minor);
380}
381
382static void handle_device_event(struct uevent *uevent)
383{
384    char devpath[96];
385    char *base, *name;
386    int block;
387
388        /* if it's not a /dev device, nothing to do */
389    if((uevent->major < 0) || (uevent->minor < 0))
390        return;
391
392        /* do we have a name? */
393    name = strrchr(uevent->path, '/');
394    if(!name)
395        return;
396    name++;
397
398        /* too-long names would overrun our buffer */
399    if(strlen(name) > 64)
400        return;
401
402        /* are we block or char? where should we live? */
403    if(!strncmp(uevent->subsystem, "block", 5)) {
404        block = 1;
405        base = "/dev/block/";
406        mkdir(base, 0755);
407    } else {
408        block = 0;
409            /* this should probably be configurable somehow */
410        if(!strncmp(uevent->subsystem, "graphics", 8)) {
411            base = "/dev/graphics/";
412            mkdir(base, 0755);
413        } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
414            base = "/dev/oncrpc/";
415            mkdir(base, 0755);
416        } else if (!strncmp(uevent->subsystem, "adsp", 4)) {
417            base = "/dev/adsp/";
418            mkdir(base, 0755);
419        } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
420            base = "/dev/msm_camera/";
421            mkdir(base, 0755);
422        } else if(!strncmp(uevent->subsystem, "input", 5)) {
423            base = "/dev/input/";
424            mkdir(base, 0755);
425        } else if(!strncmp(uevent->subsystem, "mtd", 3)) {
426            base = "/dev/mtd/";
427            mkdir(base, 0755);
428        } else if(!strncmp(uevent->subsystem, "sound", 5)) {
429            base = "/dev/snd/";
430            mkdir(base, 0755);
431        } else if(!strncmp(uevent->subsystem, "misc", 4) &&
432                    !strncmp(name, "log_", 4)) {
433            base = "/dev/log/";
434            mkdir(base, 0755);
435            name += 4;
436        } else
437            base = "/dev/";
438    }
439
440    snprintf(devpath, sizeof(devpath), "%s%s", base, name);
441
442    if(!strcmp(uevent->action, "add")) {
443        make_device(devpath, block, uevent->major, uevent->minor);
444        return;
445    }
446
447    if(!strcmp(uevent->action, "remove")) {
448        unlink(devpath);
449        return;
450    }
451}
452
453static int load_firmware(int fw_fd, int loading_fd, int data_fd)
454{
455    struct stat st;
456    long len_to_copy;
457    int ret = 0;
458
459    if(fstat(fw_fd, &st) < 0)
460        return -1;
461    len_to_copy = st.st_size;
462
463    write(loading_fd, "1", 1);  /* start transfer */
464
465    while (len_to_copy > 0) {
466        char buf[PAGE_SIZE];
467        ssize_t nr;
468
469        nr = read(fw_fd, buf, sizeof(buf));
470        if(!nr)
471            break;
472        if(nr < 0) {
473            ret = -1;
474            break;
475        }
476
477        len_to_copy -= nr;
478        while (nr > 0) {
479            ssize_t nw = 0;
480
481            nw = write(data_fd, buf + nw, nr);
482            if(nw <= 0) {
483                ret = -1;
484                goto out;
485            }
486            nr -= nw;
487        }
488    }
489
490out:
491    if(!ret)
492        write(loading_fd, "0", 1);  /* successful end of transfer */
493    else
494        write(loading_fd, "-1", 2); /* abort transfer */
495
496    return ret;
497}
498
499static void process_firmware_event(struct uevent *uevent)
500{
501    char *root, *loading, *data, *file;
502    int l, loading_fd, data_fd, fw_fd;
503
504    log_event_print("firmware event { '%s', '%s' }\n",
505                    uevent->path, uevent->firmware);
506
507    l = asprintf(&root, SYSFS_PREFIX"%s/", uevent->path);
508    if (l == -1)
509        return;
510
511    l = asprintf(&loading, "%sloading", root);
512    if (l == -1)
513        goto root_free_out;
514
515    l = asprintf(&data, "%sdata", root);
516    if (l == -1)
517        goto loading_free_out;
518
519    l = asprintf(&file, FIRMWARE_DIR"/%s", uevent->firmware);
520    if (l == -1)
521        goto data_free_out;
522
523    loading_fd = open(loading, O_WRONLY);
524    if(loading_fd < 0)
525        goto file_free_out;
526
527    data_fd = open(data, O_WRONLY);
528    if(data_fd < 0)
529        goto loading_close_out;
530
531    fw_fd = open(file, O_RDONLY);
532    if(fw_fd < 0)
533        goto data_close_out;
534
535    if(!load_firmware(fw_fd, loading_fd, data_fd))
536        log_event_print("firmware copy success { '%s', '%s' }\n", root, file);
537    else
538        log_event_print("firmware copy failure { '%s', '%s' }\n", root, file);
539
540    close(fw_fd);
541data_close_out:
542    close(data_fd);
543loading_close_out:
544    close(loading_fd);
545file_free_out:
546    free(file);
547data_free_out:
548    free(data);
549loading_free_out:
550    free(loading);
551root_free_out:
552    free(root);
553}
554
555static void handle_firmware_event(struct uevent *uevent)
556{
557    pid_t pid;
558
559    if(strcmp(uevent->subsystem, "firmware"))
560        return;
561
562    if(strcmp(uevent->action, "add"))
563        return;
564
565    /* we fork, to avoid making large memory allocations in init proper */
566    pid = fork();
567    if (!pid) {
568        process_firmware_event(uevent);
569        exit(EXIT_SUCCESS);
570    }
571}
572
573#define UEVENT_MSG_LEN  1024
574void handle_device_fd()
575{
576    char msg[UEVENT_MSG_LEN+2];
577    int n;
578
579    while((n = recv(device_fd, msg, UEVENT_MSG_LEN, 0)) > 0) {
580        struct uevent uevent;
581
582        if(n == UEVENT_MSG_LEN)   /* overflow -- discard */
583            continue;
584
585        msg[n] = '\0';
586        msg[n+1] = '\0';
587
588        parse_event(msg, &uevent);
589
590        handle_device_event(&uevent);
591        handle_firmware_event(&uevent);
592    }
593}
594
595/* Coldboot walks parts of the /sys tree and pokes the uevent files
596** to cause the kernel to regenerate device add events that happened
597** before init's device manager was started
598**
599** We drain any pending events from the netlink socket every time
600** we poke another uevent file to make sure we don't overrun the
601** socket's buffer.
602*/
603
604static void do_coldboot(DIR *d)
605{
606    struct dirent *de;
607    int dfd, fd;
608
609    dfd = dirfd(d);
610
611    fd = openat(dfd, "uevent", O_WRONLY);
612    if(fd >= 0) {
613        write(fd, "add\n", 4);
614        close(fd);
615        handle_device_fd();
616    }
617
618    while((de = readdir(d))) {
619        DIR *d2;
620
621        if(de->d_type != DT_DIR || de->d_name[0] == '.')
622            continue;
623
624        fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
625        if(fd < 0)
626            continue;
627
628        d2 = fdopendir(fd);
629        if(d2 == 0)
630            close(fd);
631        else {
632            do_coldboot(d2);
633            closedir(d2);
634        }
635    }
636}
637
638static void coldboot(const char *path)
639{
640    DIR *d = opendir(path);
641    if(d) {
642        do_coldboot(d);
643        closedir(d);
644    }
645}
646
647void device_init(void)
648{
649    suseconds_t t0, t1;
650
651    device_fd = open_uevent_socket();
652    if(device_fd < 0)
653        return;
654
655    fcntl(device_fd, F_SETFD, FD_CLOEXEC);
656    fcntl(device_fd, F_SETFL, O_NONBLOCK);
657
658    t0 = get_usecs();
659    coldboot("/sys/class");
660    coldboot("/sys/block");
661    coldboot("/sys/devices");
662    t1 = get_usecs();
663
664    log_event_print("coldboot %ld uS\n", ((long) (t1 - t0)));
665}
666
667int get_device_fd()
668{
669    return device_fd;
670}
671