From owner-svn-soc-all@FreeBSD.ORG Sun Aug 11 09:01:31 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id D20947FD for ; Sun, 11 Aug 2013 09:01:31 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BD2CA2AAF for ; Sun, 11 Aug 2013 09:01:31 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7B91V8d046259 for ; Sun, 11 Aug 2013 09:01:31 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7B91V8X046248 for svn-soc-all@FreeBSD.org; Sun, 11 Aug 2013 09:01:31 GMT (envelope-from mattbw@FreeBSD.org) Date: Sun, 11 Aug 2013 09:01:31 GMT Message-Id: <201308110901.r7B91V8X046248@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255800 - in soc2013/mattbw/backend: . query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Aug 2013 09:01:31 -0000 Author: mattbw Date: Sun Aug 11 09:01:31 2013 New Revision: 255800 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255800 Log: Clean up query code a bit. After a week of mostly shuffling around jobs, query/core.c has now received a bit of love. The initial query routing to local and remote querying has received the most changes, mainly because it was horrifically duplicated code previously. It's becoming obvious that query/core.c might need splitting, as it is now getting unfathomably long. Some space/indent errors elsewhere were fixed, but the code is long overdue an indent(1). Modified: soc2013/mattbw/backend/jobs.c soc2013/mattbw/backend/pkgutils.c soc2013/mattbw/backend/query/core.c soc2013/mattbw/backend/query/do.c Modified: soc2013/mattbw/backend/jobs.c ============================================================================== --- soc2013/mattbw/backend/jobs.c Sun Aug 11 08:38:10 2013 (r255799) +++ soc2013/mattbw/backend/jobs.c Sun Aug 11 09:01:31 2013 (r255800) @@ -131,17 +131,17 @@ jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info) { - struct pkg *pkg; + struct pkg *pkg; - assert(jobs != NULL); - assert(backend != NULL); - assert(info != NULL); - - pkg = NULL; - while (pkg_jobs(jobs, &pkg) == EPKG_OK) { - assert(pkg != NULL); - pkgutils_emit(pkg, backend, info(pkg)); - } + assert(jobs != NULL); + assert(backend != NULL); + assert(info != NULL); + + pkg = NULL; + while (pkg_jobs(jobs, &pkg) == EPKG_OK) { + assert(pkg != NULL); + pkgutils_emit(pkg, backend, info(pkg)); + } } void @@ -210,5 +210,3 @@ return namevers; } - - Modified: soc2013/mattbw/backend/pkgutils.c ============================================================================== --- soc2013/mattbw/backend/pkgutils.c Sun Aug 11 08:38:10 2013 (r255799) +++ soc2013/mattbw/backend/pkgutils.c Sun Aug 11 09:01:31 2013 (r255800) @@ -27,6 +27,7 @@ #include "pkgutils.h" /* Prototypes */ #include "utils.h" /* INTENTIONALLY_IGNORE */ +static bool pkg_matches_filters(struct pkg *pkg, PkBitfield filters); static const char *repo_of_remote(struct pkg *pkg); /* @@ -36,7 +37,7 @@ pkgutils_pkg_current_state(struct pkg *pkg) { PkInfoEnum info; - + assert(pkg != NULL); /* If the package is local, then it's installed. If it is remote, then @@ -178,7 +179,7 @@ */ gchar * pkgutils_pkg_match_id(struct pkg *pkg, gchar **split_id) -{ +{ bool success; int i; gchar *match_id; @@ -192,37 +193,45 @@ match_id = NULL; pkg_id_bits = calloc(4, sizeof(const char *)); - if (pkg_id_bits == NULL) - goto cleanup; + if (pkg_id_bits != NULL) { + match_id = pkgutils_pkg_to_id_through(pkg, pkg_id_bits); + } - match_id = pkgutils_pkg_to_id_through(pkg, pkg_id_bits); - if (match_id == NULL) - goto cleanup; + if (match_id != NULL) { + bool match_failed; - /* - * Succeed if this package's PackageID fields match the - * original PackageID. Of course, the original ID might have - * missing fields (NULLs), so we treat a comparison involving - * one as a success. This means using our "weak strcmp" - * instead of normal strcmp or even g_strcmp0. - */ - for (success = true, i = PK_PACKAGE_ID_NAME; - success && i <= PK_PACKAGE_ID_DATA; - i++) - success = string_match(split_id[i], pkg_id_bits[i]); - -cleanup: - if (!success) { - if (match_id != NULL) { + assert(pkg_id_bits != NULL); + + /* + * Succeed if this package's PackageID fields match the + * original PackageID. Of course, the original ID might have + * missing fields (NULLs), so we treat a comparison involving + * one as a success. This means using our "weak strcmp" + * instead of normal strcmp or even g_strcmp0. + */ + match_failed = false; + for (i = PK_PACKAGE_ID_NAME; i <= PK_PACKAGE_ID_DATA; i++) { + if (!string_match(split_id[i], pkg_id_bits[i])) { + match_failed = true; + break; + } + } + + if (match_failed) { g_free(match_id); match_id = NULL; + } else { + success = true; } + } + + free(pkg_id_bits); + assert (success || match_id == NULL); assert (!success || match_id != NULL); /* The strings inside this are owned by 'pkg'. Don't free them */ - free(pkg_id_bits); return match_id; } @@ -339,31 +348,45 @@ pkgutils_emit_filtered(struct pkg *pkg, PkBackend *backend, PkBitfield filters, PkInfoEnum info) { - gboolean should_emit; assert(pkg != NULL); assert(backend != NULL); - should_emit = TRUE; + if (pkg_matches_filters(pkg, filters)) { + pkgutils_emit(pkg, backend, info); + } +} + +static bool +pkg_matches_filters(struct pkg *pkg, PkBitfield filters) +{ + bool matches_filters; + PkFilterEnum wrong_filter; + + assert(pkg != NULL); + + matches_filters = true; + + if (pkgutils_pkg_current_state(pkg) == PK_INFO_ENUM_INSTALLED) { + wrong_filter = PK_FILTER_ENUM_NOT_INSTALLED; + } else { + wrong_filter = PK_FILTER_ENUM_INSTALLED; + } - if (pkgutils_pkg_current_state(pkg) == PK_INFO_ENUM_INSTALLED) - should_emit = pk_bitfield_contain(filters, - PK_FILTER_ENUM_NOT_INSTALLED) ? FALSE : should_emit; - else - should_emit = pk_bitfield_contain(filters, - PK_FILTER_ENUM_INSTALLED) ? FALSE : should_emit; - /* TODO: more filters? */ - if (should_emit) - pkgutils_emit(pkg, backend, info); + if (pk_bitfield_contain(filters, wrong_filter) == TRUE) { + matches_filters = false; + } + + return matches_filters; } /* * Gets the PackageKit repository name for the (remote) package. - * + * * Currently this is actually the pkgng repository ident. This might change. - * + * * This does not need to be freed (possibly, TODO: check). */ static const char * Modified: soc2013/mattbw/backend/query/core.c ============================================================================== --- soc2013/mattbw/backend/query/core.c Sun Aug 11 08:38:10 2013 (r255799) +++ soc2013/mattbw/backend/query/core.c Sun Aug 11 09:01:31 2013 (r255800) @@ -50,11 +50,17 @@ struct query_target *t; }; +typedef struct pkgdb_it * (*query_func_ptr) (struct query *q); + static bool can_remote_iterate(struct query *q); static enum repo_type type_of_repo_name(const char *name); static gchar *match_pkg(struct pkg *pkg, struct query *q); static gchar **init_unpack_source(PkBackend *backend, struct query_source *s); +static gchar **make_fake_id_split(const char *name); static struct pkg *match_iterator(struct pkgdb_it *it, struct query *q, gchar **match_id_p); +static struct pkg *query_find_from(query_func_ptr function, struct query *q, gchar **match_id_p); +static struct pkgdb_it *local_query(struct query *q); +static struct pkgdb_it *remote_query(struct query *q); /* * Returns the backend stored inside the given query. @@ -78,24 +84,15 @@ bool success; bool try_local; bool try_remote; - match_t match; PkBitfield filters; - const char *name; - const char *repo; gchar *match_id; struct pkg *pkg; - struct pkgdb *db; - struct pkgdb_it *it; assert(q != NULL); success = false; - match = MATCH_EXACT; match_id = NULL; pkg = NULL; - db = q->db; - name = q->id_strv[PK_PACKAGE_ID_NAME]; - repo = query_repo(q); /* * If we're not given a specific repository in the PackageID, we want @@ -112,35 +109,54 @@ if (pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_INSTALLED)) try_local = false; - /* Try a local search first, if applicable. */ - it = (try_local ? pkgdb_query(db, name, match) : NULL); - if (it != NULL) - pkg = match_iterator(it, q, &match_id); - pkgdb_it_free(it); - - /* No point trying remote if we got a local match */ - if (pkg != NULL) - try_remote = false; - - /* Next, try a remote search, again only if applicable. */ - it = (try_remote ? pkgdb_rquery(db, name, match, repo) : NULL); - if (it != NULL && can_remote_iterate(q)) - pkg = match_iterator(it, q, &match_id); - pkgdb_it_free(it); + if (try_local) { + pkg = query_find_from(local_query, q, &match_id); + } + if (pkg == NULL && try_remote) { + pkg = query_find_from(remote_query, q, &match_id); + } + if (pkg == NULL) { + assert(match_id == NULL); - if (pkg == NULL) ERR(q->backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found"); - else - success = q->t->f(pkg, match_id, q); + } else { + assert(match_id != NULL); - pkg_free(pkg); - g_free(match_id); + success = q->t->f(pkg, match_id, q); + pkg_free(pkg); + g_free(match_id); + } return success; } +static struct pkg * +query_find_from(query_func_ptr function, struct query *q, gchar **match_id_p) +{ + struct pkg *result; + struct pkgdb_it *iterator; + + assert(function != NULL); + assert(q != NULL); + assert(match_id_p != NULL); + + result = NULL; + + iterator = function(q); + if (iterator != NULL) { + result = match_iterator(iterator, q, match_id_p); + pkgdb_it_free(iterator); + } + + /* Match ID if and only if result. */ + assert(result == NULL || *(match_id_p) != NULL); + assert(result != NULL || *(match_id_p) == NULL); + + return result; +} + /* * Retrieves the repository for the query, or NULL if none is specified (or * the query is using the local database only). @@ -148,13 +164,13 @@ const char * query_repo(struct query *q) { - + assert(q != NULL); return (q->rtype == REPO_REMOTE ? q->id_strv[PK_PACKAGE_ID_DATA] : NULL); } - + /* * Returns the database stored inside the given query. */ @@ -170,7 +186,7 @@ /* * Creates a struct query for the given backend, database, source and target. - * + * * Usually you'll want to use "query_do" instead of calling this directly. */ struct query * @@ -251,11 +267,12 @@ assert(q != NULL); - if (percent == PK_BACKEND_PERCENTAGE_INVALID) + if (percent == PK_BACKEND_PERCENTAGE_INVALID) { scaled_percent = PK_BACKEND_PERCENTAGE_INVALID; - else { - if (percent > 100) + } else { + if (100 < percent) { percent = 100; + } scaled_percent = (((100 * q->s->position) + percent) / (q->s->total)); @@ -324,8 +341,6 @@ assert(pkg != NULL); assert(q != NULL); - - /* No need to do a PackageID match if we're looking for a name. */ if (q->s->type == QUERY_SINGLE_NAME) match_id = pkgutils_pkg_to_id(pkg); @@ -367,38 +382,78 @@ return pkg; } +static struct pkgdb_it * +local_query(struct query *q) +{ + + return pkgdb_query(q->db, q->id_strv[PK_PACKAGE_ID_NAME], MATCH_EXACT); +} + +static struct pkgdb_it * +remote_query(struct query *q) +{ + struct pkgdb_it *iterator; + + iterator = pkgdb_rquery(q->db, q->id_strv[PK_PACKAGE_ID_NAME], + MATCH_EXACT, query_repo(q)); + + /* + * Make sure we can use this iterator. (We only check now so that + * the case of there being no remote matches is properly handled.) + */ + if (iterator != NULL && !can_remote_iterate(q)) { + pkgdb_it_free(iterator); + iterator = NULL; + } + + return iterator; +} + /* Unpacks a query source into name/version/arch/data pointers. */ static gchar ** init_unpack_source(PkBackend *backend, struct query_source *s) { - gchar **id_strv; + gchar **id_strv; assert(backend != NULL); assert(s != NULL); id_strv = NULL; if (s->type == QUERY_SINGLE_NAME) { - /* - * Make a snake-oil ID vector; we won't be doing rigid - * checking against it so it doesn't matter that the version - * might be in the name column etc. - */ - id_strv = g_malloc0_n(5, (gsize) sizeof(gchar *)); - - id_strv[PK_PACKAGE_ID_NAME] = g_strdup(s->single); - id_strv[PK_PACKAGE_ID_VERSION] = g_strdup(""); - id_strv[PK_PACKAGE_ID_ARCH] = g_strdup(""); - id_strv[PK_PACKAGE_ID_DATA] = g_strdup(""); + id_strv = make_fake_id_split(s->single); } else if (s->type == QUERY_SINGLE_ID) { id_strv = pk_package_id_split(s->single); if (id_strv == NULL) ERR(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); - } else + } else { ERR(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "init_unpack_source given silly source type"); + } + + return id_strv; +} + +static gchar ** +make_fake_id_split(const char *name) +{ + gchar **id_strv; + + assert(name != NULL); + + /* + * Make a snake-oil ID vector; we won't be doing rigid + * checking against it so it doesn't matter that the version + * might be in the name column etc. + */ + id_strv = g_malloc0_n(5, (gsize) sizeof(gchar *)); + + id_strv[PK_PACKAGE_ID_NAME] = g_strdup(name); + id_strv[PK_PACKAGE_ID_VERSION] = g_strdup(""); + id_strv[PK_PACKAGE_ID_ARCH] = g_strdup(""); + id_strv[PK_PACKAGE_ID_DATA] = g_strdup(""); return id_strv; } Modified: soc2013/mattbw/backend/query/do.c ============================================================================== --- soc2013/mattbw/backend/query/do.c Sun Aug 11 08:38:10 2013 (r255799) +++ soc2013/mattbw/backend/query/do.c Sun Aug 11 09:01:31 2013 (r255800) @@ -86,6 +86,10 @@ for (new_s.position = 0; new_s.position < new_s.total && success; (new_s.position)++) { + if (!success) { + break; + } + new_s.single = package_ids[new_s.position]; /* Treat non-PackageIDs as pkgng package names, if allowed */ From owner-svn-soc-all@FreeBSD.ORG Sun Aug 11 09:30:47 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4D343C6F for ; Sun, 11 Aug 2013 09:30:47 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 39B8B2BE2 for ; Sun, 11 Aug 2013 09:30:47 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7B9UllR091891 for ; Sun, 11 Aug 2013 09:30:47 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7B9Ulwa091861 for svn-soc-all@FreeBSD.org; Sun, 11 Aug 2013 09:30:47 GMT (envelope-from mattbw@FreeBSD.org) Date: Sun, 11 Aug 2013 09:30:47 GMT Message-Id: <201308110930.r7B9Ulwa091861@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255801 - in soc2013/mattbw/backend: . query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Aug 2013 09:30:47 -0000 Author: mattbw Date: Sun Aug 11 09:30:46 2013 New Revision: 255801 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255801 Log: Move the repository type code to utils. This is so it can be used in jobs as well, but the new location is slightly counter-intuitive and subject to change. Modified: soc2013/mattbw/backend/query/core.c soc2013/mattbw/backend/utils.c soc2013/mattbw/backend/utils.h Modified: soc2013/mattbw/backend/query/core.c ============================================================================== --- soc2013/mattbw/backend/query/core.c Sun Aug 11 09:01:31 2013 (r255800) +++ soc2013/mattbw/backend/query/core.c Sun Aug 11 09:30:46 2013 (r255801) @@ -25,18 +25,11 @@ #include "../pk-backend.h" #include "pkg.h" - #include "../db.h" /* db_open_remote */ -#include "../utils.h" /* string_match */ +#include "../utils.h" /* string_match, type_of_repo_name */ #include "../pkgutils.h" /* pkgutils_... */ #include "core.h" /* Prototypes */ -enum repo_type { - REPO_INVALID, - REPO_ANY, - REPO_LOCAL, - REPO_REMOTE -}; struct query { PkBackend *backend; @@ -53,7 +46,7 @@ typedef struct pkgdb_it * (*query_func_ptr) (struct query *q); static bool can_remote_iterate(struct query *q); -static enum repo_type type_of_repo_name(const char *name); + static gchar *match_pkg(struct pkg *pkg, struct query *q); static gchar **init_unpack_source(PkBackend *backend, struct query_source *s); static gchar **make_fake_id_split(const char *name); @@ -308,26 +301,6 @@ return sane; } -/* - * Finds the type of the given PackageKit repository name. - */ -static enum repo_type -type_of_repo_name(const char *name) -{ - enum repo_type rtype; - - /* Null or empty implies no specific repository */ - if (name == NULL || name[0] == '\0') - rtype = REPO_ANY; - else if (strcmp(name, "installed") == 0) - rtype = REPO_LOCAL; - else if (pkg_repo_find_ident(name) != NULL) - rtype = REPO_REMOTE; - else - rtype = REPO_INVALID; - - return rtype; -} /* * Checks whether a candidate package matches any constraints provided by the Modified: soc2013/mattbw/backend/utils.c ============================================================================== --- soc2013/mattbw/backend/utils.c Sun Aug 11 09:01:31 2013 (r255800) +++ soc2013/mattbw/backend/utils.c Sun Aug 11 09:30:46 2013 (r255801) @@ -20,10 +20,11 @@ /* String/ID utilities. */ -#include /* assert */ +#include /* assert */ #include #include +#include "pkg.h" #include "pk-backend.h" /* pk_backend_get_strv */ #include "utils.h" /* prototypes */ @@ -49,6 +50,28 @@ } /* + * Finds the type of the given PackageKit repository name. + */ +enum repo_type +type_of_repo_name(const char *name) +{ + enum repo_type rtype; + + /* Null or empty implies no specific repository */ + if (name == NULL || name[0] == '\0') { + rtype = REPO_ANY; + } else if (strcmp(name, "installed") == 0) { + rtype = REPO_LOCAL; + } else if (pkg_repo_find_ident(name) != NULL) { + rtype = REPO_REMOTE; + } else { + rtype = REPO_INVALID; + } + + return rtype; +} + +/* * Retrieves PackageIDs from the backend, as well as the total number of them. */ gchar ** Modified: soc2013/mattbw/backend/utils.h ============================================================================== --- soc2013/mattbw/backend/utils.h Sun Aug 11 09:01:31 2013 (r255800) +++ soc2013/mattbw/backend/utils.h Sun Aug 11 09:30:46 2013 (r255801) @@ -23,6 +23,13 @@ #include /* bool */ +enum repo_type { + REPO_INVALID, + REPO_ANY, + REPO_LOCAL, + REPO_REMOTE +}; + #define INTENTIONALLY_IGNORE(x) (void)(x) #define STATUS(backend, status) \ (void)pk_backend_set_status((backend), (status)) @@ -30,6 +37,7 @@ (void)pk_backend_error_code((backend), (type), (msg)) bool string_match(const char *left, const char *right); +enum repo_type type_of_repo_name(const char *name); gchar **get_package_ids(PkBackend *backend, guint *count_p); #endif /* !_PKGNG_BACKEND_DETAILS_H_ */ From owner-svn-soc-all@FreeBSD.ORG Sun Aug 11 09:38:41 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id BCDF1F58 for ; Sun, 11 Aug 2013 09:38:41 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A98AB2C36 for ; Sun, 11 Aug 2013 09:38:41 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7B9cfwF067522 for ; Sun, 11 Aug 2013 09:38:41 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7B9cf42067517 for svn-soc-all@FreeBSD.org; Sun, 11 Aug 2013 09:38:41 GMT (envelope-from mattbw@FreeBSD.org) Date: Sun, 11 Aug 2013 09:38:41 GMT Message-Id: <201308110938.r7B9cf42067517@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255802 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Aug 2013 09:38:41 -0000 Author: mattbw Date: Sun Aug 11 09:38:41 2013 New Revision: 255802 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255802 Log: Use type_of_repo_name in jobs. This fixes a bug whereby the job repository being '' would break the set-repository-of-jobs code. Testing shows that the new error messages aren't working, so more creativity is required. Modified: soc2013/mattbw/backend/jobs.c Modified: soc2013/mattbw/backend/jobs.c ============================================================================== --- soc2013/mattbw/backend/jobs.c Sun Aug 11 09:30:46 2013 (r255801) +++ soc2013/mattbw/backend/jobs.c Sun Aug 11 09:38:41 2013 (r255802) @@ -29,7 +29,7 @@ #include "db.h" /* db_... */ #include "event.h" /* event_cb */ -#include "utils.h" /* ERR */ +#include "utils.h" /* ERR, type_of_repo_name */ #include "jobs.h" /* jobs_... */ #include "jobs/check.h" /* jobs_check_... */ #include "pkgutils.h" /* pkgutils_... */ @@ -79,22 +79,19 @@ bool jobs_set_repo(struct pkg_jobs *jobs, const char *reponame) { - bool is_remote; bool success; - success = true; + assert(jobs != NULL); - is_remote = (reponame != NULL && strcmp(reponame, "installed") != 0); + success = true; - if (is_remote) { + if (type_of_repo_name(reponame) == REPO_REMOTE) { int err; err = pkg_jobs_set_repository(jobs, reponame); success = (err == EPKG_OK); } - assert(is_remote || success == true); - return success; } From owner-svn-soc-all@FreeBSD.ORG Mon Aug 12 11:33:32 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DD666A7C for ; Mon, 12 Aug 2013 11:33:32 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BB70B24EF for ; Mon, 12 Aug 2013 11:33:32 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7CBXW17088458 for ; Mon, 12 Aug 2013 11:33:32 GMT (envelope-from oleksandr@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7CBXW74088452 for svn-soc-all@FreeBSD.org; Mon, 12 Aug 2013 11:33:32 GMT (envelope-from oleksandr@FreeBSD.org) Date: Mon, 12 Aug 2013 11:33:32 GMT Message-Id: <201308121133.r7CBXW74088452@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to oleksandr@FreeBSD.org using -f From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255839 - soc2013/oleksandr/ports/emulators/virtualbox-ose-additions/files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Aug 2013 11:33:32 -0000 Author: oleksandr Date: Mon Aug 12 11:33:32 2013 New Revision: 255839 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255839 Log: Delete unused include's and fixed operation with dirent structure Modified: soc2013/oleksandr/ports/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-freebsd.kmk Modified: soc2013/oleksandr/ports/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-freebsd.kmk ============================================================================== --- soc2013/oleksandr/ports/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-freebsd.kmk Mon Aug 12 10:15:09 2013 (r255838) +++ soc2013/oleksandr/ports/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-freebsd.kmk Mon Aug 12 11:33:32 2013 (r255839) @@ -18,39 +18,13 @@ #include #include #include -@@ -29,10 +29,40 @@ +@@ -29,10 +29,14 @@ #include #include -#include +#include "vboxvfs.h" -+#if 0 -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include -+#endif -+ #define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data) +#ifdef MALLOC_DECLARE @@ -60,7 +34,7 @@ static int vboxvfs_version = VBOXVFS_VERSION; SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem"); -@@ -51,15 +81,15 @@ +@@ -51,15 +55,15 @@ static vfs_unmount_t vboxvfs_unmount; static struct vfsops vboxvfs_vfsops = { @@ -85,7 +59,7 @@ }; -@@ -66,193 +96,238 @@ +@@ -66,193 +70,239 @@ VFS_SET(vboxvfs_vfsops, vboxvfs, VFCF_NETWORK); MODULE_DEPEND(vboxvfs, vboxguest, 1, 1, 1); @@ -150,6 +124,7 @@ - printf("%s: Enter\n", __FUNCTION__); + printf("%s: Enter\n", __FUNCTION__); ++ - if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS)) - return EOPNOTSUPP; @@ -536,10 +511,6 @@ - long nextino; - int caseopt; - int didrele; -+#define DIRENT_RECLEN(namelen) \ -+ ((offsetof(dirent, d_name[0]) + 1 + (namelen) + 7) & ~ 7) -+#define DIRENT_NAMELEN(reclen) \ -+ ((reclen) - (offsetof(dirent, d_name[0]))) +/* + * representation of an active mount point + */ @@ -645,11 +616,15 @@ +}; + +struct vboxvfs_mount_info { -+ char name[MAX_HOST_NAME]; -+ char nls_name[MAX_NLS_NAME]; -+ int uid; -+ int gid; -+ int ttl; ++ char name[MAX_HOST_NAME]; /* share name */ ++ char nls_name[MAX_NLS_NAME];/* name of an I/O charset */ ++ int uid; /* user ID for all entries, default 0=root */ ++ int gid; /* group ID for all entries, default 0=root */ ++ int ttl; /* time to live */ ++ int dmode; /* mode for directories if != 0xffffffff */ ++ int fmode; /* mode for regular files if != 0xffffffff */ ++ int dmask; /* umask applied to directories */ ++ int fmask; /* umask applied to regular files */ +}; + struct sf_glob_info { @@ -1949,7 +1924,7 @@ =================================================================== --- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_prov.c (revision 0) +++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_prov.c (working copy) -@@ -0,0 +1,1009 @@ +@@ -0,0 +1,1015 @@ +/** @file + * VirtualBox File System for FreeBSD Guests, provider implementation. + * Portions contributed by: Ronald. @@ -1991,6 +1966,12 @@ +#include +#include "vboxvfs.h" + ++#define DIRENT_RECLEN(namelen) ((sizeof(struct dirent) - \ ++ sizeof(((struct dirent *)NULL)->d_name) + \ ++ (namelen) + 1 + 7) & ~7) ++#define DIRENT_NAMELEN(reclen) \ ++ (sizeof((reclen) - (sizeof(((struct dirent *)NULL)->d_name)))) ++ +#define SFPROV_VERSION 1 + +static VBSFCLIENT vbox_client; @@ -2825,7 +2806,7 @@ + int error; + char *cp; + int len; -+ SHFLSTRING *mask_str = NULL; /* must be path with "/*" appended */ ++ SHFLSTRING *mask_str = NULL; /* must be path with "/" appended */ + int mask_size; + sfp_file_t *fp; + uint32_t infobuff_alloc = 16384; @@ -2926,7 +2907,7 @@ + strncpy(&dirent->sf_entry.d_name[0], info->name.String.utf8, DIRENT_NAMELEN(reclen)); + dirent->sf_entry.d_reclen = reclen; + offset += entlen; -+ dirent->sf_entry.d_off = offset; ++ //dirent->sf_entry.d_off = offset; + + /* save the stats */ + sfprov_stat_from_info(&dirent->sf_stat, &info->Info); From owner-svn-soc-all@FreeBSD.ORG Mon Aug 12 14:00:56 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 24FE9F7C for ; Mon, 12 Aug 2013 14:00:56 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 114002072 for ; Mon, 12 Aug 2013 14:00:56 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7CE0tj5075659 for ; Mon, 12 Aug 2013 14:00:55 GMT (envelope-from oleksandr@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7CE0tG8075647 for svn-soc-all@FreeBSD.org; Mon, 12 Aug 2013 14:00:55 GMT (envelope-from oleksandr@FreeBSD.org) Date: Mon, 12 Aug 2013 14:00:55 GMT Message-Id: <201308121400.r7CE0tG8075647@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to oleksandr@FreeBSD.org using -f From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255842 - soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Aug 2013 14:00:56 -0000 Author: oleksandr Date: Mon Aug 12 14:00:55 2013 New Revision: 255842 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255842 Log: Correct mount_vboxfs utility, add double alternative way to mount vfs file system, if first is fault and correct usage() function Modified: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Modified: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c ============================================================================== --- soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Mon Aug 12 13:52:15 2013 (r255841) +++ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Mon Aug 12 14:00:55 2013 (r255842) @@ -43,24 +43,45 @@ #include "mntopts.h" +#define MAX_HOST_NAME 256 static char mount_point[MAXPATHLEN + 1]; -static char vboxfs_vfsname[] = "vboxfs"; +static char vboxfs_vfsname[] = "vboxvfs"; +static struct mntopt mopts[] = { + MOPT_STDOPTS, + MOPT_END +}; + static void usage(void) __dead2; +/** + * Print out a usage message and exit. + * + * @param name The name of the application + */ +static void +usage(void) +{ + printf("Usage: [OPTIONS] NAME MOUNTPOINT\n" + "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n" + "\n" + " -w mount the shared folder writable \n" + " -r mount the shared folder read-only (the default)\n"); + exit(1); +} int main(int argc, char *argv[]) { struct iovec *iov; struct stat st; - // struct xvfsconf vfc; char *host_name; char errmsg[255]; uid_t uid; gid_t gid; mode_t dir_mode, file_mode; int iovlen; - int error, ch; - + int error, ch, ronly = 0; + int mntflags = MNT_RDONLY; + iov = NULL; iovlen = 0; errmsg[0] = '\0'; @@ -69,40 +90,43 @@ file_mode = 0; dir_mode = 0; - #if 0 - error = getvfsbyname(vboxfs_vfsname, &vfc); - - if (error) { - if (kldload(vboxfs_vfsname) < 0) - err(EX_OSERR, "kldload(%s)", vboxfs_vfsname); - error = getvfsbyname(vboxfs_vfsname, &vfc); - } - - if (error) - errx(EX_OSERR, "VBOXFS filesystem is not available"); - #endif - while ((ch = getopt(argc, argv, "o:")) != -1) + while ((ch = getopt(argc, argv, "rwo:h")) != -1) switch(ch) { - case 'o': - case '?': - usage(); - /*NOTREACHED*/ - default: - usage(); + default: + fprintf(stderr, "unknown option `%c:%#x'\n", ch, ch); + case '?': + case 'h': + usage(); + case 'r': + ronly= 1; + break; + case 'w': + ronly = 0; + break; + case 'o': + getmntopts(optarg, mopts, &mntflags, 0); + break; + break; } if (argc - optind < 2) - usage(); + usage(); host_name = argv[optind]; realpath(argv[optind+1], mount_point); - + if (stat(mount_point, &st) == -1) err(EX_OSERR, "could not find mount point %s", mount_point); + if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; err(EX_OSERR, "can't mount on %s", mount_point); } + if (strlen(host_name) > MAX_HOST_NAME - 1) + err(EX_OSERR, "host name is too big %s", host_name); + + if (!ronly) + mntflags |= MNT_ASYNC; if (uid == (uid_t)-1) uid = st.st_uid; if (gid == (gid_t)-1) @@ -129,7 +153,26 @@ build_iovec_argf(&iov, &iovlen, "dir_mode", "%d", dir_mode); build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); - error = nmount(iov, iovlen, MNT_RDONLY); + error = nmount(iov, iovlen, mntflags); + + if (error == -1 && errno == EPROTO) + { + /* Sometimes the mount utility messes up the share name. Try to + * un-mangle it again. */ + char szCWD[4096]; + size_t cchCWD; + if (!getcwd(szCWD, sizeof(szCWD))) + printf("%s: failed to get the current working directory", argv[0]); + cchCWD = strlen(szCWD); + if (!strncmp(host_name, szCWD, cchCWD)) + { + while (host_name[cchCWD] == '/') + ++cchCWD; + /* We checked before that we have enough space */ + strcpy(host_name, host_name + cchCWD); + } + error = nmount(iov, iovlen, mntflags); + } if (error) { if (errmsg[0] != 0) { @@ -143,11 +186,3 @@ return 0; } - -static void -usage(void) -{ - (void)fprintf(stderr, - "usage: mount_vboxfs [-o options] name mount-point\n"); - exit(1); -} From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 06:28:01 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 25BB6A98 for ; Tue, 13 Aug 2013 06:28:01 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 119212C37 for ; Tue, 13 Aug 2013 06:28:01 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7D6S1mb003719 for ; Tue, 13 Aug 2013 06:28:01 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7D6S06o003714 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 06:28:00 GMT (envelope-from syuu@FreeBSD.org) Date: Tue, 13 Aug 2013 06:28:00 GMT Message-Id: <201308130628.r7D6S06o003714@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255863 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb usb/gpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 06:28:01 -0000 Author: syuu Date: Tue Aug 13 06:28:00 2013 New Revision: 255863 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255863 Log: import GPL tainted desc.[ch] Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 03:10:39 2013 (r255862) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 06:28:00 2013 (r255863) @@ -18,6 +18,8 @@ .PATH: ${.CURDIR}/usb CFLAGS+=-I${.CURDIR}/usb/include -I${.CURDIR} SRCS+= core.c hcd-uhci.c host-libusb.c dev-hub.c +.PATH: ${.CURDIR}/usb/gpl +SRCS+= desc.c NO_MAN= Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Tue Aug 13 03:10:39 2013 (r255862) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Tue Aug 13 06:28:00 2013 (r255863) @@ -24,7 +24,7 @@ //#include "qemu-common.h" //#include "trace.h" #include "hw/usb.h" -//#include "hw/usb/desc.h" +#include "usb/gpl/desc.h" //#include "qemu/error-report.h" #include @@ -101,7 +101,6 @@ STR_SERIALNUMBER, }; -/* static const USBDescStrings desc_strings = { [STR_MANUFACTURER] = "QEMU", [STR_PRODUCT] = "QEMU USB Hub", @@ -150,7 +149,6 @@ .full = &desc_device_hub, .str = desc_strings, }; -*/ static const uint8_t qemu_hub_hub_descriptor[] = { @@ -311,7 +309,7 @@ trace_usb_hub_control(s->dev.addr, request, value, index, length); -// ret = usb_desc_handle_control(dev, p, request, value, index, length, data); + ret = usb_desc_handle_control(dev, p, request, value, index, length, data); if (ret >= 0) { return; } @@ -525,6 +523,7 @@ .wakeup = usb_hub_wakeup, .complete = usb_hub_complete, }; +*/ static int usb_hub_initfn(USBDevice *dev) { @@ -533,7 +532,7 @@ int i; if (dev->port->hubcount == 5) { - error_report("usb hub chain too deep"); +// error_report("usb hub chain too deep"); return -1; } @@ -542,15 +541,18 @@ s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); for (i = 0; i < NUM_PORTS; i++) { port = &s->ports[i]; + /* usb_register_port(usb_bus_from_device(dev), &port->port, s, i, &usb_hub_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); + */ usb_port_location(&port->port, dev->port, i+1); } usb_hub_handle_reset(dev); return 0; } +/* static const VMStateDescription vmstate_usb_hub_port = { .name = "usb-hub-port", .version_id = 1, Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.c Tue Aug 13 06:28:00 2013 (r255863) @@ -0,0 +1,820 @@ +#include +#include +#include +#include + +#include "hw/usb.h" +#include "desc.h" + +#define trace_usb_desc_device(a,b,c) +#define trace_usb_desc_config(a,b,c,d) +#define trace_usb_desc_string(a,b,c,d) +#define trace_usb_desc_device_qualifier(a,b,c) +#define trace_usb_desc_other_speed_config(a,b,c,d) +#define trace_usb_set_addr(a) +#define trace_usb_set_config(a,b,c) +#define trace_usb_clear_device_feature(a,b,c) +#define trace_usb_set_device_feature(a,b,c) +#define trace_usb_set_interface(a,b,c,d) +#define trace_usb_desc_bos(a,b,c) + +const USBDesc *usb_device_get_usb_desc(USBDevice *dev) +{ + return NULL; +} + +void usb_device_set_interface(USBDevice *dev, int interface, + int alt_old, int alt_new) +{ +} + + +/* ------------------------------------------------------------------ */ + +static uint8_t usb_lo(uint16_t val) +{ + return val & 0xff; +} + +static uint8_t usb_hi(uint16_t val) +{ + return (val >> 8) & 0xff; +} + +int usb_desc_device(const USBDescID *id, const USBDescDevice *dev, + uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x12; + USBDescriptor *d = (void *)dest; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE; + + d->u.device.bcdUSB_lo = usb_lo(dev->bcdUSB); + d->u.device.bcdUSB_hi = usb_hi(dev->bcdUSB); + d->u.device.bDeviceClass = dev->bDeviceClass; + d->u.device.bDeviceSubClass = dev->bDeviceSubClass; + d->u.device.bDeviceProtocol = dev->bDeviceProtocol; + d->u.device.bMaxPacketSize0 = dev->bMaxPacketSize0; + + d->u.device.idVendor_lo = usb_lo(id->idVendor); + d->u.device.idVendor_hi = usb_hi(id->idVendor); + d->u.device.idProduct_lo = usb_lo(id->idProduct); + d->u.device.idProduct_hi = usb_hi(id->idProduct); + d->u.device.bcdDevice_lo = usb_lo(id->bcdDevice); + d->u.device.bcdDevice_hi = usb_hi(id->bcdDevice); + d->u.device.iManufacturer = id->iManufacturer; + d->u.device.iProduct = id->iProduct; + d->u.device.iSerialNumber = id->iSerialNumber; + + d->u.device.bNumConfigurations = dev->bNumConfigurations; + + return bLength; +} + +int usb_desc_device_qualifier(const USBDescDevice *dev, + uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x0a; + USBDescriptor *d = (void *)dest; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE_QUALIFIER; + + d->u.device_qualifier.bcdUSB_lo = usb_lo(dev->bcdUSB); + d->u.device_qualifier.bcdUSB_hi = usb_hi(dev->bcdUSB); + d->u.device_qualifier.bDeviceClass = dev->bDeviceClass; + d->u.device_qualifier.bDeviceSubClass = dev->bDeviceSubClass; + d->u.device_qualifier.bDeviceProtocol = dev->bDeviceProtocol; + d->u.device_qualifier.bMaxPacketSize0 = dev->bMaxPacketSize0; + d->u.device_qualifier.bNumConfigurations = dev->bNumConfigurations; + d->u.device_qualifier.bReserved = 0; + + return bLength; +} + +int usb_desc_config(const USBDescConfig *conf, int flags, + uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x09; + uint16_t wTotalLength = 0; + USBDescriptor *d = (void *)dest; + int i, rc; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_CONFIG; + + d->u.config.bNumInterfaces = conf->bNumInterfaces; + d->u.config.bConfigurationValue = conf->bConfigurationValue; + d->u.config.iConfiguration = conf->iConfiguration; + d->u.config.bmAttributes = conf->bmAttributes; + d->u.config.bMaxPower = conf->bMaxPower; + wTotalLength += bLength; + + /* handle grouped interfaces if any */ + for (i = 0; i < conf->nif_groups; i++) { + rc = usb_desc_iface_group(&(conf->if_groups[i]), flags, + dest + wTotalLength, + len - wTotalLength); + if (rc < 0) { + return rc; + } + wTotalLength += rc; + } + + /* handle normal (ungrouped / no IAD) interfaces if any */ + for (i = 0; i < conf->nif; i++) { + rc = usb_desc_iface(conf->ifs + i, flags, + dest + wTotalLength, len - wTotalLength); + if (rc < 0) { + return rc; + } + wTotalLength += rc; + } + + d->u.config.wTotalLength_lo = usb_lo(wTotalLength); + d->u.config.wTotalLength_hi = usb_hi(wTotalLength); + return wTotalLength; +} + +int usb_desc_iface_group(const USBDescIfaceAssoc *iad, int flags, + uint8_t *dest, size_t len) +{ + int pos = 0; + int i = 0; + + /* handle interface association descriptor */ + uint8_t bLength = 0x08; + + if (len < bLength) { + return -1; + } + + dest[0x00] = bLength; + dest[0x01] = USB_DT_INTERFACE_ASSOC; + dest[0x02] = iad->bFirstInterface; + dest[0x03] = iad->bInterfaceCount; + dest[0x04] = iad->bFunctionClass; + dest[0x05] = iad->bFunctionSubClass; + dest[0x06] = iad->bFunctionProtocol; + dest[0x07] = iad->iFunction; + pos += bLength; + + /* handle associated interfaces in this group */ + for (i = 0; i < iad->nif; i++) { + int rc = usb_desc_iface(&(iad->ifs[i]), flags, dest + pos, len - pos); + if (rc < 0) { + return rc; + } + pos += rc; + } + + return pos; +} + +int usb_desc_iface(const USBDescIface *iface, int flags, + uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x09; + int i, rc, pos = 0; + USBDescriptor *d = (void *)dest; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_INTERFACE; + + d->u.interface.bInterfaceNumber = iface->bInterfaceNumber; + d->u.interface.bAlternateSetting = iface->bAlternateSetting; + d->u.interface.bNumEndpoints = iface->bNumEndpoints; + d->u.interface.bInterfaceClass = iface->bInterfaceClass; + d->u.interface.bInterfaceSubClass = iface->bInterfaceSubClass; + d->u.interface.bInterfaceProtocol = iface->bInterfaceProtocol; + d->u.interface.iInterface = iface->iInterface; + pos += bLength; + + for (i = 0; i < iface->ndesc; i++) { + rc = usb_desc_other(iface->descs + i, dest + pos, len - pos); + if (rc < 0) { + return rc; + } + pos += rc; + } + + for (i = 0; i < iface->bNumEndpoints; i++) { + rc = usb_desc_endpoint(iface->eps + i, flags, dest + pos, len - pos); + if (rc < 0) { + return rc; + } + pos += rc; + } + + return pos; +} + +int usb_desc_endpoint(const USBDescEndpoint *ep, int flags, + uint8_t *dest, size_t len) +{ + uint8_t bLength = ep->is_audio ? 0x09 : 0x07; + uint8_t extralen = ep->extra ? ep->extra[0] : 0; + uint8_t superlen = (flags & USB_DESC_FLAG_SUPER) ? 0x06 : 0; + USBDescriptor *d = (void *)dest; + + if (len < bLength + extralen + superlen) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_ENDPOINT; + + d->u.endpoint.bEndpointAddress = ep->bEndpointAddress; + d->u.endpoint.bmAttributes = ep->bmAttributes; + d->u.endpoint.wMaxPacketSize_lo = usb_lo(ep->wMaxPacketSize); + d->u.endpoint.wMaxPacketSize_hi = usb_hi(ep->wMaxPacketSize); + d->u.endpoint.bInterval = ep->bInterval; + if (ep->is_audio) { + d->u.endpoint.bRefresh = ep->bRefresh; + d->u.endpoint.bSynchAddress = ep->bSynchAddress; + } + + if (superlen) { + USBDescriptor *d = (void *)(dest + bLength); + + d->bLength = 0x06; + d->bDescriptorType = USB_DT_ENDPOINT_COMPANION; + + d->u.super_endpoint.bMaxBurst = ep->bMaxBurst; + d->u.super_endpoint.bmAttributes = ep->bmAttributes_super; + d->u.super_endpoint.wBytesPerInterval_lo = + usb_lo(ep->wBytesPerInterval); + d->u.super_endpoint.wBytesPerInterval_hi = + usb_hi(ep->wBytesPerInterval); + } + + if (ep->extra) { + memcpy(dest + bLength + superlen, ep->extra, extralen); + } + + return bLength + extralen + superlen; +} + +int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len) +{ + int bLength = desc->length ? desc->length : desc->data[0]; + + if (len < bLength) { + return -1; + } + + memcpy(dest, desc->data, bLength); + return bLength; +} + +static int usb_desc_cap_usb2_ext(const USBDesc *desc, uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x07; + USBDescriptor *d = (void *)dest; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE_CAPABILITY; + d->u.cap.bDevCapabilityType = USB_DEV_CAP_USB2_EXT; + + d->u.cap.u.usb2_ext.bmAttributes_1 = (1 << 1); /* LPM */ + d->u.cap.u.usb2_ext.bmAttributes_2 = 0; + d->u.cap.u.usb2_ext.bmAttributes_3 = 0; + d->u.cap.u.usb2_ext.bmAttributes_4 = 0; + + return bLength; +} + +static int usb_desc_cap_super(const USBDesc *desc, uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x0a; + USBDescriptor *d = (void *)dest; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_DEVICE_CAPABILITY; + d->u.cap.bDevCapabilityType = USB_DEV_CAP_SUPERSPEED; + + d->u.cap.u.super.bmAttributes = 0; + d->u.cap.u.super.wSpeedsSupported_lo = 0; + d->u.cap.u.super.wSpeedsSupported_hi = 0; + d->u.cap.u.super.bFunctionalitySupport = 0; + d->u.cap.u.super.bU1DevExitLat = 0x0a; + d->u.cap.u.super.wU2DevExitLat_lo = 0x20; + d->u.cap.u.super.wU2DevExitLat_hi = 0; + + if (desc->full) { + d->u.cap.u.super.wSpeedsSupported_lo |= (1 << 1); + d->u.cap.u.super.bFunctionalitySupport = 1; + } + if (desc->high) { + d->u.cap.u.super.wSpeedsSupported_lo |= (1 << 2); + if (!d->u.cap.u.super.bFunctionalitySupport) { + d->u.cap.u.super.bFunctionalitySupport = 2; + } + } + if (desc->super) { + d->u.cap.u.super.wSpeedsSupported_lo |= (1 << 3); + if (!d->u.cap.u.super.bFunctionalitySupport) { + d->u.cap.u.super.bFunctionalitySupport = 3; + } + } + + return bLength; +} + +static int usb_desc_bos(const USBDesc *desc, uint8_t *dest, size_t len) +{ + uint8_t bLength = 0x05; + uint16_t wTotalLength = 0; + uint8_t bNumDeviceCaps = 0; + USBDescriptor *d = (void *)dest; + int rc; + + if (len < bLength) { + return -1; + } + + d->bLength = bLength; + d->bDescriptorType = USB_DT_BOS; + + wTotalLength += bLength; + + if (desc->high != NULL) { + rc = usb_desc_cap_usb2_ext(desc, dest + wTotalLength, + len - wTotalLength); + if (rc < 0) { + return rc; + } + wTotalLength += rc; + bNumDeviceCaps++; + } + + if (desc->super != NULL) { + rc = usb_desc_cap_super(desc, dest + wTotalLength, + len - wTotalLength); + if (rc < 0) { + return rc; + } + wTotalLength += rc; + bNumDeviceCaps++; + } + + d->u.bos.wTotalLength_lo = usb_lo(wTotalLength); + d->u.bos.wTotalLength_hi = usb_hi(wTotalLength); + d->u.bos.bNumDeviceCaps = bNumDeviceCaps; + return wTotalLength; +} + +/* ------------------------------------------------------------------ */ + +static void usb_desc_ep_init(USBDevice *dev) +{ + const USBDescIface *iface; + int i, e, pid, ep; + + usb_ep_init(dev); + for (i = 0; i < dev->ninterfaces; i++) { + iface = dev->ifaces[i]; + if (iface == NULL) { + continue; + } + for (e = 0; e < iface->bNumEndpoints; e++) { + pid = (iface->eps[e].bEndpointAddress & USB_DIR_IN) ? + USB_TOKEN_IN : USB_TOKEN_OUT; + ep = iface->eps[e].bEndpointAddress & 0x0f; + usb_ep_set_type(dev, pid, ep, iface->eps[e].bmAttributes & 0x03); + usb_ep_set_ifnum(dev, pid, ep, iface->bInterfaceNumber); + usb_ep_set_max_packet_size(dev, pid, ep, + iface->eps[e].wMaxPacketSize); + } + } +} + +static const USBDescIface *usb_desc_find_interface(USBDevice *dev, + int nif, int alt) +{ + const USBDescIface *iface; + int g, i; + + if (!dev->config) { + return NULL; + } + for (g = 0; g < dev->config->nif_groups; g++) { + for (i = 0; i < dev->config->if_groups[g].nif; i++) { + iface = &dev->config->if_groups[g].ifs[i]; + if (iface->bInterfaceNumber == nif && + iface->bAlternateSetting == alt) { + return iface; + } + } + } + for (i = 0; i < dev->config->nif; i++) { + iface = &dev->config->ifs[i]; + if (iface->bInterfaceNumber == nif && + iface->bAlternateSetting == alt) { + return iface; + } + } + return NULL; +} + +static int usb_desc_set_interface(USBDevice *dev, int index, int value) +{ + const USBDescIface *iface; + int old; + + iface = usb_desc_find_interface(dev, index, value); + if (iface == NULL) { + return -1; + } + + old = dev->altsetting[index]; + dev->altsetting[index] = value; + dev->ifaces[index] = iface; + usb_desc_ep_init(dev); + + if (old != value) { + usb_device_set_interface(dev, index, old, value); + } + return 0; +} + +static int usb_desc_set_config(USBDevice *dev, int value) +{ + int i; + + if (value == 0) { + dev->configuration = 0; + dev->ninterfaces = 0; + dev->config = NULL; + } else { + for (i = 0; i < dev->device->bNumConfigurations; i++) { + if (dev->device->confs[i].bConfigurationValue == value) { + dev->configuration = value; + dev->ninterfaces = dev->device->confs[i].bNumInterfaces; + dev->config = dev->device->confs + i; + assert(dev->ninterfaces <= USB_MAX_INTERFACES); + } + } + if (i < dev->device->bNumConfigurations) { + return -1; + } + } + + for (i = 0; i < dev->ninterfaces; i++) { + usb_desc_set_interface(dev, i, 0); + } + for (; i < USB_MAX_INTERFACES; i++) { + dev->altsetting[i] = 0; + dev->ifaces[i] = NULL; + } + + return 0; +} + +static void usb_desc_setdefaults(USBDevice *dev) +{ + const USBDesc *desc = usb_device_get_usb_desc(dev); + + assert(desc != NULL); + switch (dev->speed) { + case USB_SPEED_LOW: + case USB_SPEED_FULL: + dev->device = desc->full; + break; + case USB_SPEED_HIGH: + dev->device = desc->high; + break; + case USB_SPEED_SUPER: + dev->device = desc->super; + break; + } + usb_desc_set_config(dev, 0); +} + +void usb_desc_init(USBDevice *dev) +{ + const USBDesc *desc = usb_device_get_usb_desc(dev); + + assert(desc != NULL); + dev->speed = USB_SPEED_FULL; + dev->speedmask = 0; + if (desc->full) { + dev->speedmask |= USB_SPEED_MASK_FULL; + } + if (desc->high) { + dev->speedmask |= USB_SPEED_MASK_HIGH; + } + if (desc->super) { + dev->speedmask |= USB_SPEED_MASK_SUPER; + } + usb_desc_setdefaults(dev); +} + +void usb_desc_attach(USBDevice *dev) +{ + const USBDesc *desc = usb_device_get_usb_desc(dev); + + assert(desc != NULL); + if (desc->super && (dev->port->speedmask & USB_SPEED_MASK_SUPER)) { + dev->speed = USB_SPEED_SUPER; + } else if (desc->high && (dev->port->speedmask & USB_SPEED_MASK_HIGH)) { + dev->speed = USB_SPEED_HIGH; + } else if (desc->full && (dev->port->speedmask & USB_SPEED_MASK_FULL)) { + dev->speed = USB_SPEED_FULL; + } else { + return; + } + usb_desc_setdefaults(dev); +} + +void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str) +{ + USBDescString *s; + + QLIST_FOREACH(s, &dev->strings, next) { + if (s->index == index) { + break; + } + } + if (s == NULL) { + s = calloc(1, sizeof(*s)); + s->index = index; + QLIST_INSERT_HEAD(&dev->strings, s, next); + } + free(s->str); + s->str = strdup(str); +} + +/* + * This function creates a serial number for a usb device. + * The serial number should: + * (a) Be unique within the virtual machine. + * (b) Be constant, so you don't get a new one each + * time the guest is started. + * So we are using the physical location to generate a serial number + * from it. It has three pieces: First a fixed, device-specific + * prefix. Second the device path of the host controller (which is + * the pci address in most cases). Third the physical port path. + * Results in serial numbers like this: "314159-0000:00:1d.7-3". + */ +void usb_desc_create_serial(USBDevice *dev) +{ +// DeviceState *hcd = dev->qdev.parent_bus->parent; + const USBDesc *desc = usb_device_get_usb_desc(dev); + int index = desc->id.iSerialNumber; + char serial[64]; + char *path = NULL; + int dst; + + if (dev->serial) { + /* 'serial' usb bus property has priority if present */ + usb_desc_set_string(dev, index, dev->serial); + return; + } + + assert(index != 0 && desc->str[index] != NULL); + dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]); +// path = qdev_get_dev_path(hcd); + if (path) { + dst += snprintf(serial+dst, sizeof(serial)-dst, "-%s", path); + } + dst += snprintf(serial+dst, sizeof(serial)-dst, "-%s", dev->port->path); + usb_desc_set_string(dev, index, serial); +} + +const char *usb_desc_get_string(USBDevice *dev, uint8_t index) +{ + USBDescString *s; + + QLIST_FOREACH(s, &dev->strings, next) { + if (s->index == index) { + return s->str; + } + } + return NULL; +} + +int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len) +{ + uint8_t bLength, pos, i; + const char *str; + + if (len < 4) { + return -1; + } + + if (index == 0) { + /* language ids */ + dest[0] = 4; + dest[1] = USB_DT_STRING; + dest[2] = 0x09; + dest[3] = 0x04; + return 4; + } + + str = usb_desc_get_string(dev, index); + if (str == NULL) { + str = usb_device_get_usb_desc(dev)->str[index]; + if (str == NULL) { + return 0; + } + } + + bLength = strlen(str) * 2 + 2; + dest[0] = bLength; + dest[1] = USB_DT_STRING; + i = 0; pos = 2; + while (pos+1 < bLength && pos+1 < len) { + dest[pos++] = str[i++]; + dest[pos++] = 0; + } + return pos; +} + +int usb_desc_get_descriptor(USBDevice *dev, USBPacket *p, + int value, uint8_t *dest, size_t len) +{ + const USBDesc *desc = usb_device_get_usb_desc(dev); + const USBDescDevice *other_dev; + uint8_t buf[256]; + uint8_t type = value >> 8; + uint8_t index = value & 0xff; + int flags, ret = -1; + + if (dev->speed == USB_SPEED_HIGH) { + other_dev = usb_device_get_usb_desc(dev)->full; + } else { + other_dev = usb_device_get_usb_desc(dev)->high; + } + + flags = 0; + if (dev->device->bcdUSB >= 0x0300) { + flags |= USB_DESC_FLAG_SUPER; + } + + switch(type) { + case USB_DT_DEVICE: + ret = usb_desc_device(&desc->id, dev->device, buf, sizeof(buf)); + trace_usb_desc_device(dev->addr, len, ret); + break; + case USB_DT_CONFIG: + if (index < dev->device->bNumConfigurations) { + ret = usb_desc_config(dev->device->confs + index, flags, + buf, sizeof(buf)); + } + trace_usb_desc_config(dev->addr, index, len, ret); + break; + case USB_DT_STRING: + ret = usb_desc_string(dev, index, buf, sizeof(buf)); + trace_usb_desc_string(dev->addr, index, len, ret); + break; + case USB_DT_DEVICE_QUALIFIER: + if (other_dev != NULL) { + ret = usb_desc_device_qualifier(other_dev, buf, sizeof(buf)); + } + trace_usb_desc_device_qualifier(dev->addr, len, ret); + break; + case USB_DT_OTHER_SPEED_CONFIG: + if (other_dev != NULL && index < other_dev->bNumConfigurations) { + ret = usb_desc_config(other_dev->confs + index, flags, + buf, sizeof(buf)); + buf[0x01] = USB_DT_OTHER_SPEED_CONFIG; + } + trace_usb_desc_other_speed_config(dev->addr, index, len, ret); + break; + case USB_DT_BOS: + ret = usb_desc_bos(desc, buf, sizeof(buf)); + trace_usb_desc_bos(dev->addr, len, ret); + break; + + case USB_DT_DEBUG: + /* ignore silently */ + break; + + default: + fprintf(stderr, "%s: %d unknown type %d (len %zd)\n", __FUNCTION__, + dev->addr, type, len); + break; + } + + if (ret > 0) { + if (ret > len) { + ret = len; + } + memcpy(dest, buf, ret); + p->actual_length = ret; + ret = 0; + } + return ret; +} + +int usb_desc_handle_control(USBDevice *dev, USBPacket *p, + int request, int value, int index, int length, uint8_t *data) +{ + const USBDesc *desc = usb_device_get_usb_desc(dev); + int ret = -1; + + assert(desc != NULL); + switch(request) { + case DeviceOutRequest | USB_REQ_SET_ADDRESS: + dev->addr = value; + trace_usb_set_addr(dev->addr); + ret = 0; + break; + + case DeviceRequest | USB_REQ_GET_DESCRIPTOR: + ret = usb_desc_get_descriptor(dev, p, value, data, length); + break; + + case DeviceRequest | USB_REQ_GET_CONFIGURATION: + /* + * 9.4.2: 0 should be returned if the device is unconfigured, otherwise + * the non zero value of bConfigurationValue. + */ + data[0] = dev->config ? dev->config->bConfigurationValue : 0; + p->actual_length = 1; + ret = 0; + break; + case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: + ret = usb_desc_set_config(dev, value); + trace_usb_set_config(dev->addr, value, ret); + break; + + case DeviceRequest | USB_REQ_GET_STATUS: { + const USBDescConfig *config = dev->config ? + dev->config : &dev->device->confs[0]; + + data[0] = 0; + /* + * Default state: Device behavior when this request is received while + * the device is in the Default state is not specified. + * We return the same value that a configured device would return if + * it used the first configuration. + */ + if (config->bmAttributes & 0x40) { + data[0] |= 1 << USB_DEVICE_SELF_POWERED; + } + if (dev->remote_wakeup) { + data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP; + } + data[1] = 0x00; + p->actual_length = 2; + ret = 0; + break; + } + case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: + if (value == USB_DEVICE_REMOTE_WAKEUP) { + dev->remote_wakeup = 0; + ret = 0; + } + trace_usb_clear_device_feature(dev->addr, value, ret); + break; + case DeviceOutRequest | USB_REQ_SET_FEATURE: + if (value == USB_DEVICE_REMOTE_WAKEUP) { + dev->remote_wakeup = 1; + ret = 0; + } + trace_usb_set_device_feature(dev->addr, value, ret); + break; + + case InterfaceRequest | USB_REQ_GET_INTERFACE: + if (index < 0 || index >= dev->ninterfaces) { + break; + } + data[0] = dev->altsetting[index]; + p->actual_length = 1; + ret = 0; + break; + case InterfaceOutRequest | USB_REQ_SET_INTERFACE: + ret = usb_desc_set_interface(dev, index, value); + trace_usb_set_interface(dev->addr, index, value, ret); + break; + + } + return ret; +} Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/desc.h Tue Aug 13 06:28:00 2013 (r255863) @@ -0,0 +1,224 @@ +#ifndef QEMU_HW_USB_DESC_H +#define QEMU_HW_USB_DESC_H + +#include + +/* binary representation */ +typedef struct USBDescriptor { + uint8_t bLength; + uint8_t bDescriptorType; + union { + struct { + uint8_t bcdUSB_lo; + uint8_t bcdUSB_hi; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t idVendor_lo; + uint8_t idVendor_hi; + uint8_t idProduct_lo; + uint8_t idProduct_hi; + uint8_t bcdDevice_lo; + uint8_t bcdDevice_hi; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; + } device; + struct { + uint8_t bcdUSB_lo; + uint8_t bcdUSB_hi; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint8_t bNumConfigurations; + uint8_t bReserved; + } device_qualifier; + struct { + uint8_t wTotalLength_lo; + uint8_t wTotalLength_hi; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; + } config; + struct { + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; + } interface; + struct { + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint8_t wMaxPacketSize_lo; + uint8_t wMaxPacketSize_hi; + uint8_t bInterval; + uint8_t bRefresh; /* only audio ep */ + uint8_t bSynchAddress; /* only audio ep */ + } endpoint; + struct { + uint8_t bMaxBurst; + uint8_t bmAttributes; + uint8_t wBytesPerInterval_lo; + uint8_t wBytesPerInterval_hi; + } super_endpoint; + struct { + uint8_t wTotalLength_lo; + uint8_t wTotalLength_hi; + uint8_t bNumDeviceCaps; + } bos; + struct { + uint8_t bDevCapabilityType; + union { + struct { + uint8_t bmAttributes_1; + uint8_t bmAttributes_2; + uint8_t bmAttributes_3; + uint8_t bmAttributes_4; + } usb2_ext; + struct { + uint8_t bmAttributes; + uint8_t wSpeedsSupported_lo; + uint8_t wSpeedsSupported_hi; + uint8_t bFunctionalitySupport; + uint8_t bU1DevExitLat; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 09:28:00 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7E8CCFE for ; Tue, 13 Aug 2013 09:28:00 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 69B9827E5 for ; Tue, 13 Aug 2013 09:28:00 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7D9S0sc058737 for ; Tue, 13 Aug 2013 09:28:00 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7D9S0a4058732 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 09:28:00 GMT (envelope-from ccqin@FreeBSD.org) Date: Tue, 13 Aug 2013 09:28:00 GMT Message-Id: <201308130928.r7D9S0a4058732@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255872 - soc2013/ccqin/head/sys/net80211 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 09:28:00 -0000 Author: ccqin Date: Tue Aug 13 09:28:00 2013 New Revision: 255872 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255872 Log: Add ieee80211_rc_info to ratectl api and finish __complete__ of ieee80211_rc_sample. *) add ieee80211_rc_info to ieee80211_ratectl. then we can conveniently provide more tx info to ratectl algo. *) update ir_rates, ieee80211_ratectl_rates and ieee80211_ratectl_complete_rcflags. *) done __complete__ stuff of ieee80211_rc_sample. Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Tue Aug 13 08:12:57 2013 (r255871) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Tue Aug 13 09:28:00 2013 (r255872) @@ -122,11 +122,13 @@ void ieee80211_ratectl_complete_rcflags(const struct ieee80211_node *ni, - struct ieee80211_rc_series *rc, int shortPreamble) + struct ieee80211_rc_info *rc_info) { const struct ieee80211com *ic = ni->ni_ic; const struct ieee80211vap *vap = ni->ni_vap; const struct ieee80211_rate_table * rt = ic->ic_rt; + struct ieee80211_rc_series *rc = rc_info->ri_rc; + int shortPreamble = rc_info->ri_shortPreamble; uint8_t rate; int i; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Tue Aug 13 08:12:57 2013 (r255871) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Tue Aug 13 09:28:00 2013 (r255872) @@ -83,6 +83,24 @@ uint16_t max4msframelen; }; +/* */ +struct ieee80211_rc_info { + struct ieee80211_rc_series ri_rc[IEEE80211_RATECTL_NUM]; + int ri_framelen; + int ri_shortPreamble; + + /* TX info */ + int ri_success; /* TX success or not */ + int ri_okcnt; /* TX ok with or without retry */ + int ri_failcnt; /* TX retry-fail count */ + int ri_txcnt; /* TX count */ + int ri_retrycnt; /* TX retry count */ + int ri_shortretry; + int ri_longretry; + int ri_finaltsi; + int ri_txrate; /* hw tx rate */ +}; + struct ieee80211_ratectl { const char *ir_name; uint32_t ir_capabilities; /* hardware capabilities offered to rc */ @@ -94,8 +112,7 @@ void (*ir_node_init)(struct ieee80211_node *); void (*ir_node_deinit)(struct ieee80211_node *); int (*ir_rate)(struct ieee80211_node *, void *, uint32_t); - void (*ir_rates)(struct ieee80211_node *, struct ieee80211_rc_series *, - int, size_t); + void (*ir_rates)(struct ieee80211_node *, struct ieee80211_rc_info *); void (*ir_tx_complete)(const struct ieee80211vap *, const struct ieee80211_node *, int, void *, void *); @@ -110,7 +127,7 @@ void ieee80211_ratectl_init(struct ieee80211vap *, uint32_t); void ieee80211_ratectl_set(struct ieee80211vap *, int); void ieee80211_ratectl_complete_rcflags(const struct ieee80211_node *, - struct ieee80211_rc_series *, int) + struct ieee80211_rc_info*) MALLOC_DECLARE(M_80211_RATECTL); @@ -145,14 +162,12 @@ } static void __inline -ieee80211_ratectl_rates(struct ieee80211_node *ni, struct ieee80211_rc_series *rc, - int shortPreamble, size_t frameLen) +ieee80211_ratectl_rates(struct ieee80211_node *ni, struct ieee80211_rc_info *rc_info) { const struct ieee80211vap *vap = ni->ni_vap; - vap->iv_rate->ir_rates(ni, rc, shortPreamble, frameLen); - - ieee80211_ratectl_complete_rcflags(ni, rc, shortPreamble); + vap->iv_rate->ir_rates(ni, rc_info); + ieee80211_ratectl_complete_rcflags(ni, rc_info); } static void __inline Modified: soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Tue Aug 13 08:12:57 2013 (r255871) +++ soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Tue Aug 13 09:28:00 2013 (r255872) @@ -73,7 +73,7 @@ .ir_node_init = sample_node_init, .ir_node_deinit = sample_node_deinit, .ir_rate = sample_rate, - .ir_rates = NULL, + .ir_rates = sample_rates, .ir_tx_complete = sample_tx_complete, .ir_tx_update = sample_tx_update, .ir_setinterval = sample_setinterval, @@ -230,7 +230,7 @@ san->stats[y][rix].ewma_pct = 0; san->stats[y][rix].perfect_tx_time = - calc_usecs_unicast_packet(size, rix, 0, 0, + calc_usecs_unicast_packet(vap, size, rix, 0, 0, (ni->ni_chw == 40)); san->stats[y][rix].average_tx_time = san->stats[y][rix].perfect_tx_time; @@ -778,16 +778,252 @@ } static void +sample_rates(struct ieee80211_node *ni, struct ieee80211_rc_info *rc_info) +{ + struct ieee80211_sample_node *san = ni->ni_rctls; + uint8_t rix0 = sample_rate(ni, NULL, 0); + const struct txschedule *sched = &san->sched[rix0]; + struct ieee80211_rc_series *rc = rc_info->ri_rc; + + KASSERT(rix0 == sched->r0, ("rix0 (%x) != sched->r0 (%x)!\n", + rix0, sched->r0)); + /* XXX */ + rc[0].flags = rc[1].flags = rc[2].flags = rc[3].flags = 0; + + rc[0].rix = sched->r0; + rc[1].rix = sched->r1; + rc[2].rix = sched->r2; + rc[3].rix = sched->r3; + + rc[0].tries = sched->t0; + rc[1].tries = sched->t1; + rc[2].tries = sched->t2; + rc[3].tries = sched->t3; +} + +static void +update_stats(const struct ieee80211vap *vap, + const struct ieee80211_node *ni, + int frame_size, + int rix0, int tries0, + int rix1, int tries1, + int rix2, int tries2, + int rix3, int tries3, + int short_tries, int tries, + int nframes, int nbad) +{ + struct ieee80211_sample_node *san = ni->ni_rctls; + struct ieee80211_sample *sample = san->san_sample; + + const int size_bin = size_to_bin(frame_size); + const int size = bin_to_size(size_bin); + + int is_ht40 = ieee80211_ratectl_hascap_cw40(vap, ni); + int tt, tries_so_far; + int pct; + + if (!IS_RATE_DEFINED(san, rix0)) + return; + tt = calc_usecs_unicast_packet(vap, size, rix0, short_tries, + MIN(tries0, tries) - 1, is_ht40); + tries_so_far = tries0; + + if (tries1 && tries_so_far < tries) { + if (!IS_RATE_DEFINED(san, rix1)) + return; + tt += calc_usecs_unicast_packet(vap, size, rix1, short_tries, + MIN(tries1 + tries_so_far, tries) - tries_so_far - 1, is_ht40); + tries_so_far += tries1; + } + + if (tries2 && tries_so_far < tries) { + if (!IS_RATE_DEFINED(san, rix2)) + return; + tt += calc_usecs_unicast_packet(vap, size, rix2, short_tries, + MIN(tries2 + tries_so_far, tries) - tries_so_far - 1, is_ht40); + tries_so_far += tries2; + } + + if (tries3 && tries_so_far < tries) { + if (!IS_RATE_DEFINED(san, rix3)) + return; + tt += calc_usecs_unicast_packet(vap, size, rix3, short_tries, + MIN(tries3 + tries_so_far, tries) - tries_so_far - 1, is_ht40); + } + + if (san->stats[size_bin][rix0].total_packets < sample->sanple_smoothing_minpackets) { + /* just average the first few packets */ + int avg_tx = san->stats[size_bin][rix0].average_tx_time; + int packets = san->stats[size_bin][rix0].total_packets; + san->stats[size_bin][rix0].average_tx_time = (tt+(avg_tx*packets))/(packets+nframes); + } else { + /* use a ewma */ + san->stats[size_bin][rix0].average_tx_time = + ((san->stats[size_bin][rix0].average_tx_time * sample->sanple_smoothing_rate) + + (tt * (100 - sample->sanple_smoothing_rate))) / 100; + } + + /* + * XXX Don't mark the higher bit rates as also having failed; as this + * unfortunately stops those rates from being tasted when trying to + * TX. This happens with 11n aggregation. + */ + if (nframes == nbad) { + san->stats[size_bin][rix0].successive_failures += nbad; + + } else { + san->stats[size_bin][rix0].packets_acked += (nframes - nbad); + san->stats[size_bin][rix0].successive_failures = 0; + } + san->stats[size_bin][rix0].tries += tries; + san->stats[size_bin][rix0].last_tx = ticks; + san->stats[size_bin][rix0].total_packets += nframes; + + /* update EWMA for this rix */ + + /* Calculate percentage based on current rate */ + if (nframes == 0) + nframes = nbad = 1; + pct = ((nframes - nbad) * 1000) / nframes; + + if (san->stats[size_bin][rix0].total_packets < + sample->sanple_smoothing_minpackets) { + /* just average the first few packets */ + int a_pct = (san->stats[size_bin][rix0].packets_acked * 1000) / + (san->stats[size_bin][rix0].total_packets); + san->stats[size_bin][rix0].ewma_pct = a_pct; + } else { + /* use a ewma */ + san->stats[size_bin][rix0].ewma_pct = + ((san->stats[size_bin][rix0].ewma_pct * sample->sanple_smoothing_rate) + + (pct * (100 - sample->sanple_smoothing_rate))) / 100; + } + + if (rix0 == san->current_sample_rix[size_bin]) { + san->sample_tt[size_bin] = tt; + san->current_sample_rix[size_bin] = -1; + } +} + +static void sample_tx_complete(const struct ieee80211vap *vap, const struct ieee80211_node *ni, int ok, - void *arg1, void *arg2 __unused) + void *arg1, void *arg2) { + struct ieee80211_sample_node *san = ni->ni_rctls; + const struct ieee80211_rate_table *rt = ieee80211_get_ratetable(vap->iv_ic->ic_curchan); + + /* XXX need to change arg2 to pointer of ieee80211_rc_info */ + struct ieee80211_rc_info *rc_info = (struct ieee80211_rc_info*)arg2; + + int final_rix, short_tries, long_tries; + int nframes, nbad; + int frame_size, mrr; + + final_rix = rt->rateCodeToIndex[rc_info->ri_txrate]; + short_tries = rc_info->ri_shortretry; + /* XXX why plus 1 here? */ + long_tries = rc_info->ri_longretry + 1; + + nframes = rc_info->ri_txcnt; + nbad = rc_info->ri_failcnt; + + frame_size = rc_info->ri_framelen; + mrr = 0; + + if (nframes == 0) { + return; + } + + if (frame_size == 0) /* NB: should not happen */ + frame_size = 1500; + + if (san->ratemask == 0) { + return; + } + + if (vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRR) + mrr = 1; + /* XXX check HT protmode too */ + if (mrr && !(vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRRPROT)) + mrr = 0; + + if (!mrr || rc_info->ri_finaltsi == 0) { + if (!IS_RATE_DEFINED(san, final_rix)) { + return; + } + /* + * Only one rate was used; optimize work. + */ + update_stats(vap, ni, frame_size, + final_rix, long_tries, + 0, 0, + 0, 0, + 0, 0, + short_tries, long_tries, + nframes, nbad); + + } else { + int finalTSIdx = rc_info->ri_finaltsi; + int i; + + /* + * NB: series > 0 are not penalized for failure + * based on the try counts under the assumption + * that losses are often bursty and since we + * sample higher rates 1 try at a time doing so + * may unfairly penalize them. + */ + if (rc[0].tries) { + update_stats(vap, ni, frame_size, + rc[0].rix, rc[0].tries, + rc[1].rix, rc[1].tries, + rc[2].rix, rc[2].tries, + rc[3].rix, rc[3].tries, + short_tries, long_tries, + nframes, nbad); + long_tries -= rc[0].tries; + } + + if (rc[1].tries && finalTSIdx > 0) { + update_stats(vap, ni, frame_size, + rc[1].rix, rc[1].tries, + rc[2].rix, rc[2].tries, + rc[3].rix, rc[3].tries, + 0, 0, + short_tries, long_tries, + nframes, nbad); + long_tries -= rc[1].tries; + } + + if (rc[2].tries && finalTSIdx > 1) { + update_stats(vap, ni, frame_size, + rc[2].rix, rc[2].tries, + rc[3].rix, rc[3].tries, + 0, 0, + 0, 0, + short_tries, long_tries, + nframes, nbad); + long_tries -= rc[2].tries; + } + + if (rc[3].tries && finalTSIdx > 2) { + update_stats(vap, ni, frame_size, + rc[3].rix, rc[3].tries, + 0, 0, + 0, 0, + 0, 0, + short_tries, long_tries, + nframes, nbad); + } + } } static void sample_tx_update(const struct ieee80211vap *vap, const struct ieee80211_node *ni, void *arg1, void *arg2, void *arg3) { + /* nothing here. */ } static void Modified: soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h Tue Aug 13 08:12:57 2013 (r255871) +++ soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h Tue Aug 13 09:28:00 2013 (r255872) @@ -139,14 +139,145 @@ return NUM_PACKET_SIZE_BINS-1; } +static uint32_t sample_pkt_txtime(const struct ieee80211_rate_table *rt, + uint32_t frameLen, uint16_t rateix, int isht40, int isShortPreamble) +{ + uint8_t rc; + int numStreams; + + rc = rt->info[rateix].rateCode; + + /* Legacy rate? Return the old way */ + if (! IS_HT_RATE(rc)) + return ieee80211_compute_duration(rt, frameLen, rateix, isShortPreamble); + + /* 11n frame - extract out the number of spatial streams */ + numStreams = HT_RC_2_STREAMS(rc); + KASSERT(numStreams > 0 && numStreams <= 4, + ("number of spatial streams needs to be 1..3: MCS rate 0x%x!", + rateix)); + + return ieee80211_compute_duration_ht(frameLen, rc, numStreams, isht40, isShortPreamble); +} + +#define WIFI_CW_MIN 31 +#define WIFI_CW_MAX 1023 + /* * Calculate the transmit duration of a frame. */ -static unsigned calc_usecs_unicast_packet(int length, +static unsigned calc_usecs_unicast_packet(const struct ieee80211vap *vap, + int length, int rix, int short_retries, int long_retries, int is_ht40) { - /* XXX not done yet */ + const struct ieee80211_rate_table *rt = ieee80211_get_ratetable(vap->iv_ic->ic_curchan); + struct ieee80211com *ic = vap->iv_ic; + int curmode = ieee80211_chan2mode(vap->iv_ic->ic_curchan); + + unsigned t_slot, t_difs, t_sifs; + int rts, cts; + int tt, x, cw, cix; + + int tt = 0; + int x = 0; + int cw = WIFI_CW_MIN; + + KASSERT(rt != NULL, ("no rate table, mode %u", curmode)); + + if (rix >= rt->rateCount) { + printf("bogus rix %d, max %u, mode %u\n", + rix, rt->rateCount, curmode); + return 0; + } + cix = rt->info[rix].controlRate; + /* + * XXX getting mac/phy level timings should be fixed for turbo + * rates, and there is probably a way to get this from the + * hal... + */ + switch (rt->info[rix].phy) { + case IEEE80211_T_OFDM: + t_slot = 9; + t_sifs = 16; + t_difs = 28; + /* fall through */ + case IEEE80211_T_TURBO: + t_slot = 9; + t_sifs = 8; + t_difs = 28; + break; + case IEEE80211_T_HT: + t_slot = 9; + t_sifs = 8; + t_difs = 28; + break; + case IEEE80211_T_DS: + /* fall through to default */ + default: + /* pg 205 ieee.802.11.pdf */ + t_slot = 20; + t_difs = 50; + t_sifs = 10; + } + + rts = cts = 0; + + if ((ic->ic_flags & IEEE80211_F_USEPROT) && + rt->info[rix].phy == IEEE80211_T_OFDM) { + if (ic->ic_protmode == IEEE80211_PROT_RTSCTS) + rts = 1; + else if (ic->ic_protmode == IEEE80211_PROT_CTSONLY) + cts = 1; + + int protrix; + if (curmode == IEEE80211_MODE_11G) + protrix = rt->rateCodeToIndex[2*2]; + else + protrix = rt->rateCodeToIndex[2*1]; + if (0xff == protrix) + protrix = 0; + + cix = rt->info[protrix].controlRate; + } + + if (0 /*length > ic->ic_rtsthreshold */) { + rts = 1; + } + + if (rts || cts) { + int ctsrate; + int ctsduration = 0; + + /* NB: this is intentionally not a runtime check */ + KASSERT(cix < rt->rateCount, + ("bogus cix %d, max %u, mode %u\n", cix, rt->rateCount, + curmode)); + + ctsrate = rt->info[cix].rateCode | rt->info[cix].shortPreamble; + if (rts) /* SIFS + CTS */ + ctsduration += rt->info[cix].spAckDuration; + + /* XXX assumes short preamble */ + ctsduration += sample_pkt_txtime(rt, length, rix, is_ht40, 0); + + if (cts) /* SIFS + ACK */ + ctsduration += rt->info[cix].spAckDuration; + + tt += (short_retries + 1) * ctsduration; + } + tt += t_difs; + + /* XXX assumes short preamble */ + tt += (long_retries+1)*sample_pkt_txtime(rt, length, rix, is_ht40, 0); + + tt += (long_retries+1)*(t_sifs + rt->info[rix].spAckDuration); + + for (x = 0; x <= short_retries + long_retries; x++) { + cw = MIN(WIFI_CW_MAX, (cw + 1) * 2); + tt += (t_slot * cw/2); + } + return tt; } #endif /* _NET80211_IEEE80211_RATECTL_SAMPLE_H_ */ From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 10:30:54 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 78D51B88 for ; Tue, 13 Aug 2013 10:30:54 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6463E2B4E for ; Tue, 13 Aug 2013 10:30:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7DAUslP030255 for ; Tue, 13 Aug 2013 10:30:54 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7DAUstj030195 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 10:30:54 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 13 Aug 2013 10:30:54 GMT Message-Id: <201308131030.r7DAUstj030195@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255876 - in soc2013/dpl: . head/lib/libzcap head/lib/libzcap/zlibworker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 10:30:54 -0000 Author: dpl Date: Tue Aug 13 10:30:53 2013 New Revision: 255876 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255876 Log: Writing the skeleton to start porting all the deflate related functions. Deleted: soc2013/dpl/datapasstest.c Modified: soc2013/dpl/head/lib/libzcap/adler32.c soc2013/dpl/head/lib/libzcap/commands.c soc2013/dpl/head/lib/libzcap/crc32.c soc2013/dpl/head/lib/libzcap/deflate.c soc2013/dpl/head/lib/libzcap/gzguts.h soc2013/dpl/head/lib/libzcap/gzlib.c soc2013/dpl/head/lib/libzcap/gzread.c soc2013/dpl/head/lib/libzcap/gzwrite.c soc2013/dpl/head/lib/libzcap/zlibworker/comands.c soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Modified: soc2013/dpl/head/lib/libzcap/adler32.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/adler32.c Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/adler32.c Tue Aug 13 10:30:53 2013 (r255876) @@ -68,16 +68,18 @@ const Bytef *buf; uInt len; { - /* Send packets of 100kb size at most. */ - if ((sizeof(*buf)*len) > (5*1024)) { - while( (len -= (5*1024)) > 0) { - buf += (5*1024)/sizeof(*buf); - adler = zcapcmd_adler32(adler, buf, len); - } - } else { - adler = zcapcmd_adler32( adler, buf, len); +#define MAX (5*1024) + int ret = 0; + /* We have to send the buffers value back and forth */ + /* Send packets of 5kb size at most. */ + while(len > MAX) { + ret += zcapcmd_adler32(file, buf, MAX); + buf += MAX; + len -= MAX; } - return adler; + ret += zcapcmd_adler32(file, buf, len); + + return ret; } /* ========================================================================= */ Modified: soc2013/dpl/head/lib/libzcap/commands.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/commands.c Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/commands.c Tue Aug 13 10:30:53 2013 (r255876) @@ -41,11 +41,57 @@ #include +/* Basic functions */ +int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, + int memLevel, int strategy, const char * version, + int stream_size); +int zcapcmd_deflate(z_streamp strm, int flush); +int zcapcmd_deflateEnd(z_streamp strm); +int zcapcmd_inflateInit(z_streamp strm); +int zcapcmd_inflate(z_streamp strm, int flush); +int zcapcmd_inflateEnd(z_streamp strm); + +/* Advanced functions */ +int zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_deflateCopy(z_streamp dest, z_streamp source); +int zcapcmd_deflateReset(z_streamp strm); +int zcapcmd_deflateParams(z_streamp strm, int level, int strategy); +int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain); +int zcapcmd_deflateBound(z_streamp strm, uLong sourceLen); +int zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits); +int zcapcmd_deflatePrime(z_streamp strm, int bits, int value); +int zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head); + +int zcapcmd_inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_inflateSync(z_streamp strm); +int zcapcmd_inflateCopy(z_streamp strm, z_streamp source); +int zcapcmd_inflateReset(z_streamp strm); +int zcapcmd_inflateReset2(z_streamp strm, int windowBits); +int zcapcmd_inflatePrime(z_streamp strm, int bits, int value); +int zcapcmd_inflateMark(z_streamp strm); +int zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head); +int zcapcmd_inflateBackInit(z_streamp strm, int windowBits, + unsigned char *window); +int zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc, + out_func out, void *out_desc); +int zcapcmd_inflateBackEnd(z_streamp strm); +int zcapcmd_zlibCompileFlags(z_streamp strm); + +/* Utility functions */ uLong zcapcmd_compressBound(uLong sourceLen); +/* gzip file functions */ gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode); int zcapcmd_gzbuffer(gzFile file, unsigned size); int zcapcmd_gzsetparams(gzFile file, int level, int strategy); +int zcapcmd_gzread(gzFile file, voidp buf, unsigned len); +int zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len); +int zcapcmd_gzprintf(gzFile file, const char *format, ...); int zcapcmd_gzputs(gzFile file, const char *s); char *zcapcmd_gzgets(gzFile file, char *buf, int len); int zcapcmd_gzputc(gzFile file, int c); @@ -55,6 +101,7 @@ int zcapcmd_simplecommand(gzFile file, int command); char * zcapcmd_gzerror(gzFile file, int *errnum); +/* checksum functions */ uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len); uLong zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 ); uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len); @@ -62,8 +109,116 @@ extern pid_t pid; extern nvlist_t *sendCommand(nvlist_t *); +extern void * data; + size_t gzFilesize = sizeof(struct gzFile_s); +size_t zstreamsize = sizeof(z_stream); + +uLong +zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, + int memLevel, int strategy, const char * version, + int stream_size) +{ + nvlist_t *nvl, *args, *result; + uLong ret; + zstream * dataplace; + + if (pid == 0) + startChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "level", level); + nvlist_add_number(args, "method", method); + nvlist_add_number(args, "windowBits", windowBits); + nvlist_add_number(args, "memLevel", memLevel); + nvlist_add_number(args, "strategy", strategy); + nvlist_add_string(args, "version", version); + nvlist_add_number(args, "stream_size", stream_size); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + /* We take the "good" struct from the worker. + Here we have the good internal_state. + When we work on the data now, we have to pass it in + buffers, and sync: next_in, avail_in, total_in, next_out, + avail_out, total_out. */ + if (ret == Z_OK) + dataplace = malloc(zstreamsize); + z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(dataplace, strm, zstreamsize); + nvlist_destroy(result); + return(ret); +} + +int +zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength) +{ + nvlist_t *nvl, *args, *result; + uLong ret; + zstream * dataplace; + + if (pid == 0) + startChild(); + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dictionary", *dictionary, dictLength); + nvlist_add_number(args, "dictLength", dictLength); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + if (ret == Z_OK) + dataplace = malloc(zstreamsize); + z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + nvlist_destroy(result); + return(ret); +} + +int +zcapcmd_deflateCopy(z_streamp dest, z_streamp source) +{ + nvlist_t *nvl, *args, *result; + uLong ret; + zstream * dataplace; + + if (pid == 0) + startChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dest", *dest, zstreamsize); + nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + /* The two z_streamp are now copied at the worker. */ + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream strm = nvlist_take_binary(result, "dest", zstreamsize); + if (ret == Z_OK) + dataplace = malloc(zstreamsize); + memcpy(dataplace, strm, zstreamsize); + nvlist_destroy(result); + return(ret); +} uLong zcapcmd_compressBound(uLong sourceLen) @@ -170,11 +325,86 @@ return(ret); } -/* XXX -zcapcmd_gzread(file, s); -zcapcmd_gzwrite(file, s); -zcapcmd_gzprintf(file, s); -*/ +int +zcapcmd_gzread(gzFile file, voidp buf, unsigned len) +{ + nvlist_t *nvl, *args, *result; + void * data; + + if (pid == 0) + startChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_GZREAD); + nvlist_add_binary(args, "file", file, gzFilesize); + nvlist_add_number(args, "len", len); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + int ret = nvlist_take_number(result, "result"); + data = nvlist_take_binary(result, "data", len); + memcpy(buf, data, (size_t)len); + nvlist_destroy(result); + return(ret); +} + +int +zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len) +{ + nvlist_t *nvl, *args, *result; + void * data; + + if (pid == 0) + startChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_GZWRITE); + nvlist_add_binary(args, "file", file, gzFilesize); + nvlist_add_binary(args, "data", buf, len); + nvlist_add_number(args, "len", len); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + int ret = nvlist_take_number(result, "result"); + nvlist_destroy(result); + return(ret); +} + +int +zcapcmd_gzprintf(gzFile file, char * str) +{ + nvlist_t *nvl, *args, *result; + void * data; + + if (pid == 0) + startChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_GZPRINTF); + nvlist_add_binary(args, "file", file, gzFilesize); + nvlist_add_string(args, "str", str); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + int ret = nvlist_take_number(result, "result"); + nvlist_destroy(result); + return(ret); +} int zcapcmd_gzputs(gzFile file, const char *s) Modified: soc2013/dpl/head/lib/libzcap/crc32.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/crc32.c Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/crc32.c Tue Aug 13 10:30:53 2013 (r255876) @@ -207,18 +207,18 @@ const unsigned char FAR *buf; uInt len; { - if (buf == Z_NULL) return 0UL; - - /* Send packets of 100kb size at most. */ - if ((sizeof(*buf)*len) > (5*1024)) { - while( (len -= (5*1024)) > 0) { - buf += (5*1024)/sizeof(*buf); - crc = zcapcmd_crc32(crc, buf, len); - } - } else { - crc = zcapcmd_crc32( crc, buf, len); +#define MAX (5*1024) + int ret = 0; + /* We have to send the buffers value back and forth */ + /* Send packets of 5kb size at most. */ + while(len > MAX) { + ret += zcapcmd_crc32(file, buf, MAX); + buf += MAX; + len -= MAX; } - return crc; + ret += zcapcmd_crc32(file, buf, len); + + return ret; } #ifdef BYFOUR Modified: soc2013/dpl/head/lib/libzcap/deflate.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/deflate.c Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/deflate.c Tue Aug 13 10:30:53 2013 (r255876) @@ -210,6 +210,7 @@ } /* ========================================================================= */ +extern int zcapcmd_deflateInit(); int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, version, stream_size) z_streamp strm; @@ -221,313 +222,81 @@ const char *version; int stream_size; { - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); + return zcapcmd_deflateInit(strm, level, method, windowBits, + memLevel, strategy, version, stream_size); } /* ========================================================================= */ +extern int zcapcmd_deflateSetDictionary(); int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) z_streamp strm; const Bytef *dictionary; uInt dictLength; { - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - z_const unsigned char *next; +#define MAX (5*1024) + int ret = 0; + /* XXX - This won't work so easily. */ + /* We have to send the buffers value back and forth */ + /* Send packets of 5kb size at most. */ + while(dictLength > MAX) { + ret += zcapcmd_crc32(strm, dictionary, MAX); + dictionary += MAX; + dictLength -= MAX; + } + ret += zcapcmd_crc32(strm, dictionary, dictLength); - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (z_const Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = s->wrap ? INIT_STATE : BUSY_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - - return Z_OK; + return ret; } /* ========================================================================= */ +extern int zcapcmd_deflateReset(); int ZEXPORT deflateReset (strm) z_streamp strm; { - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; + return zcapcmd_deflateReset(strm); } /* ========================================================================= */ +extern int zcapcmd_deflateSetHeader(); int ZEXPORT deflateSetHeader (strm, head) z_streamp strm; gz_headerp head; { - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (strm->state->wrap != 2) return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; + return zcapcmd_deflateSetHeader(strm); } /* ========================================================================= */ +extern int zcapcmd_deflatePending(); int ZEXPORT deflatePending (strm, pending, bits) unsigned *pending; int *bits; z_streamp strm; { - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; + return zcapcmd_deflatePending(strm, pending, bits); } /* ========================================================================= */ +extern int zcapcmd_deflatePrime(); int ZEXPORT deflatePrime (strm, bits, value) z_streamp strm; int bits; int value; { - deflate_state *s; - int put; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; + return zcapcmd_deflatePrime(strm, bits, value); } /* ========================================================================= */ +extern int zcapcmd_deflateParams(); int ZEXPORT deflateParams(strm, level, strategy) z_streamp strm; int level; int strategy; { - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_BLOCK); - if (err == Z_BUF_ERROR && s->pending == 0) - err = Z_OK; - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; + return zcapcmd_deflateParams(strm, level, strategy); } /* ========================================================================= */ +extern int zcapcmd_deflateTune(); int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) z_streamp strm; int good_length; @@ -535,15 +304,7 @@ int nice_length; int max_chain; { - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = good_length; - s->max_lazy_match = max_lazy; - s->nice_match = nice_length; - s->max_chain_length = max_chain; - return Z_OK; + return zcapcmd_deflateTune(strm, good_length, max_lazy, nice_length, max_chain); } /* ========================================================================= @@ -563,61 +324,12 @@ * upper bound of about 14% expansion does not seem onerous for output buffer * allocation. */ +extern int zcapcmd_deflateBound(); uLong ZEXPORT deflateBound(strm, sourceLen) z_streamp strm; uLong sourceLen; { - deflate_state *s; - uLong complen, wraplen; - Bytef *str; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* if can't get parameters, return conservative bound plus zlib wrapper */ - if (strm == Z_NULL || strm->state == Z_NULL) - return complen + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return conservative bound */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; + return zcapcmd_deflateBound(strm, sourceLen); } /* ========================================================================= @@ -662,6 +374,7 @@ } /* ========================================================================= */ +extern int zcapcmd_deflate(); int ZEXPORT deflate (strm, flush) z_streamp strm; int flush; @@ -673,7 +386,6 @@ flush > Z_BLOCK || flush < 0) { return Z_STREAM_ERROR; } - s = strm->state; if (strm->next_out == Z_NULL || (strm->next_in == Z_NULL && strm->avail_in != 0) || @@ -682,6 +394,7 @@ } if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); + s = strm->state; s->strm = strm; /* just in case */ old_flush = s->last_flush; s->last_flush = flush; @@ -976,34 +689,12 @@ } /* ========================================================================= */ +int zcapcmd_deflateEnd(); int ZEXPORT deflateEnd (strm) z_streamp strm; { - int status; - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && - status != EXTRA_STATE && - status != NAME_STATE && - status != COMMENT_STATE && - status != HCRC_STATE && - status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; + retrurn zcapcmd_deflateEnd(strm); } /* ========================================================================= @@ -1011,6 +702,7 @@ * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ +extern zcapcmd_deflateCopy(); int ZEXPORT deflateCopy (dest, source) z_streamp dest; z_streamp source; @@ -1018,51 +710,7 @@ #ifdef MAXSEG_64K return Z_STREAM_ERROR; #else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; + return zcapcmd_deflateCopy(dest, source); #endif /* MAXSEG_64K */ } Modified: soc2013/dpl/head/lib/libzcap/gzguts.h ============================================================================== --- soc2013/dpl/head/lib/libzcap/gzguts.h Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/gzguts.h Tue Aug 13 10:30:53 2013 (r255876) @@ -192,12 +192,6 @@ } gz_state; typedef gz_state FAR *gz_statep; -/* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); -#if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); -#endif - /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ Modified: soc2013/dpl/head/lib/libzcap/gzlib.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/gzlib.c Tue Aug 13 09:58:27 2013 (r255875) +++ soc2013/dpl/head/lib/libzcap/gzlib.c Tue Aug 13 10:30:53 2013 (r255876) @@ -19,264 +19,14 @@ #endif #endif -/* Local functions */ -local void gz_reset OF((gz_statep)); -local gzFile gz_open OF((const void *, int, const char *)); - -#if defined UNDER_CE - -/* Map the Windows error number in ERROR to a locale-dependent error message - string and return a pointer to it. Typically, the values for ERROR come - from GetLastError. - - The string pointed to shall not be modified by the application, but may be - overwritten by a subsequent call to gz_strwinerror - - The gz_strwinerror function does not change the current setting of - GetLastError. */ -char ZLIB_INTERNAL *gz_strwinerror (error) - DWORD error; -{ - static char buf[1024]; - - wchar_t *msgbuf; - DWORD lasterr = GetLastError(); - DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - error, - 0, /* Default language */ - (LPVOID)&msgbuf, - 0, - NULL); - if (chars != 0) { - /* If there is an \r\n appended, zap it. */ - if (chars >= 2 - && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { - chars -= 2; - msgbuf[chars] = 0; - } - - if (chars > sizeof (buf) - 1) { - chars = sizeof (buf) - 1; - msgbuf[chars] = 0; - } - - wcstombs(buf, msgbuf, chars + 1); - LocalFree(msgbuf); - } - else { - sprintf(buf, "unknown win32 error (%ld)", error); - } - - SetLastError(lasterr); - return buf; -} - -#endif /* UNDER_CE */ - -/* Reset gzip file state */ -local void gz_reset(state) - gz_statep state; -{ - state->x.have = 0; /* no output data available */ - if (state->mode == GZ_READ) { /* for reading ... */ - state->eof = 0; /* not at end of file */ - state->past = 0; /* have not read past end yet */ - state->how = LOOK; /* look for gzip header */ - } - state->seek = 0; /* no seek request pending */ - gz_error(state, Z_OK, NULL); /* clear error */ - state->x.pos = 0; /* no uncompressed data yet */ - state->strm.avail_in = 0; /* no input data yet */ -} - -/* Open a gzip file either by name or file descriptor. */ -local gzFile gz_open(path, fd, mode) - const void *path; - int fd; - const char *mode; -{ - gz_statep state; - size_t len; - int oflag; -#ifdef O_CLOEXEC - int cloexec = 0; -#endif -#ifdef O_EXCL - int exclusive = 0; -#endif *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 19:25:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 274E2522 for ; Tue, 13 Aug 2013 19:25:36 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 141BA2EC4 for ; Tue, 13 Aug 2013 19:25:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7DJPZ8t003633 for ; Tue, 13 Aug 2013 19:25:35 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7DJPZVQ003625 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 19:25:35 GMT (envelope-from syuu@FreeBSD.org) Date: Tue, 13 Aug 2013 19:25:35 GMT Message-Id: <201308131925.r7DJPZVQ003625@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255886 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 19:25:36 -0000 Author: syuu Date: Tue Aug 13 19:25:35 2013 New Revision: 255886 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255886 Log: move ARRAY_SIZE to header Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/host-libusb.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 18:51:26 2013 (r255885) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 19:25:35 2013 (r255886) @@ -21,6 +21,9 @@ .PATH: ${.CURDIR}/usb/gpl SRCS+= desc.c +.PATH: ${.CURDIR}/usb/lgpl +SRCS+= dev-serial.c + NO_MAN= DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBPTHREAD} Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/host-libusb.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/host-libusb.c Tue Aug 13 18:51:26 2013 (r255885) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/host-libusb.c Tue Aug 13 19:25:35 2013 (r255886) @@ -53,7 +53,6 @@ OBJECT_CHECK(USBHostDevice, (obj), TYPE_USB_HOST_DEVICE) #endif #define USB_HOST_DEVICE(obj) ((struct USBHostDevice *)obj) -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define trace_usb_host_req_complete(a,b,c,d,e) #define trace_usb_host_iso_start(a,b,c) From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 19:29:39 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0369E57B for ; Tue, 13 Aug 2013 19:29:39 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E43292EF5 for ; Tue, 13 Aug 2013 19:29:38 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7DJTc18010778 for ; Tue, 13 Aug 2013 19:29:38 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7DJTc0B010776 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 19:29:38 GMT (envelope-from syuu@FreeBSD.org) Date: Tue, 13 Aug 2013 19:29:38 GMT Message-Id: <201308131929.r7DJTc0B010776@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255887 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 19:29:39 -0000 Author: syuu Date: Tue Aug 13 19:29:38 2013 New Revision: 255887 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255887 Log: revert Makefile changes Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 19:25:35 2013 (r255886) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 19:29:38 2013 (r255887) @@ -21,9 +21,6 @@ .PATH: ${.CURDIR}/usb/gpl SRCS+= desc.c -.PATH: ${.CURDIR}/usb/lgpl -SRCS+= dev-serial.c - NO_MAN= DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBPTHREAD} From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 21:42:58 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F034B6CA for ; Tue, 13 Aug 2013 21:42:58 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id DD68C27F9 for ; Tue, 13 Aug 2013 21:42:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7DLgwNg092736 for ; Tue, 13 Aug 2013 21:42:58 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7DLgwcp092734 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 21:42:58 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 13 Aug 2013 21:42:58 GMT Message-Id: <201308132142.r7DLgwcp092734@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255897 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 21:42:59 -0000 Author: mattbw Date: Tue Aug 13 21:42:58 2013 New Revision: 255897 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255897 Log: Added some more event handlers. This does not fully fix the issue of some jobs exiting with only "Fatal error", but might remedy some situations. More investigation is required. Modified: soc2013/mattbw/backend/event.c Modified: soc2013/mattbw/backend/event.c ============================================================================== --- soc2013/mattbw/backend/event.c Tue Aug 13 20:38:55 2013 (r255896) +++ soc2013/mattbw/backend/event.c Tue Aug 13 21:42:58 2013 (r255897) @@ -87,6 +87,11 @@ event->e_integrity_conflict.pkg_name); break; case PKG_EVENT_NEWPKGVERSION: + /* TODO: find a better enum for this? */ + ERR(backend, + PK_ERROR_ENUM_PACKAGE_INSTALL_BLOCKED, + "A new version of pkg is available; install that first."); + break; case PKG_EVENT_NOTICE: case PKG_EVENT_INCREMENTAL_UPDATE: /* Unimplemented */ @@ -99,12 +104,34 @@ break; case PKG_EVENT_ERRNO: case PKG_EVENT_ARCHIVE_COMP_UNSUP: + /* Unimplemented */ + break; case PKG_EVENT_ALREADY_INSTALLED: + ERR(backend, + PK_ERROR_ENUM_PACKAGE_ALREADY_INSTALLED, + "Already installed."); + break; case PKG_EVENT_FAILED_CKSUM: case PKG_EVENT_CREATE_DB_ERROR: + /* Unimplemented */ + break; case PKG_EVENT_LOCKED: + /* TODO: find a better enum for this? */ + ERR(backend, + PK_ERROR_ENUM_PACKAGE_INSTALL_BLOCKED, + "Package is locked."); + break; case PKG_EVENT_REQUIRED: + /* TODO: find a better enum for this? */ + ERR(backend, + PK_ERROR_ENUM_CANNOT_REMOVE_SYSTEM_PACKAGE, + "Package is required."); + break; case PKG_EVENT_MISSING_DEP: + ERR(backend, + PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, + "Package is missing a dependency."); + break; case PKG_EVENT_NOREMOTEDB: case PKG_EVENT_NOLOCALDB: /* Unimplemented */ From owner-svn-soc-all@FreeBSD.ORG Tue Aug 13 22:42:31 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 10847FCD for ; Tue, 13 Aug 2013 22:42:31 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id F05852B90 for ; Tue, 13 Aug 2013 22:42:30 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7DMgUTB032267 for ; Tue, 13 Aug 2013 22:42:30 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7DMgUwT032263 for svn-soc-all@FreeBSD.org; Tue, 13 Aug 2013 22:42:30 GMT (envelope-from syuu@FreeBSD.org) Date: Tue, 13 Aug 2013 22:42:30 GMT Message-Id: <201308132242.r7DMgUwT032263@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255905 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb/gpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2013 22:42:31 -0000 Author: syuu Date: Tue Aug 13 22:42:30 2013 New Revision: 255905 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255905 Log: import LGPL tainted dev-serial.c Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/char.h soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 21:56:16 2013 (r255904) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Tue Aug 13 22:42:30 2013 (r255905) @@ -19,7 +19,7 @@ CFLAGS+=-I${.CURDIR}/usb/include -I${.CURDIR} SRCS+= core.c hcd-uhci.c host-libusb.c dev-hub.c .PATH: ${.CURDIR}/usb/gpl -SRCS+= desc.c +SRCS+= desc.c dev-serial.c NO_MAN= Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/char.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/char.h Tue Aug 13 22:42:30 2013 (r255905) @@ -0,0 +1,303 @@ +#ifndef QEMU_CHAR_H +#define QEMU_CHAR_H + +//#include "qemu-common.h" +//#include "qemu/queue.h" +//#include "qemu/option.h" +//#include "qemu/config-file.h" +//#include "block/aio.h" +//#include "qapi/qmp/qobject.h" +//#include "qapi/qmp/qstring.h" +//#include "qemu/main-loop.h" + +/* character device */ + +#define CHR_EVENT_BREAK 0 /* serial break char */ +#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ +#define CHR_EVENT_OPENED 2 /* new connection established */ +#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */ +#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */ +#define CHR_EVENT_CLOSED 5 /* connection closed */ + + +#define CHR_IOCTL_SERIAL_SET_PARAMS 1 +typedef struct { + int speed; + int parity; + int data_bits; + int stop_bits; +} QEMUSerialSetParams; + +#define CHR_IOCTL_SERIAL_SET_BREAK 2 + +#define CHR_IOCTL_PP_READ_DATA 3 +#define CHR_IOCTL_PP_WRITE_DATA 4 +#define CHR_IOCTL_PP_READ_CONTROL 5 +#define CHR_IOCTL_PP_WRITE_CONTROL 6 +#define CHR_IOCTL_PP_READ_STATUS 7 +#define CHR_IOCTL_PP_EPP_READ_ADDR 8 +#define CHR_IOCTL_PP_EPP_READ 9 +#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10 +#define CHR_IOCTL_PP_EPP_WRITE 11 +#define CHR_IOCTL_PP_DATA_DIR 12 + +#define CHR_IOCTL_SERIAL_SET_TIOCM 13 +#define CHR_IOCTL_SERIAL_GET_TIOCM 14 + +#define CHR_TIOCM_CTS 0x020 +#define CHR_TIOCM_CAR 0x040 +#define CHR_TIOCM_DSR 0x100 +#define CHR_TIOCM_RI 0x080 +#define CHR_TIOCM_DTR 0x002 +#define CHR_TIOCM_RTS 0x004 + +#if 0 +typedef void IOEventHandler(void *opaque, int event); + +struct CharDriverState { + void (*init)(struct CharDriverState *s); + int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); + GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); + void (*chr_update_read_handler)(struct CharDriverState *s); + int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); + int (*get_msgfd)(struct CharDriverState *s); + int (*chr_add_client)(struct CharDriverState *chr, int fd); + IOEventHandler *chr_event; + IOCanReadHandler *chr_can_read; + IOReadHandler *chr_read; + void *handler_opaque; + void (*chr_close)(struct CharDriverState *chr); + void (*chr_accept_input)(struct CharDriverState *chr); + void (*chr_set_echo)(struct CharDriverState *chr, bool echo); + void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); + void *opaque; + char *label; + char *filename; + int be_open; + int fe_open; + int explicit_fe_open; + int explicit_be_open; + int avail_connections; + int is_mux; + QemuOpts *opts; + QTAILQ_ENTRY(CharDriverState) next; +}; + +/** + * @qemu_chr_new_from_opts: + * + * Create a new character backend from a QemuOpts list. + * + * @opts see qemu-config.c for a list of valid options + * @init not sure.. + * + * Returns: a new character backend + */ +CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, + void (*init)(struct CharDriverState *s), + Error **errp); + +/** + * @qemu_chr_new: + * + * Create a new character backend from a URI. + * + * @label the name of the backend + * @filename the URI + * @init not sure.. + * + * Returns: a new character backend + */ +CharDriverState *qemu_chr_new(const char *label, const char *filename, + void (*init)(struct CharDriverState *s)); + +/** + * @qemu_chr_delete: + * + * Destroy a character backend. + */ +void qemu_chr_delete(CharDriverState *chr); + +/** + * @qemu_chr_fe_set_echo: + * + * Ask the backend to override its normal echo setting. This only really + * applies to the stdio backend and is used by the QMP server such that you + * can see what you type if you try to type QMP commands. + * + * @echo true to enable echo, false to disable echo + */ +void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo); + +/** + * @qemu_chr_fe_set_open: + * + * Set character frontend open status. This is an indication that the + * front end is ready (or not) to begin doing I/O. + */ +void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open); + +/** + * @qemu_chr_fe_printf: + * + * Write to a character backend using a printf style interface. + * + * @fmt see #printf + */ +void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); + +int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data); + +/** + * @qemu_chr_fe_write: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); + +/** + * @qemu_chr_fe_write_all: + * + * Write data to a character backend from the front end. This function will + * send data from the front end to the back end. Unlike @qemu_chr_fe_write, + * this function will block if the back end cannot consume all of the data + * attempted to be written. + * + * @buf the data + * @len the number of bytes to send + * + * Returns: the number of bytes consumed + */ +int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); + +/** + * @qemu_chr_fe_ioctl: + * + * Issue a device specific ioctl to a backend. + * + * @cmd see CHR_IOCTL_* + * @arg the data associated with @cmd + * + * Returns: if @cmd is not supported by the backend, -ENOTSUP, otherwise the + * return value depends on the semantics of @cmd + */ +int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg); + +/** + * @qemu_chr_fe_get_msgfd: + * + * For backends capable of fd passing, return the latest file descriptor passed + * by a client. + * + * Returns: -1 if fd passing isn't supported or there is no pending file + * descriptor. If a file descriptor is returned, subsequent calls to + * this function will return -1 until a client sends a new file + * descriptor. + */ +int qemu_chr_fe_get_msgfd(CharDriverState *s); + +/** + * @qemu_chr_fe_claim: + * + * Claim a backend before using it, should be called before calling + * qemu_chr_add_handlers(). + * + * Returns: -1 if the backend is already in use by another frontend, 0 on + * success. + */ +int qemu_chr_fe_claim(CharDriverState *s); + +/** + * @qemu_chr_fe_claim_no_fail: + * + * Like qemu_chr_fe_claim, but will exit qemu with an error when the + * backend is already in use. + */ +void qemu_chr_fe_claim_no_fail(CharDriverState *s); + +/** + * @qemu_chr_fe_claim: + * + * Release a backend for use by another frontend. + * + * Returns: -1 if the backend is already in use by another frontend, 0 on + * success. + */ +void qemu_chr_fe_release(CharDriverState *s); + +/** + * @qemu_chr_be_can_write: + * + * Determine how much data the front end can currently accept. This function + * returns the number of bytes the front end can accept. If it returns 0, the + * front end cannot receive data at the moment. The function must be polled + * to determine when data can be received. + * + * Returns: the number of bytes the front end can receive via @qemu_chr_be_write + */ +int qemu_chr_be_can_write(CharDriverState *s); + +/** + * @qemu_chr_be_write: + * + * Write data from the back end to the front end. Before issuing this call, + * the caller should call @qemu_chr_be_can_write to determine how much data + * the front end can currently accept. + * + * @buf a buffer to receive data from the front end + * @len the number of bytes to receive from the front end + */ +void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len); + + +/** + * @qemu_chr_be_event: + * + * Send an event from the back end to the front end. + * + * @event the event to send + */ +void qemu_chr_be_event(CharDriverState *s, int event); + +void qemu_chr_add_handlers(CharDriverState *s, + IOCanReadHandler *fd_can_read, + IOReadHandler *fd_read, + IOEventHandler *fd_event, + void *opaque); + +void qemu_chr_be_generic_open(CharDriverState *s); +void qemu_chr_accept_input(CharDriverState *s); +int qemu_chr_add_client(CharDriverState *s, int fd); +void qemu_chr_info_print(Monitor *mon, const QObject *ret_data); +void qemu_chr_info(Monitor *mon, QObject **ret_data); +CharDriverState *qemu_chr_find(const char *name); + +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); + +void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *)); +void register_char_driver_qapi(const char *name, ChardevBackendKind kind, + void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)); + +/* add an eventfd to the qemu devices that are polled */ +CharDriverState *qemu_chr_open_eventfd(int eventfd); + +extern int term_escape_char; + +CharDriverState *qemu_char_get_next_serial(void); + +/* msmouse */ +CharDriverState *qemu_chr_open_msmouse(void); + +/* baum.c */ +CharDriverState *chr_baum_init(void); +#endif + +#endif Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Tue Aug 13 22:42:30 2013 (r255905) @@ -0,0 +1,667 @@ +/* + * FTDI FT232BM Device emulation + * + * Copyright (c) 2006 CodeSourcery. + * Copyright (c) 2008 Samuel Thibault + * Written by Paul Brook, reused for FTDI by Samuel Thibault + * + * This code is licensed under the LGPL. + */ + +#include +#include +#include +#include +#include + +//#include "qemu-common.h" +//#include "qemu/error-report.h" +#include "hw/usb.h" +#include "usb/gpl/desc.h" +#include "usb/gpl/char.h" + +int strstart(const char *str, const char *val, const char **ptr); +int strstart(const char *str, const char *val, const char **ptr) +{ + const char *p, *q; + p = str; + q = val; + while (*q != '\0') { + if (*p != *q) + return 0; + p++; + q++; + } + if (ptr) + *ptr = p; + return 1; +} + + +//#define DEBUG_Serial + +#ifdef DEBUG_Serial +#define DPRINTF(fmt, ...) \ +do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) do {} while(0) +#endif + +#define RECV_BUF 384 + +/* Commands */ +#define FTDI_RESET 0 +#define FTDI_SET_MDM_CTRL 1 +#define FTDI_SET_FLOW_CTRL 2 +#define FTDI_SET_BAUD 3 +#define FTDI_SET_DATA 4 +#define FTDI_GET_MDM_ST 5 +#define FTDI_SET_EVENT_CHR 6 +#define FTDI_SET_ERROR_CHR 7 +#define FTDI_SET_LATENCY 9 +#define FTDI_GET_LATENCY 10 + +#define DeviceOutVendor ((USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8) +#define DeviceInVendor ((USB_DIR_IN |USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8) + +/* RESET */ + +#define FTDI_RESET_SIO 0 +#define FTDI_RESET_RX 1 +#define FTDI_RESET_TX 2 + +/* SET_MDM_CTRL */ + +#define FTDI_DTR 1 +#define FTDI_SET_DTR (FTDI_DTR << 8) +#define FTDI_RTS 2 +#define FTDI_SET_RTS (FTDI_RTS << 8) + +/* SET_FLOW_CTRL */ + +#define FTDI_RTS_CTS_HS 1 +#define FTDI_DTR_DSR_HS 2 +#define FTDI_XON_XOFF_HS 4 + +/* SET_DATA */ + +#define FTDI_PARITY (0x7 << 8) +#define FTDI_ODD (0x1 << 8) +#define FTDI_EVEN (0x2 << 8) +#define FTDI_MARK (0x3 << 8) +#define FTDI_SPACE (0x4 << 8) + +#define FTDI_STOP (0x3 << 11) +#define FTDI_STOP1 (0x0 << 11) +#define FTDI_STOP15 (0x1 << 11) +#define FTDI_STOP2 (0x2 << 11) + +/* GET_MDM_ST */ +/* TODO: should be sent every 40ms */ +#define FTDI_CTS (1<<4) // CTS line status +#define FTDI_DSR (1<<5) // DSR line status +#define FTDI_RI (1<<6) // RI line status +#define FTDI_RLSD (1<<7) // Receive Line Signal Detect + +/* Status */ + +#define FTDI_DR (1<<0) // Data Ready +#define FTDI_OE (1<<1) // Overrun Err +#define FTDI_PE (1<<2) // Parity Err +#define FTDI_FE (1<<3) // Framing Err +#define FTDI_BI (1<<4) // Break Interrupt +#define FTDI_THRE (1<<5) // Transmitter Holding Register +#define FTDI_TEMT (1<<6) // Transmitter Empty +#define FTDI_FIFO (1<<7) // Error in FIFO + +typedef struct { + USBDevice dev; + uint8_t recv_buf[RECV_BUF]; + uint16_t recv_ptr; + uint16_t recv_used; + uint8_t event_chr; + uint8_t error_chr; + uint8_t event_trigger; + QEMUSerialSetParams params; + int latency; /* ms */ +// CharDriverState *cs; +} USBSerialState; + +enum { + STR_MANUFACTURER = 1, + STR_PRODUCT_SERIAL, + STR_PRODUCT_BRAILLE, + STR_SERIALNUMBER, +}; + +static const USBDescStrings desc_strings = { + [STR_MANUFACTURER] = "QEMU", + [STR_PRODUCT_SERIAL] = "QEMU USB SERIAL", + [STR_PRODUCT_BRAILLE] = "QEMU USB BAUM BRAILLE", + [STR_SERIALNUMBER] = "1", +}; + +static const USBDescIface desc_iface0 = { + .bInterfaceNumber = 0, + .bNumEndpoints = 2, + .bInterfaceClass = 0xff, + .bInterfaceSubClass = 0xff, + .bInterfaceProtocol = 0xff, + .eps = (USBDescEndpoint[]) { + { + .bEndpointAddress = USB_DIR_IN | 0x01, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = 64, + },{ + .bEndpointAddress = USB_DIR_OUT | 0x02, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = 64, + }, + } +}; + +static const USBDescDevice desc_device = { + .bcdUSB = 0x0200, + .bMaxPacketSize0 = 8, + .bNumConfigurations = 1, + .confs = (USBDescConfig[]) { + { + .bNumInterfaces = 1, + .bConfigurationValue = 1, + .bmAttributes = 0x80, + .bMaxPower = 50, + .nif = 1, + .ifs = &desc_iface0, + }, + }, +}; + +static const USBDesc desc_serial = { + .id = { + .idVendor = 0x0403, + .idProduct = 0x6001, + .bcdDevice = 0x0400, + .iManufacturer = STR_MANUFACTURER, + .iProduct = STR_PRODUCT_SERIAL, + .iSerialNumber = STR_SERIALNUMBER, + }, + .full = &desc_device, + .str = desc_strings, +}; + +static const USBDesc desc_braille = { + .id = { + .idVendor = 0x0403, + .idProduct = 0xfe72, + .bcdDevice = 0x0400, + .iManufacturer = STR_MANUFACTURER, + .iProduct = STR_PRODUCT_BRAILLE, + .iSerialNumber = STR_SERIALNUMBER, + }, + .full = &desc_device, + .str = desc_strings, +}; + +static void usb_serial_reset(USBSerialState *s) +{ + /* TODO: Set flow control to none */ + s->event_chr = 0x0d; + s->event_trigger = 0; + s->recv_ptr = 0; + s->recv_used = 0; + /* TODO: purge in char driver */ +} + +static void usb_serial_handle_reset(USBDevice *dev) +{ + USBSerialState *s = (USBSerialState *)dev; + + DPRINTF("Reset\n"); + + usb_serial_reset(s); + /* TODO: Reset char device, send BREAK? */ +} + +static uint8_t usb_get_modem_lines(USBSerialState *s) +{ + int flags; + uint8_t ret; + +// if (qemu_chr_fe_ioctl(s->cs, CHR_IOCTL_SERIAL_GET_TIOCM, &flags) == -ENOTSUP) +// return FTDI_CTS|FTDI_DSR|FTDI_RLSD; + + ret = 0; + if (flags & CHR_TIOCM_CTS) + ret |= FTDI_CTS; + if (flags & CHR_TIOCM_DSR) + ret |= FTDI_DSR; + if (flags & CHR_TIOCM_RI) + ret |= FTDI_RI; + if (flags & CHR_TIOCM_CAR) + ret |= FTDI_RLSD; + + return ret; +} + +static void usb_serial_handle_control(USBDevice *dev, USBPacket *p, + int request, int value, int index, int length, uint8_t *data) +{ + USBSerialState *s = (USBSerialState *)dev; + int ret; + + DPRINTF("got control %x, value %x\n",request, value); + ret = usb_desc_handle_control(dev, p, request, value, index, length, data); + if (ret >= 0) { + return; + } + + switch (request) { + case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: + break; + + /* Class specific requests. */ + case DeviceOutVendor | FTDI_RESET: + switch (value) { + case FTDI_RESET_SIO: + usb_serial_reset(s); + break; + case FTDI_RESET_RX: + s->recv_ptr = 0; + s->recv_used = 0; + /* TODO: purge from char device */ + break; + case FTDI_RESET_TX: + /* TODO: purge from char device */ + break; + } + break; + case DeviceOutVendor | FTDI_SET_MDM_CTRL: + { + static int flags; +// qemu_chr_fe_ioctl(s->cs,CHR_IOCTL_SERIAL_GET_TIOCM, &flags); + if (value & FTDI_SET_RTS) { + if (value & FTDI_RTS) + flags |= CHR_TIOCM_RTS; + else + flags &= ~CHR_TIOCM_RTS; + } + if (value & FTDI_SET_DTR) { + if (value & FTDI_DTR) + flags |= CHR_TIOCM_DTR; + else + flags &= ~CHR_TIOCM_DTR; + } +// qemu_chr_fe_ioctl(s->cs,CHR_IOCTL_SERIAL_SET_TIOCM, &flags); + break; + } + case DeviceOutVendor | FTDI_SET_FLOW_CTRL: + /* TODO: ioctl */ + break; + case DeviceOutVendor | FTDI_SET_BAUD: { + static const int subdivisors8[8] = { 0, 4, 2, 1, 3, 5, 6, 7 }; + int subdivisor8 = subdivisors8[((value & 0xc000) >> 14) + | ((index & 1) << 2)]; + int divisor = value & 0x3fff; + + /* chip special cases */ + if (divisor == 1 && subdivisor8 == 0) + subdivisor8 = 4; + if (divisor == 0 && subdivisor8 == 0) + divisor = 1; + + s->params.speed = (48000000 / 2) / (8 * divisor + subdivisor8); +// qemu_chr_fe_ioctl(s->cs, CHR_IOCTL_SERIAL_SET_PARAMS, &s->params); + break; + } + case DeviceOutVendor | FTDI_SET_DATA: + switch (value & FTDI_PARITY) { + case 0: + s->params.parity = 'N'; + break; + case FTDI_ODD: + s->params.parity = 'O'; + break; + case FTDI_EVEN: + s->params.parity = 'E'; + break; + default: + DPRINTF("unsupported parity %d\n", value & FTDI_PARITY); + goto fail; + } + switch (value & FTDI_STOP) { + case FTDI_STOP1: + s->params.stop_bits = 1; + break; + case FTDI_STOP2: + s->params.stop_bits = 2; + break; + default: + DPRINTF("unsupported stop bits %d\n", value & FTDI_STOP); + goto fail; + } +// qemu_chr_fe_ioctl(s->cs, CHR_IOCTL_SERIAL_SET_PARAMS, &s->params); + /* TODO: TX ON/OFF */ + break; + case DeviceInVendor | FTDI_GET_MDM_ST: + data[0] = usb_get_modem_lines(s) | 1; + data[1] = 0; + p->actual_length = 2; + break; + case DeviceOutVendor | FTDI_SET_EVENT_CHR: + /* TODO: handle it */ + s->event_chr = value; + break; + case DeviceOutVendor | FTDI_SET_ERROR_CHR: + /* TODO: handle it */ + s->error_chr = value; + break; + case DeviceOutVendor | FTDI_SET_LATENCY: + s->latency = value; + break; + case DeviceInVendor | FTDI_GET_LATENCY: + data[0] = s->latency; + p->actual_length = 1; + break; + default: + fail: + DPRINTF("got unsupported/bogus control %x, value %x\n", request, value); + p->status = USB_RET_STALL; + break; + } +} + +static void usb_serial_handle_data(USBDevice *dev, USBPacket *p) +{ + USBSerialState *s = (USBSerialState *)dev; + uint8_t devep = p->ep->nr; + struct iovec *iov; + uint8_t header[2]; + int i, first_len, len; + + switch (p->pid) { + case USB_TOKEN_OUT: + if (devep != 2) + goto fail; + for (i = 0; i < p->iov.niov; i++) { + iov = p->iov.iov + i; +// qemu_chr_fe_write(s->cs, iov->iov_base, iov->iov_len); + } + p->actual_length = p->iov.size; + break; + + case USB_TOKEN_IN: + if (devep != 1) + goto fail; + first_len = RECV_BUF - s->recv_ptr; + len = p->iov.size; + if (len <= 2) { + p->status = USB_RET_NAK; + break; + } + header[0] = usb_get_modem_lines(s) | 1; + /* We do not have the uart details */ + /* handle serial break */ + if (s->event_trigger && s->event_trigger & FTDI_BI) { + s->event_trigger &= ~FTDI_BI; + header[1] = FTDI_BI; + usb_packet_copy(p, header, 2); + break; + } else { + header[1] = 0; + } + len -= 2; + if (len > s->recv_used) + len = s->recv_used; + if (!len) { + p->status = USB_RET_NAK; + break; + } + if (first_len > len) + first_len = len; + usb_packet_copy(p, header, 2); + usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len); + if (len > first_len) + usb_packet_copy(p, s->recv_buf, len - first_len); + s->recv_used -= len; + s->recv_ptr = (s->recv_ptr + len) % RECV_BUF; + break; + + default: + DPRINTF("Bad token\n"); + fail: + p->status = USB_RET_STALL; + break; + } +} + +static int usb_serial_can_read(void *opaque) +{ + USBSerialState *s = opaque; + + if (!s->dev.attached) { + return 0; + } + return RECV_BUF - s->recv_used; +} + +static void usb_serial_read(void *opaque, const uint8_t *buf, int size) +{ + USBSerialState *s = opaque; + int first_size, start; + + /* room in the buffer? */ + if (size > (RECV_BUF - s->recv_used)) + size = RECV_BUF - s->recv_used; + + start = s->recv_ptr + s->recv_used; + if (start < RECV_BUF) { + /* copy data to end of buffer */ + first_size = RECV_BUF - start; + if (first_size > size) + first_size = size; + + memcpy(s->recv_buf + start, buf, first_size); + + /* wrap around to front if needed */ + if (size > first_size) + memcpy(s->recv_buf, buf + first_size, size - first_size); + } else { + start -= RECV_BUF; + memcpy(s->recv_buf + start, buf, size); + } + s->recv_used += size; +} + +static void usb_serial_event(void *opaque, int event) +{ + USBSerialState *s = opaque; + + switch (event) { + case CHR_EVENT_BREAK: + s->event_trigger |= FTDI_BI; + break; + case CHR_EVENT_FOCUS: + break; + case CHR_EVENT_OPENED: + if (!s->dev.attached) { + usb_device_attach(&s->dev); + } + break; + case CHR_EVENT_CLOSED: + if (s->dev.attached) { + usb_device_detach(&s->dev); + } + break; + } +} + +#if 0 +static int usb_serial_initfn(USBDevice *dev) +{ + USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); + + usb_desc_create_serial(dev); + usb_desc_init(dev); + dev->auto_attach = 0; + + if (!s->cs) { + error_report("Property chardev is required"); + return -1; + } + + qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read, + usb_serial_event, s); + usb_serial_handle_reset(dev); + + if (s->cs->be_open && !dev->attached) { + usb_device_attach(dev); + } + return 0; +} +#endif + +static USBDevice *usb_serial_init(USBBus *bus, const char *filename) +{ + USBDevice *dev; +// CharDriverState *cdrv; + uint32_t vendorid = 0, productid = 0; + char label[32]; + static int index; + + while (*filename && *filename != ':') { + const char *p; + char *e; + if (strstart(filename, "vendorid=", &p)) { + vendorid = strtol(p, &e, 16); + if (e == p || (*e && *e != ',' && *e != ':')) { +// error_report("bogus vendor ID %s", p); + return NULL; + } + filename = e; + } else if (strstart(filename, "productid=", &p)) { + productid = strtol(p, &e, 16); + if (e == p || (*e && *e != ',' && *e != ':')) { +// error_report("bogus product ID %s", p); + return NULL; + } + filename = e; + } else { +// error_report("unrecognized serial USB option %s", filename); + return NULL; + } + while(*filename == ',') + filename++; + } + if (!*filename) { +// error_report("character device specification needed"); + return NULL; + } + filename++; + + snprintf(label, sizeof(label), "usbserial%d", index++); +// cdrv = qemu_chr_new(label, filename, NULL); +// if (!cdrv) +// return NULL; + + dev = usb_create(bus, "usb-serial"); + if (!dev) { + return NULL; + } +// qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); +// if (vendorid) +// qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid); +// if (productid) +// qdev_prop_set_uint16(&dev->qdev, "productid", productid); +// qdev_init_nofail(&dev->qdev); + + return dev; +} + +static USBDevice *usb_braille_init(USBBus *bus, const char *unused) +{ + USBDevice *dev; +// CharDriverState *cdrv; + +// cdrv = qemu_chr_new("braille", "braille", NULL); +// if (!cdrv) +// return NULL; + + dev = usb_create(bus, "usb-braille"); +// qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); +// qdev_init_nofail(&dev->qdev); + + return dev; +} + +#if 0 +static const VMStateDescription vmstate_usb_serial = { + .name = "usb-serial", + .unmigratable = 1, +}; + +static Property serial_properties[] = { + DEFINE_PROP_CHR("chardev", USBSerialState, cs), + DEFINE_PROP_END_OF_LIST(), +}; + +static void usb_serial_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + USBDeviceClass *uc = USB_DEVICE_CLASS(klass); + + uc->init = usb_serial_initfn; + uc->product_desc = "QEMU USB Serial"; + uc->usb_desc = &desc_serial; + uc->handle_reset = usb_serial_handle_reset; + uc->handle_control = usb_serial_handle_control; + uc->handle_data = usb_serial_handle_data; + dc->vmsd = &vmstate_usb_serial; + dc->props = serial_properties; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); +} + +static const TypeInfo serial_info = { + .name = "usb-serial", + .parent = TYPE_USB_DEVICE, + .instance_size = sizeof(USBSerialState), + .class_init = usb_serial_class_initfn, +}; + +static Property braille_properties[] = { + DEFINE_PROP_CHR("chardev", USBSerialState, cs), + DEFINE_PROP_END_OF_LIST(), +}; + +static void usb_braille_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + USBDeviceClass *uc = USB_DEVICE_CLASS(klass); + + uc->init = usb_serial_initfn; + uc->product_desc = "QEMU USB Braille"; + uc->usb_desc = &desc_braille; + uc->handle_reset = usb_serial_handle_reset; + uc->handle_control = usb_serial_handle_control; + uc->handle_data = usb_serial_handle_data; + dc->vmsd = &vmstate_usb_serial; + dc->props = braille_properties; + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); +} + +static const TypeInfo braille_info = { + .name = "usb-braille", + .parent = TYPE_USB_DEVICE, + .instance_size = sizeof(USBSerialState), + .class_init = usb_braille_class_initfn, +}; + +static void usb_serial_register_types(void) +{ + type_register_static(&serial_info); + usb_legacy_register("usb-serial", "serial", usb_serial_init); + type_register_static(&braille_info); + usb_legacy_register("usb-braille", "braille", usb_braille_init); +} + +type_init(usb_serial_register_types) +#endif From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 10:22:54 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DE6D2985 for ; Wed, 14 Aug 2013 10:22:54 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BD73F2E48 for ; Wed, 14 Aug 2013 10:22:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EAMsWf059930 for ; Wed, 14 Aug 2013 10:22:54 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EAMsGT059914 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 10:22:54 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 14 Aug 2013 10:22:54 GMT Message-Id: <201308141022.r7EAMsGT059914@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255922 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb usb/gpl usb/include/hw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 10:22:54 -0000 Author: syuu Date: Wed Aug 14 10:22:54 2013 New Revision: 255922 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255922 Log: import GPL tainted bus.c Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Aug 14 08:10:54 2013 (r255921) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Aug 14 10:22:54 2013 (r255922) @@ -19,7 +19,7 @@ CFLAGS+=-I${.CURDIR}/usb/include -I${.CURDIR} SRCS+= core.c hcd-uhci.c host-libusb.c dev-hub.c .PATH: ${.CURDIR}/usb/gpl -SRCS+= desc.c dev-serial.c +SRCS+= desc.c dev-serial.c bus.c NO_MAN= Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Wed Aug 14 10:22:54 2013 (r255922) @@ -0,0 +1,690 @@ +#include +//#include "hw/hw.h" +#include "hw/usb.h" +//#include "hw/qdev.h" +//#include "sysemu/sysemu.h" +//#include "monitor/monitor.h" +//#include "trace.h" + +#if 0 +static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); + +static char *usb_get_dev_path(DeviceState *dev); +static char *usb_get_fw_dev_path(DeviceState *qdev); +static int usb_qdev_exit(DeviceState *qdev); + +static Property usb_props[] = { + DEFINE_PROP_STRING("port", USBDevice, port_path), + DEFINE_PROP_STRING("serial", USBDevice, serial), + DEFINE_PROP_BIT("full-path", USBDevice, flags, + USB_DEV_FLAG_FULL_PATH, true), + DEFINE_PROP_END_OF_LIST() +}; + +static void usb_bus_class_init(ObjectClass *klass, void *data) +{ + BusClass *k = BUS_CLASS(klass); + + k->print_dev = usb_bus_dev_print; + k->get_dev_path = usb_get_dev_path; + k->get_fw_dev_path = usb_get_fw_dev_path; +} + +static const TypeInfo usb_bus_info = { + .name = TYPE_USB_BUS, + .parent = TYPE_BUS, + .instance_size = sizeof(USBBus), + .class_init = usb_bus_class_init, +}; +#endif + +static int next_usb_bus = 0; +static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); + +#if 0 +static int usb_device_post_load(void *opaque, int version_id) +{ + USBDevice *dev = opaque; + + if (dev->state == USB_STATE_NOTATTACHED) { + dev->attached = 0; + } else { + dev->attached = 1; + } + return 0; +} + +const VMStateDescription vmstate_usb_device = { + .name = "USBDevice", + .version_id = 1, + .minimum_version_id = 1, + .post_load = usb_device_post_load, + .fields = (VMStateField []) { + VMSTATE_UINT8(addr, USBDevice), + VMSTATE_INT32(state, USBDevice), + VMSTATE_INT32(remote_wakeup, USBDevice), + VMSTATE_INT32(setup_state, USBDevice), + VMSTATE_INT32(setup_len, USBDevice), + VMSTATE_INT32(setup_index, USBDevice), + VMSTATE_UINT8_ARRAY(setup_buf, USBDevice, 8), + VMSTATE_END_OF_LIST(), + } +}; +#endif + +void usb_bus_new(USBBus *bus, USBBusOps *ops /*, DeviceState *host*/) +{ +// qbus_create_inplace(&bus->qbus, TYPE_USB_BUS, host, NULL); + bus->ops = ops; + bus->busnr = next_usb_bus++; +// bus->qbus.allow_hotplug = 1; /* Yes, we can */ + QTAILQ_INIT(&bus->free); + QTAILQ_INIT(&bus->used); + QTAILQ_INSERT_TAIL(&busses, bus, next); +} + +#if 0 +USBBus *usb_bus_find(int busnr) +{ + USBBus *bus; + + if (-1 == busnr) + return QTAILQ_FIRST(&busses); + QTAILQ_FOREACH(bus, &busses, next) { + if (bus->busnr == busnr) + return bus; + } + return NULL; +} + +static int usb_device_init(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->init) { + return klass->init(dev); + } + return 0; +} + +USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->find_device) { + return klass->find_device(dev, addr); + } + return NULL; +} + +static void usb_device_handle_destroy(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->handle_destroy) { + klass->handle_destroy(dev); + } +} + +void usb_device_cancel_packet(USBDevice *dev, USBPacket *p) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->cancel_packet) { + klass->cancel_packet(dev, p); + } +} + +void usb_device_handle_attach(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->handle_attach) { + klass->handle_attach(dev); + } +} + +void usb_device_handle_reset(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->handle_reset) { + klass->handle_reset(dev); + } +} + +void usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, + int value, int index, int length, uint8_t *data) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->handle_control) { + klass->handle_control(dev, p, request, value, index, length, data); + } +} + +void usb_device_handle_data(USBDevice *dev, USBPacket *p) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->handle_data) { + klass->handle_data(dev, p); + } +} + +const char *usb_device_get_product_desc(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + return klass->product_desc; +} + +const USBDesc *usb_device_get_usb_desc(USBDevice *dev) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (dev->usb_desc) { + return dev->usb_desc; + } + return klass->usb_desc; +} + +void usb_device_set_interface(USBDevice *dev, int interface, + int alt_old, int alt_new) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->set_interface) { + klass->set_interface(dev, interface, alt_old, alt_new); + } +} +#endif + +void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->flush_ep_queue) { + klass->flush_ep_queue(dev, ep); + } +} + +void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep) +{ + USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); + if (klass->ep_stopped) { + klass->ep_stopped(dev, ep); + } +} + +#if 0 +static int usb_qdev_init(DeviceState *qdev) +{ + USBDevice *dev = USB_DEVICE(qdev); + int rc; + + pstrcpy(dev->product_desc, sizeof(dev->product_desc), + usb_device_get_product_desc(dev)); + dev->auto_attach = 1; + QLIST_INIT(&dev->strings); + usb_ep_init(dev); + rc = usb_claim_port(dev); + if (rc != 0) { + return rc; + } + rc = usb_device_init(dev); + if (rc != 0) { + usb_release_port(dev); + return rc; + } + if (dev->auto_attach) { + rc = usb_device_attach(dev); + if (rc != 0) { + usb_qdev_exit(qdev); + return rc; + } + } + return 0; +} + +static int usb_qdev_exit(DeviceState *qdev) +{ + USBDevice *dev = USB_DEVICE(qdev); + + if (dev->attached) { + usb_device_detach(dev); + } + usb_device_handle_destroy(dev); + if (dev->port) { + usb_release_port(dev); + } + return 0; +} + +typedef struct LegacyUSBFactory +{ + const char *name; + const char *usbdevice_name; + USBDevice *(*usbdevice_init)(USBBus *bus, const char *params); +} LegacyUSBFactory; + +static GSList *legacy_usb_factory; + +void usb_legacy_register(const char *typename, const char *usbdevice_name, + USBDevice *(*usbdevice_init)(USBBus *bus, + const char *params)) +{ + if (usbdevice_name) { + LegacyUSBFactory *f = g_malloc0(sizeof(*f)); + f->name = typename; + f->usbdevice_name = usbdevice_name; + f->usbdevice_init = usbdevice_init; + legacy_usb_factory = g_slist_append(legacy_usb_factory, f); + } +} + +USBDevice *usb_create(USBBus *bus, const char *name) +{ + DeviceState *dev; + + dev = qdev_create(&bus->qbus, name); + return USB_DEVICE(dev); +} + +USBDevice *usb_create_simple(USBBus *bus, const char *name) +{ + USBDevice *dev = usb_create(bus, name); + int rc; + + if (!dev) { + error_report("Failed to create USB device '%s'", name); + return NULL; + } + rc = qdev_init(&dev->qdev); + if (rc < 0) { + error_report("Failed to initialize USB device '%s'", name); + return NULL; + } + return dev; +} +#endif + +static void usb_fill_port(USBPort *port, void *opaque, int index, + USBPortOps *ops, int speedmask) +{ + port->opaque = opaque; + port->index = index; + port->ops = ops; + port->speedmask = speedmask; + usb_port_location(port, NULL, index + 1); +} + +void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, + USBPortOps *ops, int speedmask) +{ + usb_fill_port(port, opaque, index, ops, speedmask); + QTAILQ_INSERT_TAIL(&bus->free, port, next); + bus->nfree++; +} + +int usb_register_companion(const char *masterbus, USBPort *ports[], + uint32_t portcount, uint32_t firstport, + void *opaque, USBPortOps *ops, int speedmask) +{ + USBBus *bus; + int i; + +#if 0 + QTAILQ_FOREACH(bus, &busses, next) { + if (strcmp(bus->qbus.name, masterbus) == 0) { + break; + } + } +#endif + + if (!bus || !bus->ops->register_companion) { +// qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus", +// "an USB masterbus"); + if (bus) { +// error_printf_unless_qmp( +// "USB bus '%s' does not allow companion controllers\n", +// masterbus); + } + return -1; + } + + for (i = 0; i < portcount; i++) { + usb_fill_port(ports[i], opaque, i, ops, speedmask); + } + + return bus->ops->register_companion(bus, ports, portcount, firstport); +} + +void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr) +{ + if (upstream) { + snprintf(downstream->path, sizeof(downstream->path), "%s.%d", + upstream->path, portnr); + downstream->hubcount = upstream->hubcount + 1; + } else { + snprintf(downstream->path, sizeof(downstream->path), "%d", portnr); + downstream->hubcount = 0; + } +} + +#if 0 +void usb_unregister_port(USBBus *bus, USBPort *port) +{ + if (port->dev) + qdev_free(&port->dev->qdev); + QTAILQ_REMOVE(&bus->free, port, next); + bus->nfree--; +} + +int usb_claim_port(USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + USBPort *port; + + assert(dev->port == NULL); + + if (dev->port_path) { + QTAILQ_FOREACH(port, &bus->free, next) { + if (strcmp(port->path, dev->port_path) == 0) { + break; + } + } + if (port == NULL) { + error_report("Error: usb port %s (bus %s) not found (in use?)", + dev->port_path, bus->qbus.name); + return -1; + } + } else { + if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) { + /* Create a new hub and chain it on */ + usb_create_simple(bus, "usb-hub"); + } + if (bus->nfree == 0) { + error_report("Error: tried to attach usb device %s to a bus " + "with no free ports", dev->product_desc); + return -1; + } + port = QTAILQ_FIRST(&bus->free); + } + trace_usb_port_claim(bus->busnr, port->path); + + QTAILQ_REMOVE(&bus->free, port, next); + bus->nfree--; + + dev->port = port; + port->dev = dev; + + QTAILQ_INSERT_TAIL(&bus->used, port, next); + bus->nused++; + return 0; +} + +void usb_release_port(USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + USBPort *port = dev->port; + + assert(port != NULL); + trace_usb_port_release(bus->busnr, port->path); + + QTAILQ_REMOVE(&bus->used, port, next); + bus->nused--; + + dev->port = NULL; + port->dev = NULL; + + QTAILQ_INSERT_TAIL(&bus->free, port, next); + bus->nfree++; +} + +static void usb_mask_to_str(char *dest, size_t size, + unsigned int speedmask) +{ + static const struct { + unsigned int mask; + const char *name; + } speeds[] = { + { .mask = USB_SPEED_MASK_FULL, .name = "full" }, + { .mask = USB_SPEED_MASK_HIGH, .name = "high" }, + { .mask = USB_SPEED_MASK_SUPER, .name = "super" }, + }; + int i, pos = 0; + + for (i = 0; i < ARRAY_SIZE(speeds); i++) { + if (speeds[i].mask & speedmask) { + pos += snprintf(dest + pos, size - pos, "%s%s", + pos ? "+" : "", + speeds[i].name); + } + } +} + +int usb_device_attach(USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + USBPort *port = dev->port; + char devspeed[32], portspeed[32]; + + assert(port != NULL); + assert(!dev->attached); + usb_mask_to_str(devspeed, sizeof(devspeed), dev->speedmask); + usb_mask_to_str(portspeed, sizeof(portspeed), port->speedmask); + trace_usb_port_attach(bus->busnr, port->path, + devspeed, portspeed); + + if (!(port->speedmask & dev->speedmask)) { + error_report("Warning: speed mismatch trying to attach" + " usb device \"%s\" (%s speed)" + " to bus \"%s\", port \"%s\" (%s speed)", + dev->product_desc, devspeed, + bus->qbus.name, port->path, portspeed); + return -1; + } + + dev->attached++; + usb_attach(port); + + return 0; +} + +int usb_device_detach(USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + USBPort *port = dev->port; + + assert(port != NULL); + assert(dev->attached); + trace_usb_port_detach(bus->busnr, port->path); + + usb_detach(port); + dev->attached--; + return 0; +} + +int usb_device_delete_addr(int busnr, int addr) +{ + USBBus *bus; + USBPort *port; + USBDevice *dev; + + bus = usb_bus_find(busnr); + if (!bus) + return -1; + + QTAILQ_FOREACH(port, &bus->used, next) { + if (port->dev->addr == addr) + break; + } + if (!port) + return -1; + dev = port->dev; + + qdev_free(&dev->qdev); + return 0; +} + +static const char *usb_speed(unsigned int speed) +{ + static const char *txt[] = { + [ USB_SPEED_LOW ] = "1.5", + [ USB_SPEED_FULL ] = "12", + [ USB_SPEED_HIGH ] = "480", + [ USB_SPEED_SUPER ] = "5000", + }; + if (speed >= ARRAY_SIZE(txt)) + return "?"; + return txt[speed]; +} + +static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) +{ + USBDevice *dev = USB_DEVICE(qdev); + USBBus *bus = usb_bus_from_device(dev); + + monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n", + indent, "", bus->busnr, dev->addr, + dev->port ? dev->port->path : "-", + usb_speed(dev->speed), dev->product_desc, + dev->attached ? ", attached" : ""); +} + +static char *usb_get_dev_path(DeviceState *qdev) +{ + USBDevice *dev = USB_DEVICE(qdev); + DeviceState *hcd = qdev->parent_bus->parent; + char *id = NULL; + + if (dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) { + id = qdev_get_dev_path(hcd); + } + if (id) { + char *ret = g_strdup_printf("%s/%s", id, dev->port->path); + g_free(id); + return ret; + } else { + return g_strdup(dev->port->path); + } +} + +static char *usb_get_fw_dev_path(DeviceState *qdev) +{ + USBDevice *dev = USB_DEVICE(qdev); + char *fw_path, *in; + ssize_t pos = 0, fw_len; + long nr; + + fw_len = 32 + strlen(dev->port->path) * 6; + fw_path = g_malloc(fw_len); + in = dev->port->path; + while (fw_len - pos > 0) { + nr = strtol(in, &in, 10); + if (in[0] == '.') { + /* some hub between root port and device */ + pos += snprintf(fw_path + pos, fw_len - pos, "hub@%ld/", nr); + in++; + } else { + /* the device itself */ + pos += snprintf(fw_path + pos, fw_len - pos, "%s@%ld", + qdev_fw_name(qdev), nr); + break; + } + } + return fw_path; +} + +void usb_info(Monitor *mon, const QDict *qdict) +{ + USBBus *bus; + USBDevice *dev; + USBPort *port; + + if (QTAILQ_EMPTY(&busses)) { + monitor_printf(mon, "USB support not enabled\n"); + return; + } + + QTAILQ_FOREACH(bus, &busses, next) { + QTAILQ_FOREACH(port, &bus->used, next) { + dev = port->dev; + if (!dev) + continue; + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n", + bus->busnr, dev->addr, port->path, usb_speed(dev->speed), + dev->product_desc); + } + } +} + +/* handle legacy -usbdevice cmd line option */ +USBDevice *usbdevice_create(const char *cmdline) +{ + USBBus *bus = usb_bus_find(-1 /* any */); + LegacyUSBFactory *f = NULL; + GSList *i; + char driver[32]; + const char *params; + int len; + + params = strchr(cmdline,':'); + if (params) { + params++; + len = params - cmdline; + if (len > sizeof(driver)) + len = sizeof(driver); + pstrcpy(driver, len, cmdline); + } else { + params = ""; + pstrcpy(driver, sizeof(driver), cmdline); + } + + for (i = legacy_usb_factory; i; i = i->next) { + f = i->data; + if (strcmp(f->usbdevice_name, driver) == 0) { + break; + } + } + if (i == NULL) { +#if 0 + /* no error because some drivers are not converted (yet) */ + error_report("usbdevice %s not found", driver); +#endif + return NULL; + } + + if (!bus) { + error_report("Error: no usb bus to attach usbdevice %s, " + "please try -machine usb=on and check that " + "the machine model supports USB", driver); + return NULL; + } + + if (!f->usbdevice_init) { + if (*params) { + error_report("usbdevice %s accepts no params", driver); + return NULL; + } + return usb_create_simple(bus, f->name); + } + return f->usbdevice_init(bus, params); +} + +static void usb_device_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *k = DEVICE_CLASS(klass); + k->bus_type = TYPE_USB_BUS; + k->init = usb_qdev_init; + k->unplug = qdev_simple_unplug_cb; + k->exit = usb_qdev_exit; + k->props = usb_props; +} + +static const TypeInfo usb_device_type_info = { + .name = TYPE_USB_DEVICE, + .parent = TYPE_DEVICE, + .instance_size = sizeof(USBDevice), + .abstract = true, + .class_size = sizeof(USBDeviceClass), + .class_init = usb_device_class_init, +}; + +static void usb_register_types(void) +{ + type_register_static(&usb_bus_info); + type_register_static(&usb_device_type_info); +} + +type_init(usb_register_types) +#endif Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Aug 14 08:10:54 2013 (r255921) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Aug 14 10:22:54 2013 (r255922) @@ -427,7 +427,7 @@ async = QTAILQ_FIRST(&queue->asyncs); uhci_async_cancel(async); } -// usb_device_ep_stopped(queue->ep->dev, queue->ep); + usb_device_ep_stopped(queue->ep->dev, queue->ep); trace_usb_uhci_queue_del(queue->token, reason); QTAILQ_REMOVE(&s->queues, queue, next); @@ -1245,7 +1245,7 @@ assert(int_mask == 0); plink = ptd.link; } -// usb_device_flush_ep_queue(q->ep->dev, q->ep); + usb_device_flush_ep_queue(q->ep->dev, q->ep); } static void uhci_process_frame(UHCIState *s) @@ -1450,6 +1450,7 @@ .impl.max_access_size = 2, .endianness = DEVICE_LITTLE_ENDIAN, }; +*/ static USBPortOps uhci_port_ops = { .attach = uhci_attach, @@ -1461,11 +1462,11 @@ static USBBusOps uhci_bus_ops = { }; -*/ +#if 0 static int usb_uhci_common_initfn(PCIDevice *dev) { -// PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); -// UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class); + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); + UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class); UHCIState *s = DO_UPCAST(UHCIState, dev, dev); uint8_t *pci_conf = s->dev.config; int i; @@ -1474,8 +1475,8 @@ /* TODO: reset value should be 0. */ pci_conf[USB_SBRN] = USB_RELEASE_1; // release number -// s->irq_pin = u->info.irq_pin; -// pci_config_set_interrupt_pin(pci_conf, s->irq_pin + 1); + s->irq_pin = u->info.irq_pin; + pci_config_set_interrupt_pin(pci_conf, s->irq_pin + 1); if (s->masterbus) { USBPort *ports[NB_PORTS]; @@ -1483,32 +1484,31 @@ ports[i] = &s->ports[i].port; } if (usb_register_companion(s->masterbus, ports, NB_PORTS, - s->firstport, s, /*&uhci_port_ops*/ NULL, + s->firstport, s, &uhci_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL) != 0) { return -1; } } else { -// usb_bus_new(&s->bus, &uhci_bus_ops, &s->dev.qdev); + usb_bus_new(&s->bus, &uhci_bus_ops/*, &s->dev.qdev*/); for (i = 0; i < NB_PORTS; i++) { - usb_register_port(&s->bus, &s->ports[i].port, s, i, /*&uhci_port_ops*/NULL, + usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); } } -// s->bh = qemu_bh_new(uhci_bh, s); -// s->frame_timer = qemu_new_timer_ns(vm_clock, uhci_frame_timer, s); + s->bh = qemu_bh_new(uhci_bh, s); + s->frame_timer = qemu_new_timer_ns(vm_clock, uhci_frame_timer, s); s->num_ports_vmstate = NB_PORTS; QTAILQ_INIT(&s->queues); + qemu_register_reset(uhci_reset, s); -// qemu_register_reset(uhci_reset, s); - -// memory_region_init_io(&s->io_bar, &uhci_ioport_ops, s, "uhci", 0x20); + memory_region_init_io(&s->io_bar, &uhci_ioport_ops, s, "uhci", 0x20); /* Use region 4 for consistency with real hardware. BSD guests seem to rely on this. */ -// pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar); + pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar); return 0; } -#if 0 + static int usb_uhci_vt82c686b_initfn(PCIDevice *dev) { UHCIState *s = DO_UPCAST(UHCIState, dev, dev); @@ -1523,18 +1523,14 @@ return usb_uhci_common_initfn(dev); } -#endif static void usb_uhci_exit(PCIDevice *dev) { -#if 0 UHCIState *s = DO_UPCAST(UHCIState, dev, dev); memory_region_destroy(&s->io_bar); -#endif } -#if 0 static Property uhci_properties[] = { DEFINE_PROP_STRING("masterbus", UHCIState, masterbus), DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0), @@ -1542,9 +1538,7 @@ DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128), DEFINE_PROP_END_OF_LIST(), }; -#endif -#if 0 static void uhci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -1563,9 +1557,7 @@ dc->props = uhci_properties; u->info = *info; } -#endif -#if 0 static UHCIInfo uhci_info[] = { { .name = "piix3-usb-uhci", @@ -1633,11 +1625,9 @@ .unplug = false, } }; -#endif static void uhci_register_types(void) { -#if 0 TypeInfo uhci_type_info = { .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(UHCIState), @@ -1651,10 +1641,10 @@ uhci_type_info.class_data = uhci_info + i; type_register(&uhci_type_info); } -#endif } -//type_init(uhci_register_types) +type_init(uhci_register_types) +#endif static void pci_uhci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, @@ -1713,6 +1703,27 @@ } memset(&sc->sc_st, 0, sizeof(sc->sc_st)); + + if (sc->sc_st.masterbus) { + int i; + USBPort *ports[NB_PORTS]; + for(i = 0; i < NB_PORTS; i++) { + ports[i] = &sc->sc_st.ports[i].port; + } + if (usb_register_companion(sc->sc_st.masterbus, ports, NB_PORTS, + sc->sc_st.firstport, &sc->sc_st, &uhci_port_ops, + USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL) != 0) { + return -1; + } + } else { + int i; + usb_bus_new(&sc->sc_st.bus, &uhci_bus_ops/*, &sc->sc_st.dev.qdev*/); + for (i = 0; i < NB_PORTS; i++) { + usb_register_port(&sc->sc_st.bus, &sc->sc_st.ports[i].port, &sc->sc_st, i, &uhci_port_ops, + USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); + } + } + sc->sc_st.frame_timer = new_timer(uhci_frame_timer, &sc->sc_st); sc->sc_st.num_ports_vmstate = NB_PORTS; QTAILQ_INIT(&sc->sc_st.queues); Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Wed Aug 14 08:10:54 2013 (r255921) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Wed Aug 14 10:22:54 2013 (r255922) @@ -205,53 +205,9 @@ QTAILQ_HEAD(, USBPacket) queue; }; -enum USBDeviceFlags { - USB_DEV_FLAG_FULL_PATH, - USB_DEV_FLAG_IS_HOST, -}; - -/* definition of a USB device */ -struct USBDevice { -// DeviceState qdev; - USBPort *port; - char *port_path; - char *serial; - void *opaque; - uint32_t flags; - - /* Actual connected speed */ - int speed; - /* Supported speeds, not in info because it may be variable (hostdevs) */ - int speedmask; - uint8_t addr; - char product_desc[32]; - int auto_attach; - int attached; - - int32_t state; - uint8_t setup_buf[8]; - uint8_t data_buf[4096]; - int32_t remote_wakeup; - int32_t setup_state; - int32_t setup_len; - int32_t setup_index; - - USBEndpoint ep_ctl; - USBEndpoint ep_in[USB_MAX_ENDPOINTS]; - USBEndpoint ep_out[USB_MAX_ENDPOINTS]; - - QLIST_HEAD(, USBDescString) strings; - const USBDesc *usb_desc; /* Overrides class usb_desc if not NULL */ - const USBDescDevice *device; - - int configuration; - int ninterfaces; - int altsetting[USB_MAX_INTERFACES]; - const USBDescConfig *config; - const USBDescIface *ifaces[USB_MAX_INTERFACES]; -}; - #define TYPE_USB_DEVICE "usb-device" +#define USB_DEVICE_GET_CLASS(dev) (&dev->klass) + #if 0 #define USB_DEVICE(obj) \ OBJECT_CHECK(USBDevice, (obj), TYPE_USB_DEVICE) @@ -330,6 +286,54 @@ const USBDesc *usb_desc; } USBDeviceClass; + +enum USBDeviceFlags { + USB_DEV_FLAG_FULL_PATH, + USB_DEV_FLAG_IS_HOST, +}; + +/* definition of a USB device */ +struct USBDevice { +// DeviceState qdev; + USBDeviceClass klass; + USBPort *port; + char *port_path; + char *serial; + void *opaque; + uint32_t flags; + + /* Actual connected speed */ + int speed; + /* Supported speeds, not in info because it may be variable (hostdevs) */ + int speedmask; + uint8_t addr; + char product_desc[32]; + int auto_attach; + int attached; + + int32_t state; + uint8_t setup_buf[8]; + uint8_t data_buf[4096]; + int32_t remote_wakeup; + int32_t setup_state; + int32_t setup_len; + int32_t setup_index; + + USBEndpoint ep_ctl; + USBEndpoint ep_in[USB_MAX_ENDPOINTS]; + USBEndpoint ep_out[USB_MAX_ENDPOINTS]; + + QLIST_HEAD(, USBDescString) strings; + const USBDesc *usb_desc; /* Overrides class usb_desc if not NULL */ + const USBDescDevice *device; + + int configuration; + int ninterfaces; + int altsetting[USB_MAX_INTERFACES]; + const USBDescConfig *config; + const USBDescIface *ifaces[USB_MAX_INTERFACES]; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 10:26:26 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EF491A60 for ; Wed, 14 Aug 2013 10:26:26 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C32932E6F for ; Wed, 14 Aug 2013 10:26:26 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EAQQRV098597 for ; Wed, 14 Aug 2013 10:26:26 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EAQQSm098594 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 10:26:26 GMT (envelope-from mattbw@FreeBSD.org) Date: Wed, 14 Aug 2013 10:26:26 GMT Message-Id: <201308141026.r7EAQQSm098594@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255923 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 10:26:27 -0000 Author: mattbw Date: Wed Aug 14 10:26:26 2013 New Revision: 255923 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255923 Log: Regurgitate last error string event at job failure. This is a very "last resort" approach to finding out why pkcon bails out in updates. Unfortunately, I accidentally upgraded properly using pkg and thus cannot test it until I set up a proper testing environment. Next up is GetDepends and GetRequires, which should theoretically be simple query extensions. Modified: soc2013/mattbw/backend/event.c soc2013/mattbw/backend/jobs.c Modified: soc2013/mattbw/backend/event.c ============================================================================== --- soc2013/mattbw/backend/event.c Wed Aug 14 10:22:54 2013 (r255922) +++ soc2013/mattbw/backend/event.c Wed Aug 14 10:26:26 2013 (r255923) @@ -99,8 +99,14 @@ case PKG_EVENT_ERROR: /* * This is sometimes used for nonfatal errors, so we can't - * throw an error code here. + * throw an error code here. What we'll do (mainly for debug + * purposes) is post the error into the backend so we can + * retrieve it if it was fatal. + * + * pk_backend_set_string seems to strdup, so we don't have to. */ + (void)pk_backend_set_string(backend, "job_error", + event->e_pkg_error.msg); break; case PKG_EVENT_ERRNO: case PKG_EVENT_ARCHIVE_COMP_UNSUP: Modified: soc2013/mattbw/backend/jobs.c ============================================================================== --- soc2013/mattbw/backend/jobs.c Wed Aug 14 10:22:54 2013 (r255922) +++ soc2013/mattbw/backend/jobs.c Wed Aug 14 10:26:26 2013 (r255923) @@ -70,7 +70,16 @@ assert(EPKG_OK <= err); assert(err <= EPKG_INSECURE); if (err != EPKG_OK) { - ERR(backend, job_failed, APPLY_ERRORS[err]); + const gchar *error_string; + + /* Did we trap an error in the events handler? */ + error_string = pk_backend_get_string(backend, "job_error"); + if (error_string == NULL) { + error_string = APPLY_ERRORS[err]; + } + assert(error_string != NULL); + + ERR(backend, job_failed, error_string); } return (err == EPKG_OK); From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 15:19:17 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2A39191A for ; Wed, 14 Aug 2013 15:19:17 +0000 (UTC) (envelope-from zcore@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 14DE521A5 for ; Wed, 14 Aug 2013 15:19:17 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EFJGrJ032323 for ; Wed, 14 Aug 2013 15:19:16 GMT (envelope-from zcore@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EFJG7D032318 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 15:19:16 GMT (envelope-from zcore@FreeBSD.org) Date: Wed, 14 Aug 2013 15:19:16 GMT Message-Id: <201308141519.r7EFJG7D032318@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zcore@FreeBSD.org using -f From: zcore@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255932 - soc2013/zcore/head/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 15:19:17 -0000 Author: zcore Date: Wed Aug 14 15:19:16 2013 New Revision: 255932 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255932 Log: map cmdlist/rfis when enabling CMD_ST/CMD_FRE Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c ============================================================================== --- soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Wed Aug 14 14:45:47 2013 (r255931) +++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Wed Aug 14 15:19:16 2013 (r255932) @@ -73,6 +73,7 @@ struct blockif_ctxt *bctx; struct pci_ahci_softc *pr_sc; uint64_t cmd_lst; + uint64_t rfis; uint32_t clb; uint32_t clbu; uint32_t fb; @@ -390,29 +391,37 @@ break; case AHCI_P_CMD: { - uint64_t clb; p->cmd = value; if (!(value & AHCI_P_CMD_ST)) { p->cmd &= ~(AHCI_P_CMD_CR | AHCI_P_CMD_CCS_MASK); p->ci = 0; p->sact = 0; - } else + } else { + uint64_t clb; + p->cmd |= AHCI_P_CMD_CR; + clb = (uint64_t)p->clbu << 32 | p->clb; + p->cmd_lst = paddr_guest2host(ahci_ctx(sc), clb, + AHCI_CL_SIZE * AHCI_MAX_SLOTS); + } + + if (value & AHCI_P_CMD_FRE) { + uint64_t fb; - if (value & AHCI_P_CMD_FRE) p->cmd |= AHCI_P_CMD_FR; - else + fb = (uint64_t)p->fbu << 32 | p->fb; + /* we don't support FBSCP, so rfis size is 256Bytes */ + p->rfis = paddr_guest2host(ahci_ctx(sc), fb, 256); + } else { p->cmd &= ~AHCI_P_CMD_FR; + } if (value & AHCI_P_CMD_CLO) { p->tfd = 0; p->cmd &= ~AHCI_P_CMD_CLO; } - clb = (uint64_t)p->clbu << 32 | p->clb; - p->cmd_lst = paddr_guest2host(ahci_ctx(sc), clb, - AHCI_CL_SIZE * AHCI_MAX_SLOTS); handle_cmd(p); break; } From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 15:20:14 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B78EEA5D for ; Wed, 14 Aug 2013 15:20:14 +0000 (UTC) (envelope-from zcore@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A3DAE21BC for ; Wed, 14 Aug 2013 15:20:14 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EFKEUf049350 for ; Wed, 14 Aug 2013 15:20:14 GMT (envelope-from zcore@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EFKEMM049335 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 15:20:14 GMT (envelope-from zcore@FreeBSD.org) Date: Wed, 14 Aug 2013 15:20:14 GMT Message-Id: <201308141520.r7EFKEMM049335@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zcore@FreeBSD.org using -f From: zcore@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255933 - soc2013/zcore/head/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 15:20:14 -0000 Author: zcore Date: Wed Aug 14 15:20:14 2013 New Revision: 255933 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255933 Log: add ahci_write_fis to emulate d2h/sdb fis Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c ============================================================================== --- soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Wed Aug 14 15:19:16 2013 (r255932) +++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c Wed Aug 14 15:20:14 2013 (r255933) @@ -52,13 +52,27 @@ #include "ahci.h" #include "block_if.h" +#define PxSIG_ATA 0x00000101 /* ATA drive */ +#define PxSIG_ATAPI 0xeb140101 /* ATAPI drive */ + +enum sata_fis_type { + FIS_TYPE_REGH2D = 0x27, /* Register FIS - host to device */ + FIS_TYPE_REGD2H = 0x34, /* Register FIS - device to host */ + FIS_TYPE_DMAACT = 0x39, /* DMA activate FIS - device to host */ + FIS_TYPE_DMASETUP = 0x41, /* DMA setup FIS - bidirectional */ + FIS_TYPE_DATA = 0x46, /* Data FIS - bidirectional */ + FIS_TYPE_BIST = 0x58, /* BIST activate FIS - bidirectional */ + FIS_TYPE_PIOSETUP = 0x5F, /* PIO setup FIS - device to host */ + FIS_TYPE_SETDEVBITS = 0xA1, /* Set device bits FIS - device to host */ +}; + /* * Debug printf */ static FILE *dbg; #define dprintf(format, arg...) do{fprintf(dbg, format, ##arg);fflush(dbg);}while(0) #define DPRINTF(params) dprintf params -#define WPRINTF(params) printf params +#define WPRINTF(params) dprintf params struct ahci_ioreq { struct blockif_req io_req; @@ -74,6 +88,8 @@ struct pci_ahci_softc *pr_sc; uint64_t cmd_lst; uint64_t rfis; + int atapi; + uint32_t clb; uint32_t clbu; uint32_t fb; @@ -155,6 +171,50 @@ pci_generate_msi(sc->asc_pi, 0); } +static void ahci_write_fis(struct ahci_port *p, enum sata_fis_type ft, + uint8_t *fis) +{ + int offset, len, irq; + + if (p->rfis == 0 || !(p->cmd & AHCI_P_CMD_FRE)) + return; + + switch (ft) { + case FIS_TYPE_REGD2H: + offset = 0x40; + len = 20; + irq = AHCI_P_IX_DHR; + break; + case FIS_TYPE_SETDEVBITS: + offset = 0x58; + len = 8; + irq = AHCI_P_IX_SDB; + break; + default: + WPRINTF(("unsupported fis type %d\n", ft)); + break; + } + memcpy(p->rfis + offset, fis, len); + p->is |= irq; + ahci_generate_intr(p->pr_sc); +} + +static void ahci_write_fis_d2h(struct ahci_port *p) +{ + uint8_t fis[20]; + + memset(fis, 0, sizeof(fis)); + fis[0] = FIS_TYPE_REGD2H; + fis[3] = 1; + fis[4] = 1; + if (p->atapi) { + fis[5] = 0x14; + fis[6] = 0xeb; + } + fis[12] = 1; + ahci_write_fis(p, FIS_TYPE_REGD2H, fis); +} + /* * blockif callback routine - this runs in the context of the blockif * i/o thread, so the mutex needs to be acquired. @@ -219,14 +279,21 @@ pr->serr = 0; pr->sact = 0; - /* TODO set signature by the device kind */ - pr->sig = 0x00000101; - pr->tfd = 0; - if (pr->bctx) - pr->ssts = ATA_SS_DET_PHY_ONLINE | ATA_SS_SPD_GEN2 | - ATA_SS_IPM_ACTIVE; - else + if (!pr->bctx) { pr->ssts = ATA_SS_DET_NO_DEVICE; + pr->sig = 0xFFFFFFFF; + pr->tfd = 0x7F; + return; + } + pr->ssts = ATA_SS_DET_PHY_ONLINE | ATA_SS_SPD_GEN2 | + ATA_SS_IPM_ACTIVE; + pr->tfd = (1 << 8) | ATA_S_DSC | ATA_S_DMA; + if (!pr->atapi) { + pr->sig = PxSIG_ATA; + pr->tfd |= ATA_S_READY; + } else + pr->sig = PxSIG_ATAPI; + ahci_write_fis_d2h(pr); } static void From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 17:01:17 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A313368E for ; Wed, 14 Aug 2013 17:01:17 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8E59727C3 for ; Wed, 14 Aug 2013 17:01:17 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EH1HPS047352 for ; Wed, 14 Aug 2013 17:01:17 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EH1Hxc047340 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 17:01:17 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 14 Aug 2013 17:01:17 GMT Message-Id: <201308141701.r7EH1Hxc047340@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255937 - in soc2013/dpl/head/lib/libzcap: . zlibworker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 17:01:17 -0000 Author: dpl Date: Wed Aug 14 17:01:17 2013 New Revision: 255937 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255937 Log: Adapted many functions to be executed on the worker. We now have to finish adapting all the left funtions and adapt the worker functions. Modified: soc2013/dpl/head/lib/libzcap/commands.c soc2013/dpl/head/lib/libzcap/deflate.c soc2013/dpl/head/lib/libzcap/infback.c soc2013/dpl/head/lib/libzcap/inflate.c soc2013/dpl/head/lib/libzcap/inftrees.c soc2013/dpl/head/lib/libzcap/zlibworker/comands.c soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c soc2013/dpl/head/lib/libzcap/zutil.c Modified: soc2013/dpl/head/lib/libzcap/commands.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/commands.c Wed Aug 14 16:15:14 2013 (r255936) +++ soc2013/dpl/head/lib/libzcap/commands.c Wed Aug 14 17:01:17 2013 (r255937) @@ -1,130 +1,803 @@ /* - This is just a template of the capsicumized functions. + * Here live the capsicumed functions of this library. + */ + +#include "zlib.h" +#include "capsicum.c" +#include "commands.h" + +#include + + +/* Basic functions */ +int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, + int memLevel, int strategy, const char * version, + int stream_size); +int zcapcmd_deflate(z_streamp strm, int flush); +int zcapcmd_deflateEnd(z_streamp strm); +int zcapcmd_inflateInit(z_streamp strm); +int zcapcmd_inflate(z_streamp strm, int flush); +int zcapcmd_inflateEnd(z_streamp strm); + +/* Advanced functions */ +int zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_deflateCopy(z_streamp dest, z_streamp source); +int zcapcmd_deflateReset(z_streamp strm); +int zcapcmd_deflateParams(z_streamp strm, int level, int strategy); +int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain); +int zcapcmd_deflateBound(z_streamp strm, uLong sourceLen); +int zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits); +int zcapcmd_deflatePrime(z_streamp strm, int bits, int value); +int zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head); + +int zcapcmd_inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength); +int zcapcmd_inflateSync(z_streamp strm); +int zcapcmd_inflateCopy(z_streamp strm, z_streamp source); +int zcapcmd_inflateReset(z_streamp strm); +int zcapcmd_inflateReset2(z_streamp strm, int windowBits); +int zcapcmd_inflatePrime(z_streamp strm, int bits, int value); +int zcapcmd_inflateMark(z_streamp strm); +int zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head); +int zcapcmd_inflateBackInit(z_streamp strm, int windowBits, + unsigned char *window); +int zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc, + out_func out, void *out_desc); +int zcapcmd_inflateBackEnd(z_streamp strm); +uLong zcapcmd_zlibCompileFlags(void); + +/* Utility functions */ +uLong zcapcmd_compressBound(uLong sourceLen); + +/* gzip file functions */ +gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode); +int zcapcmd_gzbuffer(gzFile file, unsigned size); +int zcapcmd_gzsetparams(gzFile file, int level, int strategy); +int zcapcmd_gzread(gzFile file, voidp buf, unsigned len); +int zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len); +int zcapcmd_gzprintf(gzFile file, const char *format, ...); +int zcapcmd_gzputs(gzFile file, const char *s); +char *zcapcmd_gzgets(gzFile file, char *buf, int len); +int zcapcmd_gzputc(gzFile file, int c); +int zcapcmd_gzungetc(int c, gzFile file); +int zcapcmd_gzflush(gzFile file, int flush); +z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence); +int zcapcmd_simplecommand(gzFile file, int command); +char * zcapcmd_gzerror(gzFile file, int *errnum); + +/* Checksum functions */ +uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len); +uLong zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 ); +uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len); +uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2); + +extern pid_t pid; +extern nvlist_t *sendCommand(nvlist_t *); +extern void * data; + +nvlist_t *nvl, *args, *result; +size_t gzfilesize = sizeof(struct gzFile_s); +size_t gzheadersize = sizeof(struct gz_header_s); +size_t zstreamsize = sizeof(z_stream); + +void checkChild(void) { + if (pid == 0) + startChild(); +} + +void +destroy(void) { + nvlist_destroy(nvl); + nvlist_destroy(args); + nvlist_destroy(result); +} + +int +zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, + int memLevel, int strategy, const char * version, int stream_size) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + /* No worries here */ + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "level", level); + nvlist_add_number(args, "method", method); + nvlist_add_number(args, "windowBits", windowBits); + nvlist_add_number(args, "memLevel", memLevel); + nvlist_add_number(args, "strategy", strategy); + nvlist_add_string(args, "version", version); + nvlist_add_number(args, "stream_size", stream_size); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + /* We take the "good" struct from the worker. + Here we have the good internal_state. + When we work on the data now, we have to pass it in + buffers, and sync: next_in, avail_in, total_in, next_out, + avail_out, total_out. */ + /* Supposing there's already space reserved for z_stream */ + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); + return(ret); +} + +int +zcapcmd_deflateEnd(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + /* Supposing there's already space reserved for z_stream */ + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateInit(z_streamp strm, int windowBits, + const char *version, int stream_size) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + /* No worries here */ + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "windowBits", windowBits); + nvlist_add_string(args, "version", version); + nvlist_add_number(args, "stream_size", stream_size); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); + return(ret); +} + +int +zcapcmd_inflateEnd(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +/* Advanced functions */ +int +zcapcmd_deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, uInt dictLength) +{ + /* XXX */ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dictionary", *dictionary, dictLength); + nvlist_add_number(args, "dictLength", dictLength); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + if (ret == Z_OK) + dataplace = malloc(zstreamsize); + z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateGetDictionary(z_streamp strm, + const Bytef *dictionary, uInt *dictLength) +{ + /* XXX */ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dictionary", *dictionary, dictLength); + nvlist_add_number(args, "dictLength", dictLength); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + if (ret == Z_OK) + dataplace = malloc(zstreamsize); + z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateCopy(z_streamp dest, z_streamp source) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dest", *dest, zstreamsize); + nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + /* The two z_streamp are now copied at the worker. */ + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateReset(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + /* Save the reseted strm. */ + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); + return(ret); +} + +int +zcapcmd_deflateParams(z_streamp strm, int level, int int strategy) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "level", level); + nvlist_add_number(args, "strategy", strategy); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + /* Overwrite the old streamp */ + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "good_length", good_length); + nvlist_add_number(args, "max_lazy", max_lazy); + nvlist_add_number(args, "nice_length", nice_length); + nvlist_add_number(args, "max_chain", max_chain); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateBound(z_streamp strm, uLong sourceLen) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "sourceLen", sourceLen); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + /* Will get malloc()ed at the worker. */ + nvlist_add_number(args, "pending", *pending); + nvlist_add_number(args, "bits", *bits); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflatePrime(z_streamp strm, int bits, int value) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "bits", bits); + nvlist_add_number(args, "value", value); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head) +{ + /* XXX: Beware of gz_headerp extra */ + /* What happens with header->extra??? */ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "head", *head, gzheadersize); + nvlist_add_string(nvl, "name", head->name); + nvlist_add_string(nvl, "comment", head->comment); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateSetDictionary(z_streamp strm, + const Bytef *dictionary, uInt dictLength) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateSync(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateCopy(z_streamp dest, z_streamp source) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_binary(args, "dest", *dest, zstreamsize); + nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + /* The two z_streamp are now copied at the worker. */ + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} + +int +zcapcmd_inflateReset(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); + return(ret); +} -datatype -zcapcmd_function( real func args ) +int +zcapcmd_inflateReset2(z_streamp strm, int windowBits) { - nvlist_t *nvl, *args, *result; - datatype ret; + uLong ret; + zstream * dataplace; - if (pid == 0) - startChild(); + checkChild(); if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL ) { perror("nvlist_create"); - return (NULL); + return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_COMMAND); - nvlist_add_number(args, "crc1", crc1); - nvlist_add_number(args, "crc2", crc2); - nvlist_add_number(args, "len2", len2); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "windowBits", windowBits); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); - ret = nvlist_take_datatypenvl(result, "result") + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); + return(ret); +} + +int +zcapcmd_inflatePrime(z_streamp strm, int bits, int value) +{ + uLong ret; + zstream * dataplace; - nvlist_destroy(args); - nvlist_destroy(nvl); - nvlist_destroy(result); + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(args, "bits", bits); + nvlist_add_number(args, "value", value); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); return(ret); } -*/ +long +zcapcmd_inflateMark(z_streamp strm) +{ + uLong ret; + zstream * dataplace; + + checkChild(); -#include "zlib.h" -#include "capsicum.c" -#include "commands.h" + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_nvlist(nvl, "args", args); -#include + result = sendCommand(nvl); + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); + return(ret); +} -/* Basic functions */ -int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, - int memLevel, int strategy, const char * version, - int stream_size); -int zcapcmd_deflate(z_streamp strm, int flush); -int zcapcmd_deflateEnd(z_streamp strm); -int zcapcmd_inflateInit(z_streamp strm); -int zcapcmd_inflate(z_streamp strm, int flush); -int zcapcmd_inflateEnd(z_streamp strm); +int +zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head) +{ + /* XXX: Beware of gz_headerp extra */ + uLong ret; + zstream * dataplace; + + checkChild(); -/* Advanced functions */ -int zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); -int zcapcmd_deflateCopy(z_streamp dest, z_streamp source); -int zcapcmd_deflateReset(z_streamp strm); -int zcapcmd_deflateParams(z_streamp strm, int level, int strategy); -int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, - int nice_length, int max_chain); -int zcapcmd_deflateBound(z_streamp strm, uLong sourceLen); -int zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits); -int zcapcmd_deflatePrime(z_streamp strm, int bits, int value); -int zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head); + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER); + nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "head", *head, gzheadersize); + nvlist_add_nvlist(nvl, "args", args); -int zcapcmd_inflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); -int zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); -int zcapcmd_inflateSync(z_streamp strm); -int zcapcmd_inflateCopy(z_streamp strm, z_streamp source); -int zcapcmd_inflateReset(z_streamp strm); -int zcapcmd_inflateReset2(z_streamp strm, int windowBits); -int zcapcmd_inflatePrime(z_streamp strm, int bits, int value); -int zcapcmd_inflateMark(z_streamp strm); -int zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head); -int zcapcmd_inflateBackInit(z_streamp strm, int windowBits, - unsigned char *window); -int zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc, - out_func out, void *out_desc); -int zcapcmd_inflateBackEnd(z_streamp strm); -int zcapcmd_zlibCompileFlags(z_streamp strm); + result = sendCommand(nvl); -/* Utility functions */ -uLong zcapcmd_compressBound(uLong sourceLen); + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + gz_headerp newhead = nvlist_take_binary(result, "newhead", gzheadersize); + head->done = newhead->done; + destroy(); + return(ret); +} -/* gzip file functions */ -gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode); -int zcapcmd_gzbuffer(gzFile file, unsigned size); -int zcapcmd_gzsetparams(gzFile file, int level, int strategy); -int zcapcmd_gzread(gzFile file, voidp buf, unsigned len); -int zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len); -int zcapcmd_gzprintf(gzFile file, const char *format, ...); -int zcapcmd_gzputs(gzFile file, const char *s); -char *zcapcmd_gzgets(gzFile file, char *buf, int len); -int zcapcmd_gzputc(gzFile file, int c); -int zcapcmd_gzungetc(int c, gzFile file); -int zcapcmd_gzflush(gzFile file, int flush); -z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence); -int zcapcmd_simplecommand(gzFile file, int command); -char * zcapcmd_gzerror(gzFile file, int *errnum); +uLong +zcapcmd_zlibCompileFlags(z_streamp strm, gz_headerp head) +{ + uLong ret; + zstream * dataplace; + + checkChild(); -/* checksum functions */ -uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len); -uLong zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 ); -uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len); -uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2); + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_ZLIBCOMPILEFLAGS); + nvlist_add_nvlist(nvl, "args", args); -extern pid_t pid; -extern nvlist_t *sendCommand(nvlist_t *); -extern void * data; + result = sendCommand(nvl); -size_t gzFilesize = sizeof(struct gzFile_s); -size_t zstreamsize = sizeof(z_stream); + ret = nvlist_take_number(result, "result"); + destroy(); + return(ret); +} -uLong -zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, - int memLevel, int strategy, const char * version, - int stream_size) +int +zcapcmd_inflateBackInit(z_streamp strm, int windowBits, unsigned char *window + const char *version, int stream_size) { - nvlist_t *nvl, *args, *result; + /* window has to be a pointer to at least a 32kb buffer */ uLong ret; zstream * dataplace; - if (pid == 0) - startChild(); + checkChild(); if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL ) { @@ -132,12 +805,9 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + /* No worries here */ nvlist_add_binary(args, "strm", *strm, zstreamsize); - nvlist_add_number(args, "level", level); - nvlist_add_number(args, "method", method); nvlist_add_number(args, "windowBits", windowBits); - nvlist_add_number(args, "memLevel", memLevel); - nvlist_add_number(args, "strategy", strategy); nvlist_add_string(args, "version", version); nvlist_add_number(args, "stream_size", stream_size); nvlist_add_nvlist(nvl, "args", args); @@ -145,89 +815,74 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - /* We take the "good" struct from the worker. - Here we have the good internal_state. - When we work on the data now, we have to pass it in - buffers, and sync: next_in, avail_in, total_in, next_out, - avail_out, total_out. */ - if (ret == Z_OK) - dataplace = malloc(zstreamsize); - z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(dataplace, strm, zstreamsize); - nvlist_destroy(result); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + char *msg = nvlist_take_string(result, "msg"); + memcpy(strm->msg, msg, strlen(msg)+1); + destroy(); return(ret); } int -zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength) +zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc, + out_func out, void *out_desc) { - nvlist_t *nvl, *args, *result; uLong ret; zstream * dataplace; - if (pid == 0) - startChild(); + checkChild(); if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL ) { perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "dictionary", *dictionary, dictLength); - nvlist_add_number(args, "dictLength", dictLength); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", *strm, zstreamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - if (ret == Z_OK) - dataplace = malloc(zstreamsize); - z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); - nvlist_destroy(result); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + memcpy(strm, newstrm, zstreamsize); + destroy(); return(ret); } int -zcapcmd_deflateCopy(z_streamp dest, z_streamp source) +zcapcmd_inflateBackEnd(z_streamp strm) { - nvlist_t *nvl, *args, *result; uLong ret; zstream * dataplace; - if (pid == 0) - startChild(); + checkChild(); if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL ) { perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "dest", *dest, zstreamsize); - nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", *strm, zstreamsize); nvlist_add_nvlist(nvl, "args", args); - /* The two z_streamp are now copied at the worker. */ result = sendCommand(nvl); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 20:30:07 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 572FE961 for ; Wed, 14 Aug 2013 20:30:07 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 44AD724B2 for ; Wed, 14 Aug 2013 20:30:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EKU7p1004591 for ; Wed, 14 Aug 2013 20:30:07 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EKU7Xo004578 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 20:30:07 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 14 Aug 2013 20:30:07 GMT Message-Id: <201308142030.r7EKU7Xo004578@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255942 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 20:30:07 -0000 Author: syuu Date: Wed Aug 14 20:30:06 2013 New Revision: 255942 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255942 Log: implement pci_dma_read/pci_dma_write Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Aug 14 19:34:13 2013 (r255941) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Aug 14 20:30:06 2013 (r255942) @@ -35,6 +35,7 @@ #include #include "pci_emul.h" +#include "bhyverun.h" #include "hw/usb.h" #define le32_to_cpus(x) le32toh(x) @@ -45,6 +46,7 @@ #define PCI_VENDOR_ID_INTEL 0x8086 #define PCI_DEVICE_ID_INTEL_82801I_UHCI6 0x2939 +#if 0 struct PCIDevice { uint8_t *config; }; @@ -55,6 +57,7 @@ typedef struct PCIDevice PCIDevice; typedef struct PCIDeviceClass PCIDeviceClass; typedef struct MemoryRegion MemoryRegion; +#endif FILE *usblog; @@ -204,7 +207,7 @@ typedef struct UHCIAsync UHCIAsync; typedef struct UHCIQueue UHCIQueue; typedef struct UHCIInfo UHCIInfo; -typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass; +//typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass; struct UHCIInfo { const char *name; @@ -212,14 +215,16 @@ uint16_t device_id; uint8_t revision; uint8_t irq_pin; - int (*initfn)(PCIDevice *dev); +// int (*initfn)(PCIDevice *dev); bool unplug; }; +#if 0 struct UHCIPCIDeviceClass { PCIDeviceClass parent_class; UHCIInfo info; }; +#endif /* * Pending async transaction. @@ -261,9 +266,8 @@ } Timer; struct UHCIState { - struct pci_uhci_softc *sc; - PCIDevice dev; - MemoryRegion io_bar; +// PCIDevice dev; +// MemoryRegion io_bar; USBBus bus; /* Note unused when we're a companion controller */ uint16_t cmd; /* cmd register */ uint16_t status; @@ -293,6 +297,8 @@ uint32_t firstport; uint32_t maxframes; }; +#define STATE_TO_SC(state) \ + container_of((state), struct pci_uhci_softc, sc_pi) typedef struct UHCI_TD { uint32_t link; @@ -314,6 +320,7 @@ struct UHCIState sc_st; pthread_mutex_t sc_mtx; }; +#define uhci_ctx(sc) ((sc)->sc_pi->pi_vmctx) static void uhci_async_cancel(UHCIAsync *async); static void uhci_queue_fill(UHCIQueue *q, UHCI_TD *td); @@ -321,6 +328,29 @@ #define SECINNS (1000000000L) +static int pci_dma_read(struct pci_uhci_softc *sc, uintptr_t addr, void *buf, size_t len) +{ + void *haddr = paddr_guest2host(uhci_ctx(sc), addr, len); + if (!haddr) { + printf("%s failed to translate %p\n", __func__, (void *)addr); + return -1; + } + memcpy(buf, haddr, len); + return 0; +} + +static int pci_dma_write(struct pci_uhci_softc *sc, uintptr_t addr, const void *buf, size_t len) +{ + void *haddr = paddr_guest2host(uhci_ctx(sc), addr, len); + if (!haddr) { + printf("%s failed to translate %p\n", __func__, (void *)addr); + return -1; + } + memcpy(haddr, buf, len); + return 0; +} + + static int64_t timespec_to_ns(struct timespec *ts) { return ((int64_t)(ts->tv_sec * SECINNS) + ts->tv_nsec); @@ -580,9 +610,9 @@ level = 0; } if (level) - pci_lintr_assert(s->sc->sc_pi); + pci_lintr_assert(STATE_TO_SC(s)->sc_pi); else - pci_lintr_deassert(s->sc->sc_pi); + pci_lintr_deassert(STATE_TO_SC(s)->sc_pi); } static void uhci_reset(void *opaque) @@ -590,7 +620,7 @@ UHCIState *s = opaque; int i; UHCIPort *port; - struct pci_uhci_softc *sc = s->sc; + struct pci_uhci_softc *sc = STATE_TO_SC(s); trace_usb_uhci_reset(); @@ -930,7 +960,7 @@ static void uhci_read_td(UHCIState *s, UHCI_TD *td, uint32_t link) { -// pci_dma_read(&s->dev, link & ~0xf, td, sizeof(*td)); + pci_dma_read(STATE_TO_SC(s), link & ~0xf, td, sizeof(*td)); le32_to_cpus(&td->link); le32_to_cpus(&td->ctrl); le32_to_cpus(&td->token); @@ -1009,7 +1039,7 @@ *int_mask |= 0x01; if (pid == USB_TOKEN_IN) { -// pci_dma_write(&s->dev, td->buffer, async->buf, len); + pci_dma_write(STATE_TO_SC(s), td->buffer, async->buf, len); if ((td->ctrl & TD_CTRL_SPD) && len < max_len) { *int_mask |= 0x02; /* short packet: do not update QH */ @@ -1127,7 +1157,7 @@ switch(pid) { case USB_TOKEN_OUT: case USB_TOKEN_SETUP: -// pci_dma_read(&s->dev, td->buffer, async->buf, max_len); + pci_dma_read(STATE_TO_SC(s), td->buffer, async->buf, max_len); usb_handle_packet(q->ep->dev, &async->packet); if (async->packet.status == USB_RET_SUCCESS) { async->packet.actual_length = max_len; @@ -1259,7 +1289,7 @@ frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); -// pci_dma_read(&s->dev, frame_addr, &link, 4); + pci_dma_read(STATE_TO_SC(s), frame_addr, &link, 4); le32_to_cpus(&link); int_mask = 0; @@ -1297,7 +1327,7 @@ } } -// pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); + pci_dma_read(STATE_TO_SC(s), link & ~0xf, &qh, sizeof(qh)); le32_to_cpus(&qh.link); le32_to_cpus(&qh.el_link); @@ -1322,7 +1352,7 @@ if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); -// pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); + pci_dma_write(STATE_TO_SC(s), (link & ~0xf) + 4, &val, sizeof(val)); } switch (ret) { @@ -1350,7 +1380,7 @@ /* update QH element link */ qh.el_link = link; val = cpu_to_le32(qh.el_link); -// pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); + pci_dma_write(STATE_TO_SC(s), (curr_qh & ~0xf) + 4, &val, sizeof(val)); if (!depth_first(link)) { /* done with this QH */ @@ -1727,7 +1757,6 @@ sc->sc_st.frame_timer = new_timer(uhci_frame_timer, &sc->sc_st); sc->sc_st.num_ports_vmstate = NB_PORTS; QTAILQ_INIT(&sc->sc_st.queues); - sc->sc_st.sc = sc; fprintf(usblog, "%s:%d\n", __func__, __LINE__); uhci_reset(&sc->sc_st); From owner-svn-soc-all@FreeBSD.ORG Wed Aug 14 21:05:56 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 4E85CF8B for ; Wed, 14 Aug 2013 21:05:56 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3C3A82724 for ; Wed, 14 Aug 2013 21:05:56 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7EL5uWt079381 for ; Wed, 14 Aug 2013 21:05:56 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7EL5tGb079366 for svn-soc-all@FreeBSD.org; Wed, 14 Aug 2013 21:05:55 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 14 Aug 2013 21:05:55 GMT Message-Id: <201308142105.r7EL5tGb079366@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255944 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Aug 2013 21:05:56 -0000 Author: syuu Date: Wed Aug 14 21:05:55 2013 New Revision: 255944 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255944 Log: temporary commented out assert() in pci_lintr_assert/pci_lintr_deassert Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/pci_emul.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/pci_emul.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/pci_emul.c Wed Aug 14 20:20:42 2013 (r255943) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/pci_emul.c Wed Aug 14 21:05:55 2013 (r255944) @@ -1158,7 +1158,7 @@ pci_lintr_assert(struct pci_devinst *pi) { - assert(pi->pi_lintr_pin); +// assert(pi->pi_lintr_pin); ioapic_assert_pin(pi->pi_vmctx, pi->pi_lintr_pin); } @@ -1166,7 +1166,7 @@ pci_lintr_deassert(struct pci_devinst *pi) { - assert(pi->pi_lintr_pin); +// assert(pi->pi_lintr_pin); ioapic_deassert_pin(pi->pi_vmctx, pi->pi_lintr_pin); } From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 04:30:04 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A057AB90 for ; Thu, 15 Aug 2013 04:30:04 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7FA4220FE for ; Thu, 15 Aug 2013 04:30:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7F4U4GX058478 for ; Thu, 15 Aug 2013 04:30:04 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7F4U4OD058472 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 04:30:04 GMT (envelope-from syuu@FreeBSD.org) Date: Thu, 15 Aug 2013 04:30:04 GMT Message-Id: <201308150430.r7F4U4OD058472@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255958 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb: . gpl include/hw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 04:30:04 -0000 Author: syuu Date: Thu Aug 15 04:30:03 2013 New Revision: 255958 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255958 Log: trying to enable device registration Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/dev-hub.c Thu Aug 15 04:30:03 2013 (r255958) @@ -28,8 +28,6 @@ //#include "qemu/error-report.h" #include -#define NUM_PORTS 8 - #define trace_usb_hub_attach(a,b) #define trace_usb_hub_detach(a,b) #define trace_usb_hub_reset(a) @@ -38,6 +36,8 @@ #define trace_usb_hub_set_port_feature(a,b,c) #define trace_usb_hub_clear_port_feature(a,b,c) +#if 0 +#define NUM_PORTS 8 typedef struct USBHubPort { USBPort port; @@ -51,6 +51,7 @@ USBEndpoint *intr; USBHubPort ports[NUM_PORTS]; } USBHubState; +#endif #define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE) #define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE) @@ -515,7 +516,6 @@ } } -/* static USBPortOps usb_hub_port_ops = { .attach = usb_hub_attach, .detach = usb_hub_detach, @@ -523,7 +523,6 @@ .wakeup = usb_hub_wakeup, .complete = usb_hub_complete, }; -*/ static int usb_hub_initfn(USBDevice *dev) { @@ -532,7 +531,7 @@ int i; if (dev->port->hubcount == 5) { -// error_report("usb hub chain too deep"); + error_report("usb hub chain too deep"); return -1; } @@ -541,11 +540,9 @@ s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); for (i = 0; i < NUM_PORTS; i++) { port = &s->ports[i]; - /* usb_register_port(usb_bus_from_device(dev), &port->port, s, i, &usb_hub_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); - */ usb_port_location(&port->port, dev->port, i+1); } usb_hub_handle_reset(dev); @@ -575,12 +572,12 @@ VMSTATE_END_OF_LIST() } }; +*/ -static void usb_hub_class_initfn(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - USBDeviceClass *uc = USB_DEVICE_CLASS(klass); +void usb_hub_class_initfn(USBDeviceClass *uc, void *data); +void usb_hub_class_initfn(USBDeviceClass *uc, void *data) +{ uc->init = usb_hub_initfn; uc->product_desc = "QEMU USB Hub"; uc->usb_desc = &desc_hub; @@ -589,10 +586,11 @@ uc->handle_control = usb_hub_handle_control; uc->handle_data = usb_hub_handle_data; uc->handle_destroy = usb_hub_handle_destroy; - dc->fw_name = "hub"; - dc->vmsd = &vmstate_usb_hub; +// dc->fw_name = "hub"; +// dc->vmsd = &vmstate_usb_hub; } +/* static const TypeInfo hub_info = { .name = "usb-hub", .parent = TYPE_USB_DEVICE, Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/bus.c Thu Aug 15 04:30:03 2013 (r255958) @@ -1,4 +1,6 @@ #include +#include +#include //#include "hw/hw.h" #include "hw/usb.h" //#include "hw/qdev.h" @@ -6,12 +8,34 @@ //#include "monitor/monitor.h" //#include "trace.h" +#define trace_usb_port_claim(a, b) +#define trace_usb_port_attach(a,b,c,d) + +void pstrcpy(char *buf, int buf_size, const char *str) +{ + int c; + char *q = buf; + + if (buf_size <= 0) + return; + + for(;;) { + c = *str++; + if (c == 0 || q >= buf + buf_size - 1) + break; + *q++ = c; + } + *q = '\0'; +} + #if 0 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); static char *usb_get_fw_dev_path(DeviceState *qdev); -static int usb_qdev_exit(DeviceState *qdev); +#endif +static int usb_qdev_exit(USBDevice *dev); +#if 0 static Property usb_props[] = { DEFINE_PROP_STRING("port", USBDevice, port_path), @@ -75,6 +99,7 @@ void usb_bus_new(USBBus *bus, USBBusOps *ops /*, DeviceState *host*/) { // qbus_create_inplace(&bus->qbus, TYPE_USB_BUS, host, NULL); + strncpy(bus->name, TYPE_USB_BUS, sizeof(bus->name)); bus->ops = ops; bus->busnr = next_usb_bus++; // bus->qbus.allow_hotplug = 1; /* Yes, we can */ @@ -96,6 +121,7 @@ } return NULL; } +#endif static int usb_device_init(USBDevice *dev) { @@ -106,6 +132,7 @@ return 0; } +#if 0 USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr) { USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); @@ -114,6 +141,7 @@ } return NULL; } +#endif static void usb_device_handle_destroy(USBDevice *dev) { @@ -123,6 +151,7 @@ } } +#if 0 void usb_device_cancel_packet(USBDevice *dev, USBPacket *p) { USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); @@ -205,10 +234,8 @@ } } -#if 0 -static int usb_qdev_init(DeviceState *qdev) +static int usb_qdev_init(USBDevice *dev) { - USBDevice *dev = USB_DEVICE(qdev); int rc; pstrcpy(dev->product_desc, sizeof(dev->product_desc), @@ -228,17 +255,15 @@ if (dev->auto_attach) { rc = usb_device_attach(dev); if (rc != 0) { - usb_qdev_exit(qdev); + usb_qdev_exit(dev); return rc; } } return 0; } -static int usb_qdev_exit(DeviceState *qdev) +static int usb_qdev_exit(USBDevice *dev) { - USBDevice *dev = USB_DEVICE(qdev); - if (dev->attached) { usb_device_detach(dev); } @@ -249,6 +274,7 @@ return 0; } +#if 0 typedef struct LegacyUSBFactory { const char *name; @@ -270,32 +296,27 @@ legacy_usb_factory = g_slist_append(legacy_usb_factory, f); } } +#endif -USBDevice *usb_create(USBBus *bus, const char *name) +USBDevice *usb_create(USBBus *bus, const char *name, size_t len) { - DeviceState *dev; + USBDevice *dev; - dev = qdev_create(&bus->qbus, name); - return USB_DEVICE(dev); + dev = (USBDevice *)calloc(1, len); + strncpy(dev->name, name, sizeof(dev->name)); + return dev; } -USBDevice *usb_create_simple(USBBus *bus, const char *name) +USBDevice *usb_create_simple(USBBus *bus, const char *name, size_t len) { - USBDevice *dev = usb_create(bus, name); - int rc; + USBDevice *dev = usb_create(bus, name, len); if (!dev) { error_report("Failed to create USB device '%s'", name); return NULL; } - rc = qdev_init(&dev->qdev); - if (rc < 0) { - error_report("Failed to initialize USB device '%s'", name); - return NULL; - } return dev; } -#endif static void usb_fill_port(USBPort *port, void *opaque, int index, USBPortOps *ops, int speedmask) @@ -322,13 +343,11 @@ USBBus *bus; int i; -#if 0 QTAILQ_FOREACH(bus, &busses, next) { - if (strcmp(bus->qbus.name, masterbus) == 0) { + if (strcmp(bus->name, masterbus) == 0) { break; } } -#endif if (!bus || !bus->ops->register_companion) { // qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus", @@ -360,11 +379,10 @@ } } -#if 0 void usb_unregister_port(USBBus *bus, USBPort *port) { - if (port->dev) - qdev_free(&port->dev->qdev); +// if (port->dev) +// qdev_free(&port->dev->qdev); QTAILQ_REMOVE(&bus->free, port, next); bus->nfree--; } @@ -384,13 +402,13 @@ } if (port == NULL) { error_report("Error: usb port %s (bus %s) not found (in use?)", - dev->port_path, bus->qbus.name); + dev->port_path, bus->name); return -1; } } else { - if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) { + if (bus->nfree == 1 && strcmp(dev->name, "usb-hub") != 0) { /* Create a new hub and chain it on */ - usb_create_simple(bus, "usb-hub"); + usb_create_simple(bus, "usb-hub", sizeof(struct USBHubState)); } if (bus->nfree == 0) { error_report("Error: tried to attach usb device %s to a bus " @@ -412,6 +430,7 @@ return 0; } +#if 0 void usb_release_port(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); @@ -429,6 +448,7 @@ QTAILQ_INSERT_TAIL(&bus->free, port, next); bus->nfree++; } +#endif static void usb_mask_to_str(char *dest, size_t size, unsigned int speedmask) @@ -470,7 +490,7 @@ " usb device \"%s\" (%s speed)" " to bus \"%s\", port \"%s\" (%s speed)", dev->product_desc, devspeed, - bus->qbus.name, port->path, portspeed); + bus->name, port->path, portspeed); return -1; } @@ -480,6 +500,7 @@ return 0; } +#if 0 int usb_device_detach(USBDevice *dev) { USBBus *bus = usb_bus_from_device(dev); Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/gpl/dev-serial.c Thu Aug 15 04:30:03 2013 (r255958) @@ -13,6 +13,7 @@ #include #include #include +#include //#include "qemu-common.h" //#include "qemu/error-report.h" @@ -124,6 +125,7 @@ uint8_t event_trigger; QEMUSerialSetParams params; int latency; /* ms */ + FILE *fp; // CharDriverState *cs; } USBSerialState; @@ -385,6 +387,7 @@ for (i = 0; i < p->iov.niov; i++) { iov = p->iov.iov + i; // qemu_chr_fe_write(s->cs, iov->iov_base, iov->iov_len); + fwrite(iov->iov_base, iov->iov_len, 1, s->fp); } p->actual_length = p->iov.size; break; @@ -495,8 +498,7 @@ } } -#if 0 -static int usb_serial_initfn(USBDevice *dev) +int usb_serial_initfn(USBDevice *dev) { USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); @@ -504,6 +506,7 @@ usb_desc_init(dev); dev->auto_attach = 0; +#if 0 if (!s->cs) { error_report("Property chardev is required"); return -1; @@ -511,59 +514,62 @@ qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read, usb_serial_event, s); +#endif + s->fp = fopen("/tmp/usbserial.out", "w"); usb_serial_handle_reset(dev); - if (s->cs->be_open && !dev->attached) { +// if (s->cs->be_open && !dev->attached) { usb_device_attach(dev); - } +// } return 0; } -#endif -static USBDevice *usb_serial_init(USBBus *bus, const char *filename) +USBDevice *usb_serial_init(USBBus *bus /*, const char *filename */) { USBDevice *dev; // CharDriverState *cdrv; - uint32_t vendorid = 0, productid = 0; +// uint32_t vendorid = 0, productid = 0; char label[32]; static int index; +#if 0 while (*filename && *filename != ':') { const char *p; char *e; if (strstart(filename, "vendorid=", &p)) { vendorid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { -// error_report("bogus vendor ID %s", p); + error_report("bogus vendor ID %s", p); return NULL; } filename = e; } else if (strstart(filename, "productid=", &p)) { productid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { -// error_report("bogus product ID %s", p); + error_report("bogus product ID %s", p); return NULL; } filename = e; } else { -// error_report("unrecognized serial USB option %s", filename); + error_report("unrecognized serial USB option %s", filename); return NULL; } while(*filename == ',') filename++; } if (!*filename) { -// error_report("character device specification needed"); + error_report("character device specification needed"); return NULL; } filename++; +#endif snprintf(label, sizeof(label), "usbserial%d", index++); // cdrv = qemu_chr_new(label, filename, NULL); // if (!cdrv) // return NULL; - dev = usb_create(bus, "usb-serial"); + dev = usb_create(bus, "usb-serial", sizeof(USBSerialState)); if (!dev) { return NULL; } @@ -577,23 +583,23 @@ return dev; } +#if 0 static USBDevice *usb_braille_init(USBBus *bus, const char *unused) { USBDevice *dev; -// CharDriverState *cdrv; + CharDriverState *cdrv; -// cdrv = qemu_chr_new("braille", "braille", NULL); -// if (!cdrv) -// return NULL; + cdrv = qemu_chr_new("braille", "braille", NULL); + if (!cdrv) + return NULL; dev = usb_create(bus, "usb-braille"); -// qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); -// qdev_init_nofail(&dev->qdev); + qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); + qdev_init_nofail(&dev->qdev); return dev; } -#if 0 static const VMStateDescription vmstate_usb_serial = { .name = "usb-serial", .unmigratable = 1, @@ -603,23 +609,22 @@ DEFINE_PROP_CHR("chardev", USBSerialState, cs), DEFINE_PROP_END_OF_LIST(), }; +#endif -static void usb_serial_class_initfn(ObjectClass *klass, void *data) +static void usb_serial_class_initfn(USBDeviceClass *uc, void *data) { - DeviceClass *dc = DEVICE_CLASS(klass); - USBDeviceClass *uc = USB_DEVICE_CLASS(klass); - uc->init = usb_serial_initfn; uc->product_desc = "QEMU USB Serial"; uc->usb_desc = &desc_serial; uc->handle_reset = usb_serial_handle_reset; uc->handle_control = usb_serial_handle_control; uc->handle_data = usb_serial_handle_data; - dc->vmsd = &vmstate_usb_serial; - dc->props = serial_properties; - set_bit(DEVICE_CATEGORY_INPUT, dc->categories); +// dc->vmsd = &vmstate_usb_serial; +// dc->props = serial_properties; +// set_bit(DEVICE_CATEGORY_INPUT, dc->categories); } +#if 0 static const TypeInfo serial_info = { .name = "usb-serial", .parent = TYPE_USB_DEVICE, Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Thu Aug 15 04:30:03 2013 (r255958) @@ -1702,6 +1702,8 @@ return (value); } +extern USBDevice *usb_serial_init(USBBus *bus /*, const char *filename */); +extern int usb_serial_initfn(USBDevice *dev); static int pci_uhci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { @@ -1761,6 +1763,10 @@ uhci_reset(&sc->sc_st); pci_emul_alloc_bar(pi, 4, PCIBAR_IO, 0x20); + { + USBDevice *dev = usb_serial_init(&sc->sc_st.bus); + usb_serial_initfn(dev); + } return (0); } Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Aug 15 01:42:46 2013 (r255957) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Thu Aug 15 04:30:03 2013 (r255958) @@ -332,6 +332,7 @@ int altsetting[USB_MAX_INTERFACES]; const USBDescConfig *config; const USBDescIface *ifaces[USB_MAX_INTERFACES]; + char name[128]; }; typedef struct USBPortOps { @@ -512,6 +513,7 @@ QTAILQ_HEAD(, USBPort) free; QTAILQ_HEAD(, USBPort) used; QTAILQ_ENTRY(USBBus) next; + char name[128]; }; struct USBBusOps { @@ -525,8 +527,8 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name, USBDevice *(*usbdevice_init)(USBBus *bus, const char *params)); -USBDevice *usb_create(USBBus *bus, const char *name); -USBDevice *usb_create_simple(USBBus *bus, const char *name); +USBDevice *usb_create(USBBus *bus, const char *name, size_t len); +USBDevice *usb_create_simple(USBBus *bus, const char *name, size_t len); USBDevice *usbdevice_create(const char *cmdline); void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, USBPortOps *ops, int speedmask); @@ -595,4 +597,21 @@ uint8_t interface_protocol); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define error_report(...) fprintf(stderr, __VA_ARGS__) + +#define NUM_PORTS 8 + +typedef struct USBHubPort { + USBPort port; + uint16_t wPortStatus; + uint16_t wPortChange; + uint16_t wPortChange_reported; +} USBHubPort; + +typedef struct USBHubState { + USBDevice dev; + USBEndpoint *intr; + USBHubPort ports[NUM_PORTS]; +} USBHubState; + #endif From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 08:00:02 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 57ECB4F9 for ; Thu, 15 Aug 2013 08:00:02 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2A18B2DB7 for ; Thu, 15 Aug 2013 08:00:02 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7F8028s044754 for ; Thu, 15 Aug 2013 08:00:02 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7F8027R044720 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 08:00:02 GMT (envelope-from ccqin@FreeBSD.org) Date: Thu, 15 Aug 2013 08:00:02 GMT Message-Id: <201308150800.r7F8027R044720@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255966 - soc2013/ccqin/head/sys/net80211 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 08:00:02 -0000 Author: ccqin Date: Thu Aug 15 08:00:01 2013 New Revision: 255966 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255966 Log: Fix some errors and move the ir_capabilities to irn_capabilities in per node rc state. * some minor errors fixed. * add struct ieee80211_ratectl_node. this is the common state that all per node rc state, i.e. ieee80211_[amrr|sample]_node, should contains it as the first field. * move ir_capabilities to irn_capabilities in ieee80211_ratectl_node. ieee80211_ratectl is readonly, so ir_capabilities can't be set. And, the capabilities is not a part of rc algo. It seems that it should be put in the per node rc state. Interface of ieee80211_ratectl_node_init() and its callers are updated. References to ir_capabilities are also adapted. Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c soc2013/ccqin/head/sys/net80211/ieee80211_amrr.h soc2013/ccqin/head/sys/net80211/ieee80211_node.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h soc2013/ccqin/head/sys/net80211/ieee80211_sta.c Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 08:00:01 2013 (r255966) @@ -47,8 +47,8 @@ #include #include -#include #include +#include #define is_success(amn) \ ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10) @@ -60,7 +60,7 @@ static void amrr_setinterval(const struct ieee80211vap *, int); static void amrr_init(struct ieee80211vap *); static void amrr_deinit(struct ieee80211vap *); -static void amrr_node_init(struct ieee80211_node *); +static void amrr_node_init(struct ieee80211_node *, uint32_t); static void amrr_node_deinit(struct ieee80211_node *); static int amrr_update(struct ieee80211_amrr *, struct ieee80211_amrr_node *, struct ieee80211_node *); @@ -141,7 +141,7 @@ } static void -amrr_node_init(struct ieee80211_node *ni) +amrr_node_init(struct ieee80211_node *ni, uint32_t capabilities) { const struct ieee80211_rateset *rs = NULL; struct ieee80211vap *vap = ni->ni_vap; @@ -159,6 +159,10 @@ } } else amn = ni->ni_rctls; + + struct ieee80211_ratectl_node *irn = IEEE80211_RATECTL_NODE(ni); + irn->irn_capabilities = capabilities; + amn->amn_amrr = amrr; amn->amn_success = 0; amn->amn_recovery = 0; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_amrr.h Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_amrr.h Thu Aug 15 08:00:01 2013 (r255966) @@ -20,6 +20,7 @@ #ifndef _NET80211_IEEE80211_AMRR_H_ #define _NET80211_IEEE80211_AMRR_H_ +#include /*- * Naive implementation of the Adaptive Multi Rate Retry algorithm: * @@ -47,6 +48,7 @@ * Rate control state for a given node. */ struct ieee80211_amrr_node { + struct ieee80211_ratectl_node amn_node; struct ieee80211_amrr *amn_amrr;/* backpointer */ int amn_rix; /* current rate index */ int amn_ticks; /* time of last update */ Modified: soc2013/ccqin/head/sys/net80211/ieee80211_node.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_node.c Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_node.c Thu Aug 15 08:00:01 2013 (r255966) @@ -846,7 +846,8 @@ /* XXX QoS? Difficult given that WME config is specific to a master */ ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); return ieee80211_sta_join1(ieee80211_ref_node(ni)); } @@ -1188,7 +1189,8 @@ IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni, "%s: inact_reload %u", __func__, ni->ni_inact_reload); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); return ni; } @@ -1228,7 +1230,8 @@ /* XXX optimize away */ ieee80211_psq_init(&ni->ni_psq, "unknown"); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); } else { /* XXX msg */ vap->iv_stats.is_rx_nodealloc++; @@ -1457,7 +1460,8 @@ #endif } ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, 1); /* XXX not right for 802.1x/WPA */ @@ -1531,7 +1535,8 @@ ieee80211_setup_basic_htrates(ni, ni->ni_ies.htinfo_ie); ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); } } @@ -1558,7 +1563,8 @@ if (ieee80211_iserp_rateset(&ni->ni_rates)) ni->ni_flags |= IEEE80211_NODE_ERP; ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, 1); /* XXX not right for 802.1x/WPA */ @@ -2528,7 +2534,8 @@ ); ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); /* give driver a chance to setup state like ni_txrate */ if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, newassoc); Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 08:00:01 2013 (r255966) @@ -94,11 +94,10 @@ } void -ieee80211_ratectl_init(struct ieee80211vap *vap, uint32_t capabilities) +ieee80211_ratectl_init(struct ieee80211vap *vap) { if (vap->iv_rate == ratectls[IEEE80211_RATECTL_NONE]) ieee80211_ratectl_set(vap, IEEE80211_RATECTL_AMRR); - vap->iv_rate.ir_capabilities = capabilities; vap->iv_rate->ir_init(vap); } @@ -121,11 +120,10 @@ } void -ieee80211_ratectl_complete_rcflags(const struct ieee80211_node *ni, +ieee80211_ratectl_complete_rcflags(struct ieee80211_node *ni, struct ieee80211_rc_info *rc_info) { const struct ieee80211com *ic = ni->ni_ic; - const struct ieee80211vap *vap = ni->ni_vap; const struct ieee80211_rate_table * rt = ic->ic_rt; struct ieee80211_rc_series *rc = rc_info->ri_rc; int shortPreamble = rc_info->ri_shortPreamble; @@ -136,7 +134,7 @@ * If enable rts/cts and is pre-802.11n, blank tries 1, 2, 3 */ - if (! (vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRRPROT)) + if (! IEEE80211_RATECTL_HASCAP_MRRPROT(ni)) { for (i = 1; i < IEEE80211_RATECTL_NUM; i++) { Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 08:00:01 2013 (r255966) @@ -60,11 +60,21 @@ #define IEEE80211_RATECTL_STBC_FLAG 0x20 /* enable STBC */ #define IEEE80211_RATECTL_TS_FLAG 0x40 /* triple-stream rate */ -/* Hardware CAPs chip offered to rate control code */ +/* Hardware CAPs offered to rate control algo */ #define IEEE80211_RATECTL_CAP_MRR 0x01 /* support MRR */ #define IEEE80211_RATECTL_CAP_MRRPROT 0x02 /* support MRR + protect */ #define IEEE80211_RATECTL_CAP_MULTXCHAIN 0x04 /* has more than 1 txchain */ +#define IEEE80211_RATECTL_NODE(_ni) \ + ((struct ieee80211_ratectl_node *)((_ni)->ni_rctls)) + +#define IEEE80211_RATECTL_HASCAP_MRR(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRR) +#define IEEE80211_RATECTL_HASCAP_MRRPROT(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRRPROT) +#define IEEE80211_RATECTL_HASCAP_MULTXCHAIN(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MULTXCHAIN) + #define IS_VAP_HT(vap) ((vap)->iv_htcaps & IEEE80211_HTC_HT) #define IS_HT_RATE(_rate) ((_rate) & 0x80) @@ -83,7 +93,7 @@ uint16_t max4msframelen; }; -/* */ +/* net80211 rate control infomation */ struct ieee80211_rc_info { struct ieee80211_rc_series ri_rc[IEEE80211_RATECTL_NUM]; int ri_framelen; @@ -103,13 +113,11 @@ struct ieee80211_ratectl { const char *ir_name; - uint32_t ir_capabilities; /* hardware capabilities offered to rc */ - int (*ir_attach)(const struct ieee80211vap *); void (*ir_detach)(const struct ieee80211vap *); void (*ir_init)(struct ieee80211vap *); void (*ir_deinit)(struct ieee80211vap *); - void (*ir_node_init)(struct ieee80211_node *); + void (*ir_node_init)(struct ieee80211_node *, uint32_t); void (*ir_node_deinit)(struct ieee80211_node *); int (*ir_rate)(struct ieee80211_node *, void *, uint32_t); void (*ir_rates)(struct ieee80211_node *, struct ieee80211_rc_info *); @@ -122,12 +130,17 @@ void (*ir_setinterval)(const struct ieee80211vap *, int); }; +/* per ratectl node must start with this common state */ +struct ieee80211_ratectl_node { + uint32_t irn_capabilities; /* hardware capabilities offered to rc */ +}; + void ieee80211_ratectl_register(int, const struct ieee80211_ratectl *); void ieee80211_ratectl_unregister(int); -void ieee80211_ratectl_init(struct ieee80211vap *, uint32_t); +void ieee80211_ratectl_init(struct ieee80211vap *); void ieee80211_ratectl_set(struct ieee80211vap *, int); -void ieee80211_ratectl_complete_rcflags(const struct ieee80211_node *, - struct ieee80211_rc_info*) +void ieee80211_ratectl_complete_rcflags(struct ieee80211_node *, + struct ieee80211_rc_info*); MALLOC_DECLARE(M_80211_RATECTL); @@ -138,11 +151,11 @@ } static void __inline -ieee80211_ratectl_node_init(struct ieee80211_node *ni) +ieee80211_ratectl_node_init(struct ieee80211_node *ni, uint32_t capabilities) { const struct ieee80211vap *vap = ni->ni_vap; - vap->iv_rate->ir_node_init(ni); + vap->iv_rate->ir_node_init(ni, capabilities); } static void __inline @@ -205,18 +218,19 @@ ieee80211_ratectl_hascap_shortgi(const struct ieee80211vap *vap, const struct ieee80211_node *ni) { - if (! IS_VAP_HT(vap)) - return IEEE80211_RATECTL_FALSE; - - if (ni->ni_chw == 40 && - vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI40 && - ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40) - return IEEE80211_RATECTL_TRUE; - - if (ni->ni_chw == 20 && - vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI20 && - ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) - return IEEE80211_RATECTL_TRUE; + if (IS_VAP_HT(vap)) + { + if (ni->ni_chw == 40 && + vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI40 && + ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40) + return IEEE80211_RATECTL_TRUE; + + if (ni->ni_chw == 20 && + vap->iv_htcaps & IEEE80211_HTCAP_SHORTGI20 && + ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) + return IEEE80211_RATECTL_TRUE; + } + return IEEE80211_RATECTL_FALSE; } @@ -226,7 +240,7 @@ { return IS_VAP_HT(vap) && (vap->iv_htcaps & IEEE80211_HTCAP_TXSTBC) && (ni->ni_htcap & IEEE80211_HTCAP_RXSTBC_1STREAM) && - (vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MULTXCHAIN); + IEEE80211_RATECTL_HASCAP_MULTXCHAIN(ni); } #endif Modified: soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Thu Aug 15 08:00:01 2013 (r255966) @@ -1,6 +1,7 @@ /* $FreeBSD: head/sys/dev/ath/ath_rate/sample/sample.c 248573 2013-02-27 04:33:06Z adrian $*/ /*- + * Copyright (c) 2005 John Bicket * Copyright (c) 2013 Chenchong Qin * All rights reserved. * @@ -138,7 +139,7 @@ }; static void -sample_node_init(struct ieee80211_node *ni) +sample_node_init(struct ieee80211_node *ni, uint32_t capabilities) { #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) #define DOT11RATE(_ix) (rt->info[(_ix)].dot11Rate & IEEE80211_RATE_VAL) @@ -160,6 +161,10 @@ } } else san = ni->ni_rctls; + + struct ieee80211_ratectl_node *irn = IEEE80211_RATECTL_NODE(ni); + irn->irn_capabilities = capabilities; + san->san_sample = sample; KASSERT(rt != NULL, ("no rate table, mode %u", curmode)); @@ -628,9 +633,9 @@ goto done; } - if (vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRR) + if (IEEE80211_RATECTL_HASCAP_MRR(ni)) mrr = 1; - if (!(vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRRPROT)) + if (! IEEE80211_RATECTL_HASCAP_MRRPROT(ni)) mrr = 0; best_rix = pick_best_rate(ni, rt, size_bin, !mrr); @@ -942,12 +947,12 @@ return; } - if (vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRR) + if (IEEE80211_RATECTL_HASCAP_MRR(ni)) mrr = 1; /* XXX check HT protmode too */ - if (mrr && !(vap->iv_rate->ir_capabilities & IEEE80211_RATECTL_CAP_MRRPROT)) + if (mrr && !IEEE80211_RATECTL_HASCAP_MRRPROT(ni)) mrr = 0; - + if (!mrr || rc_info->ri_finaltsi == 0) { if (!IS_RATE_DEFINED(san, final_rix)) { return; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.h Thu Aug 15 08:00:01 2013 (r255966) @@ -1,6 +1,7 @@ /* $FreeBSD: head/sys/dev/ath/ath_rate/sample/sample.h 240382 2012-08-15 07:10:10Z adrian $*/ /*- + * Copyright (c) 2005 John Bicket * Copyright (c) 2013 Chenchong Qin * All rights reserved. * @@ -39,6 +40,8 @@ #ifndef _NET80211_IEEE80211_RATECTL_SAMPLE_H_ #define _NET80211_IEEE80211_RATECTL_SAMPLE_H_ +#include + /* * for now, we track performance for three different packet * size buckets @@ -82,6 +85,7 @@ */ /* XXX change naming conversion? */ struct ieee80211_sample_node { + struct ieee80211_ratectl_node san_node; /* common state */ struct ieee80211_sample *san_sample;/* backpointer */ int static_rix; /* rate index of fixed tx rate */ uint64_t ratemask; /* bit mask of valid rate indices */ Modified: soc2013/ccqin/head/sys/net80211/ieee80211_sta.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_sta.c Thu Aug 15 07:54:31 2013 (r255965) +++ soc2013/ccqin/head/sys/net80211/ieee80211_sta.c Thu Aug 15 08:00:01 2013 (r255966) @@ -1636,7 +1636,8 @@ IEEE80211_F_JOIN | IEEE80211_F_DOBRS); ieee80211_setup_basic_htrates(ni, htinfo); ieee80211_node_setuptxparms(ni); - ieee80211_ratectl_node_init(ni); + /* XXX TODO fill the cap field */ + ieee80211_ratectl_node_init(ni, 0); } else { #ifdef IEEE80211_SUPPORT_SUPERG if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_ATH)) From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 09:07:05 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id AFDC665E for ; Thu, 15 Aug 2013 09:07:05 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9C2A8212D for ; Thu, 15 Aug 2013 09:07:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7F975eL007991 for ; Thu, 15 Aug 2013 09:07:05 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7F975tk007967 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 09:07:05 GMT (envelope-from ccqin@FreeBSD.org) Date: Thu, 15 Aug 2013 09:07:05 GMT Message-Id: <201308150907.r7F975tk007967@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255969 - soc2013/ccqin/head/sys/net80211 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 09:07:05 -0000 Author: ccqin Date: Thu Aug 15 09:07:05 2013 New Revision: 255969 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255969 Log: Some error fixed and come functions added. * fix the error refering rateCode of ieee80211_rate_table. * add ieee80211_ratectl_[node_is11n|get_rateset] to the ratectl api. rc algos all need these functions. * change the naming conversion of IEEE80211_RATECTL_FLAG_*. Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 08:21:00 2013 (r255968) +++ soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 09:07:05 2013 (r255969) @@ -130,7 +130,7 @@ } static int -amrr_node_is_11n(struct ieee80211_node *ni) +ieee80211_ratectl_node_is11n(struct ieee80211_node *ni) { if (ni->ni_chan == NULL) @@ -169,23 +169,13 @@ amn->amn_txcnt = amn->amn_retrycnt = 0; amn->amn_success_threshold = amrr->amrr_min_success_threshold; - /* 11n or not? Pick the right rateset */ - if (amrr_node_is_11n(ni)) { - /* XXX ew */ - IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "%s: 11n node", __func__); - rs = (struct ieee80211_rateset *) &ni->ni_htrates; - } else { - IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "%s: non-11n node", __func__); - rs = &ni->ni_rates; - } + rs = ieee80211_ratectl_get_rateset(ni); /* Initial rate - lowest */ rate = rs->rs_rates[0]; /* XXX clear the basic rate flag if it's not 11n */ - if (! amrr_node_is_11n(ni)) + if (! ieee80211_ratectl_node_is11n(ni)) rate &= IEEE80211_RATE_VAL; /* pick initial rate from the rateset - HT or otherwise */ @@ -193,7 +183,7 @@ amn->amn_rix--) { /* legacy - anything < 36mbit, stop searching */ /* 11n - stop at MCS4 / MCS12 / MCS28 */ - if (amrr_node_is_11n(ni) && + if (ieee80211_ratectl_node_is11n(ni) && (rs->rs_rates[amn->amn_rix] & 0x7) < 4) break; else if ((rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL) <= 72) @@ -202,7 +192,7 @@ } /* if the rate is an 11n rate, ensure the MCS bit is set */ - if (amrr_node_is_11n(ni)) + if (ieee80211_ratectl_node_is11n(ni)) rate |= IEEE80211_RATE_MCS; /* Assign initial rate from the rateset */ @@ -230,13 +220,8 @@ KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt)); - /* 11n or not? Pick the right rateset */ - if (amrr_node_is_11n(ni)) { - /* XXX ew */ - rs = (struct ieee80211_rateset *) &ni->ni_htrates; - } else { - rs = &ni->ni_rates; - } + rs = ieee80211_ratectl_get_rateset(ni); + IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "AMRR: current rate %d, txcnt=%d, retrycnt=%d", @@ -308,13 +293,7 @@ const struct ieee80211_rateset *rs = NULL; int rix; - /* 11n or not? Pick the right rateset */ - if (amrr_node_is_11n(ni)) { - /* XXX ew */ - rs = (struct ieee80211_rateset *) &ni->ni_htrates; - } else { - rs = &ni->ni_rates; - } + rs = ieee80211_ratectl_get_rateset(ni); if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) { rix = amrr_update(amrr, amn, ni); @@ -322,7 +301,7 @@ /* update public rate */ ni->ni_txrate = rs->rs_rates[rix]; /* XXX strip basic rate flag from txrate, if non-11n */ - if (amrr_node_is_11n(ni)) + if (ieee80211_ratectl_node_is11n(ni)) ni->ni_txrate |= IEEE80211_RATE_MCS; else ni->ni_txrate &= IEEE80211_RATE_VAL; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 08:21:00 2013 (r255968) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 09:07:05 2013 (r255969) @@ -123,13 +123,15 @@ ieee80211_ratectl_complete_rcflags(struct ieee80211_node *ni, struct ieee80211_rc_info *rc_info) { + const struct ieee80211_rate_table * rt = NULL; const struct ieee80211com *ic = ni->ni_ic; - const struct ieee80211_rate_table * rt = ic->ic_rt; struct ieee80211_rc_series *rc = rc_info->ri_rc; int shortPreamble = rc_info->ri_shortPreamble; uint8_t rate; int i; + rt = ieee80211_get_ratetable(ni->ni_ic->ic_curchan); + /* Make sure that rate control code doesn't mess it up. * If enable rts/cts and is pre-802.11n, blank tries 1, 2, 3 */ @@ -138,9 +140,9 @@ { for (i = 1; i < IEEE80211_RATECTL_NUM; i++) { - if (rc[0].flags & IEEE80211_RATECTL_RTSCTS_FLAG) + if (rc[0].flags & IEEE80211_RATECTL_FLAG_RTSCTS) rc[i].tries = 0; - rc[i].flags &= ~IEEE80211_RATECTL_RTSCTS_FLAG; + rc[i].flags &= ~IEEE80211_RATECTL_FLAG_RTSCTS; } } @@ -149,13 +151,18 @@ if (rc[i].tries == 0) continue; - rate = rt->info[rc[i].rix].rateCode; + rate = rt->info[rc[i].rix].dot11Rate; /* * Only enable short preamble for legacy rates */ + + /* XXX how we get the non_ht ratecode here? */ + + #if 0 if ((! IS_HT_RATE(rate)) && shortPreamble) rate |= rt->info[rc[i].rix].shortPreamble; + #endif /* * Save this, used by the TX and completion code @@ -164,7 +171,7 @@ /* Only enable shortgi, 2040, dual-stream if HT is set */ if (IS_HT_RATE(rate)) { - rc[i].flags |= IEEE80211_RATECTL_HT_FLAG; + rc[i].flags |= IEEE80211_RATECTL_FLAG_HT; /* * XXX TODO: LDPC @@ -174,9 +181,9 @@ * Dual / Triple stream rate? */ if (HT_RC_2_STREAMS(rate) == 2) - rc[i].flags |= IEEE80211_RATECTL_DS_FLAG; + rc[i].flags |= IEEE80211_RATECTL_FLAG_DS; else if (HT_RC_2_STREAMS(rate) == 3) - rc[i].flags |= IEEE80211_RATECTL_TS_FLAG; + rc[i].flags |= IEEE80211_RATECTL_FLAG_TS; } /* @@ -190,16 +197,16 @@ * Calculate the maximum 4ms frame length based * on the MCS rate, SGI and channel width flags. */ - if ((rc[i].flags & IEEE80211_RATECTL_HT_FLAG) && + if ((rc[i].flags & IEEE80211_RATECTL_FLAG_HT) && (HT_RC_2_MCS(rate) < 32)) { int j; - if (rc[i].flags & IEEE80211_RATECTL_CW40_FLAG) { - if (rc[i].flags & IEEE80211_RATECTL_SGI_FLAG) + if (rc[i].flags & IEEE80211_RATECTL_FLAG_CW40) { + if (rc[i].flags & IEEE80211_RATECTL_FLAG_SGI) j = MCS_HT40_SGI; else j = MCS_HT40; } else { - if (rc[i].flags & IEEE80211_RATECTL_SGI_FLAG) + if (rc[i].flags & IEEE80211_RATECTL_FLAG_SGI) j = MCS_HT20_SGI; else j = MCS_HT20; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 08:21:00 2013 (r255968) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 09:07:05 2013 (r255969) @@ -37,13 +37,6 @@ IEEE80211_RATECTL_MAX }; -enum { - MCS_HT20, - MCS_HT20_SGI, - MCS_HT40, - MCS_HT40_SGI, -}; - #define IEEE80211_RATECTL_TX_SUCCESS 1 #define IEEE80211_RATECTL_TX_FAILURE 0 @@ -52,35 +45,30 @@ #define IEEE80211_RATECTL_NUM 4 -#define IEEE80211_RATECTL_DS_FLAG 0x01 /* dual-stream rate */ -#define IEEE80211_RATECTL_CW40_FLAG 0x02 /* use HT40 */ -#define IEEE80211_RATECTL_SGI_FLAG 0x04 /* use short-GI */ -#define IEEE80211_RATECTL_HT_FLAG 0x08 /* use HT */ -#define IEEE80211_RATECTL_RTSCTS_FLAG 0x10 /* enable RTS/CTS protection */ -#define IEEE80211_RATECTL_STBC_FLAG 0x20 /* enable STBC */ -#define IEEE80211_RATECTL_TS_FLAG 0x40 /* triple-stream rate */ +#define IEEE80211_RATECTL_FLAG_DS 0x01 /* dual-stream rate */ +#define IEEE80211_RATECTL_FLAG_CW40 0x02 /* use HT40 */ +#define IEEE80211_RATECTL_FLAG_SGI 0x04 /* use short-GI */ +#define IEEE80211_RATECTL_FLAG_HT 0x08 /* use HT */ +#define IEEE80211_RATECTL_FLAG_RTSCTS 0x10 /* enable RTS/CTS protection */ +#define IEEE80211_RATECTL_FLAG_STBC 0x20 /* enable STBC */ +#define IEEE80211_RATECTL_FLAG_TS 0x40 /* triple-stream rate */ /* Hardware CAPs offered to rate control algo */ #define IEEE80211_RATECTL_CAP_MRR 0x01 /* support MRR */ #define IEEE80211_RATECTL_CAP_MRRPROT 0x02 /* support MRR + protect */ #define IEEE80211_RATECTL_CAP_MULTXCHAIN 0x04 /* has more than 1 txchain */ -#define IEEE80211_RATECTL_NODE(_ni) \ - ((struct ieee80211_ratectl_node *)((_ni)->ni_rctls)) - -#define IEEE80211_RATECTL_HASCAP_MRR(_ni) \ - (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRR) -#define IEEE80211_RATECTL_HASCAP_MRRPROT(_ni) \ - (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRRPROT) -#define IEEE80211_RATECTL_HASCAP_MULTXCHAIN(_ni) \ - (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MULTXCHAIN) - #define IS_VAP_HT(vap) ((vap)->iv_htcaps & IEEE80211_HTC_HT) - #define IS_HT_RATE(_rate) ((_rate) & 0x80) #define HT_RC_2_MCS(_rc) ((_rc) & 0x7f) #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1) +enum { + MCS_HT20, + MCS_HT20_SGI, + MCS_HT40, + MCS_HT40_SGI, +}; extern int max_4ms_framelen[4][32]; @@ -135,6 +123,16 @@ uint32_t irn_capabilities; /* hardware capabilities offered to rc */ }; +#define IEEE80211_RATECTL_NODE(_ni) \ + ((struct ieee80211_ratectl_node *)((_ni)->ni_rctls)) + +#define IEEE80211_RATECTL_HASCAP_MRR(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRR) +#define IEEE80211_RATECTL_HASCAP_MRRPROT(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MRRPROT) +#define IEEE80211_RATECTL_HASCAP_MULTXCHAIN(_ni) \ + (IEEE80211_RATECTL_NODE(_ni)->irn_capabilities & IEEE80211_RATECTL_CAP_MULTXCHAIN) + void ieee80211_ratectl_register(int, const struct ieee80211_ratectl *); void ieee80211_ratectl_unregister(int); void ieee80211_ratectl_init(struct ieee80211vap *); @@ -243,4 +241,22 @@ IEEE80211_RATECTL_HASCAP_MULTXCHAIN(ni); } +static int __inline +ieee80211_ratectl_node_is11n(const struct ieee80211_node *ni) +{ + if (ni->ni_chan == NULL) + return (0); + if (ni->ni_chan == IEEE80211_CHAN_ANYC) + return (0); + return (IEEE80211_IS_CHAN_HT(ni->ni_chan)); +} + +static const struct ieee80211_rateset * __inline +ieee80211_ratectl_get_rateset(const struct ieee80211_node *ni) +{ + return ieee80211_ratectl_node_is11n(ni) ? + (struct ieee80211_rateset *) &ni->ni_htrates : + &ni->ni_rates; +} + #endif Modified: soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Thu Aug 15 08:21:00 2013 (r255968) +++ soc2013/ccqin/head/sys/net80211/ieee80211_rc_sample.c Thu Aug 15 09:07:05 2013 (r255969) @@ -111,18 +111,6 @@ free(vap->iv_rs, M_80211_RATECTL); } -// XXX should be shared by ratectl algos -static int -sample_node_is_11n(struct ieee80211_node *ni) -{ - - if (ni->ni_chan == NULL) - return (0); - if (ni->ni_chan == IEEE80211_CHAN_ANYC) - return (0); - return (IEEE80211_IS_CHAN_HT(ni->ni_chan)); -} - static const struct txschedule *mrr_schedules[IEEE80211_MODE_MAX+2] = { NULL, /* IEEE80211_MODE_AUTO */ series_11a, /* IEEE80211_MODE_11A */ @@ -591,24 +579,6 @@ #undef MCS } -static const struct ieee80211_rateset * -sample_get_rateset(const struct ieee80211_node *ni) -{ - const struct ieee80211_rateset *rs = NULL; - /* 11n or not? Pick the right rateset */ - if (sample_node_is_11n(ni)) { - /* XXX ew */ - IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "%s: 11n node", __func__); - rs = (struct ieee80211_rateset *) &ni->ni_htrates; - } else { - IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "%s: non-11n node", __func__); - rs = &ni->ni_rates; - } - return rs; -} - static int sample_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused) { From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 10:18:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B4CF5299 for ; Thu, 15 Aug 2013 10:18:36 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9562424E5 for ; Thu, 15 Aug 2013 10:18:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7FAIaBv082216 for ; Thu, 15 Aug 2013 10:18:36 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7FAIa5S082204 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 10:18:36 GMT (envelope-from ccqin@FreeBSD.org) Date: Thu, 15 Aug 2013 10:18:36 GMT Message-Id: <201308151018.r7FAIa5S082204@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255970 - soc2013/ccqin/head/sys/net80211 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 10:18:36 -0000 Author: ccqin Date: Thu Aug 15 10:18:36 2013 New Revision: 255970 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255970 Log: fix some errors. Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h soc2013/ccqin/head/sys/net80211/ieee80211_ratectl_none.c Modified: soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 09:07:05 2013 (r255969) +++ soc2013/ccqin/head/sys/net80211/ieee80211_amrr.c Thu Aug 15 10:18:36 2013 (r255970) @@ -129,17 +129,6 @@ free(vap->iv_rs, M_80211_RATECTL); } -static int -ieee80211_ratectl_node_is11n(struct ieee80211_node *ni) -{ - - if (ni->ni_chan == NULL) - return (0); - if (ni->ni_chan == IEEE80211_CHAN_ANYC) - return (0); - return (IEEE80211_IS_CHAN_HT(ni->ni_chan)); -} - static void amrr_node_init(struct ieee80211_node *ni, uint32_t capabilities) { Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 09:07:05 2013 (r255969) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.c Thu Aug 15 10:18:36 2013 (r255970) @@ -124,9 +124,8 @@ struct ieee80211_rc_info *rc_info) { const struct ieee80211_rate_table * rt = NULL; - const struct ieee80211com *ic = ni->ni_ic; struct ieee80211_rc_series *rc = rc_info->ri_rc; - int shortPreamble = rc_info->ri_shortPreamble; + /* int shortPreamble = rc_info->ri_shortPreamble; */ uint8_t rate; int i; Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 09:07:05 2013 (r255969) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl.h Thu Aug 15 10:18:36 2013 (r255970) @@ -251,7 +251,7 @@ return (IEEE80211_IS_CHAN_HT(ni->ni_chan)); } -static const struct ieee80211_rateset * __inline +__inline static const struct ieee80211_rateset * ieee80211_ratectl_get_rateset(const struct ieee80211_node *ni) { return ieee80211_ratectl_node_is11n(ni) ? Modified: soc2013/ccqin/head/sys/net80211/ieee80211_ratectl_none.c ============================================================================== --- soc2013/ccqin/head/sys/net80211/ieee80211_ratectl_none.c Thu Aug 15 09:07:05 2013 (r255969) +++ soc2013/ccqin/head/sys/net80211/ieee80211_ratectl_none.c Thu Aug 15 10:18:36 2013 (r255970) @@ -57,7 +57,7 @@ } static void -none_node_init(struct ieee80211_node *ni) +none_node_init(struct ieee80211_node *ni, uint32_t capabilities) { ni->ni_txrate = ni->ni_rates.rs_rates[0] & IEEE80211_RATE_VAL; } From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 10:22:15 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7024F306 for ; Thu, 15 Aug 2013 10:22:15 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4E4B8252B for ; Thu, 15 Aug 2013 10:22:15 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7FAMF5K060813 for ; Thu, 15 Aug 2013 10:22:15 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7FAMFlG060798 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 10:22:15 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 15 Aug 2013 10:22:15 GMT Message-Id: <201308151022.r7FAMFlG060798@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255971 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 10:22:15 -0000 Author: mattbw Date: Thu Aug 15 10:22:15 2013 New Revision: 255971 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255971 Log: Add stubs for GetDepends and GetRequires. These aren't yet wired up to the main backend file, but are ready to build and fill in with code otherwise. Added: soc2013/mattbw/backend/actions/get_depends.c soc2013/mattbw/backend/actions/get_requires.c Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions.h soc2013/mattbw/backend/actions/get_files.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Thu Aug 15 10:18:36 2013 (r255970) +++ soc2013/mattbw/backend/Makefile Thu Aug 15 10:22:15 2013 (r255971) @@ -33,9 +33,11 @@ search.c \ utils.c SRCS+= \ + actions/get_depends.c \ actions/get_details.c \ actions/get_files.c \ actions/get_repo_list.c \ + actions/get_requires.c \ actions/get_update_detail.c \ actions/install_files.c \ actions/install_packages.c \ Modified: soc2013/mattbw/backend/actions.h ============================================================================== --- soc2013/mattbw/backend/actions.h Thu Aug 15 10:18:36 2013 (r255970) +++ soc2013/mattbw/backend/actions.h Thu Aug 15 10:22:15 2013 (r255971) @@ -28,9 +28,11 @@ * Each thread is implemented in its namesake C file, except simulations * which are stored with their non-simulated counterparts. */ +gboolean get_depends_thread(PkBackend *backend); gboolean get_details_thread(PkBackend *backend); gboolean get_files_thread(PkBackend *backend); gboolean get_repo_list_thread(PkBackend *backend); +gboolean get_requires_thread(PkBackend *backend); gboolean get_update_detail_thread(PkBackend *backend); gboolean install_files_thread(PkBackend *backend); gboolean install_packages_thread(PkBackend *backend); Added: soc2013/mattbw/backend/actions/get_depends.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get_depends.c Thu Aug 15 10:22:15 2013 (r255971) @@ -0,0 +1,36 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include /* assert */ +#include /* gboolean */ +#include "../pk-backend.h" /* PkBackend */ + +#include "../actions.h" /* Prototype */ + +/* + * The thread that performs a GetDepends operation. Should be invoked by the + * pk_backend_get_depends hook. + */ +gboolean +get_depends_thread(PkBackend *backend) +{ + + assert(backend != NULL); + return FALSE; +} Modified: soc2013/mattbw/backend/actions/get_files.c ============================================================================== --- soc2013/mattbw/backend/actions/get_files.c Thu Aug 15 10:18:36 2013 (r255970) +++ soc2013/mattbw/backend/actions/get_files.c Thu Aug 15 10:22:15 2013 (r255971) @@ -33,8 +33,8 @@ static bool emit(struct pkg *pkg, const gchar *id, struct query *q); /* - * The thread that performs a GetDetails operation. Should be invoked by the - * pk_backend_get_details hook. + * The thread that performs a GetFiles operation. Should be invoked by the + * pk_backend_get_files hook. */ gboolean get_files_thread(PkBackend *backend) Added: soc2013/mattbw/backend/actions/get_requires.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get_requires.c Thu Aug 15 10:22:15 2013 (r255971) @@ -0,0 +1,37 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include /* assert */ +#include /* gboolean */ +#include "../pk-backend.h" /* PkBackend */ + +#include "../actions.h" /* Prototype */ + +/* + * The thread that performs a GetRequires operation. Should be invoked by the + * pk_backend_get_requires hook. + */ +gboolean +get_requires_thread(PkBackend *backend) +{ + + assert(backend != NULL); + return FALSE; +} From owner-svn-soc-all@FreeBSD.ORG Thu Aug 15 21:16:04 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 19528FD0 for ; Thu, 15 Aug 2013 21:16:04 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EBA442A3A for ; Thu, 15 Aug 2013 21:16:03 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7FLG3O1004750 for ; Thu, 15 Aug 2013 21:16:03 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7FLG3Ri004736 for svn-soc-all@FreeBSD.org; Thu, 15 Aug 2013 21:16:03 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 15 Aug 2013 21:16:03 GMT Message-Id: <201308152116.r7FLG3Ri004736@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255996 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Aug 2013 21:16:04 -0000 Author: mattbw Date: Thu Aug 15 21:16:03 2013 New Revision: 255996 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255996 Log: Add stub GetDepends and GetImplements to the backend. These are now wired up to the query code, but need the actual package emitters making. These should both use very similar code, so I'll probably factor it out as part of the query directory. Modified: soc2013/mattbw/backend/actions/get_depends.c soc2013/mattbw/backend/actions/get_files.c soc2013/mattbw/backend/actions/get_requires.c soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/actions/get_depends.c ============================================================================== --- soc2013/mattbw/backend/actions/get_depends.c Thu Aug 15 20:33:17 2013 (r255995) +++ soc2013/mattbw/backend/actions/get_depends.c Thu Aug 15 21:16:03 2013 (r255996) @@ -19,9 +19,16 @@ */ #include /* assert */ #include /* gboolean */ +#include /* bool */ +#include "pkg.h" /* PKG_..., struct pkg, etc. */ #include "../pk-backend.h" /* PkBackend */ #include "../actions.h" /* Prototype */ +#include "../query.h" /* query_... */ + +static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_DEPS; + +static bool emit(struct pkg *pkg, const gchar *id, struct query *q); /* * The thread that performs a GetDepends operation. Should be invoked by the @@ -30,7 +37,27 @@ gboolean get_depends_thread(PkBackend *backend) { + bool success; assert(backend != NULL); - return FALSE; + + (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); + success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit); + + (void)pk_backend_finished(backend); + return success ? TRUE : FALSE; +} + +static bool +emit(struct pkg *pkg, const gchar *id, struct query *q) +{ + + bool success; + + assert(pkg != NULL); + assert(id != NULL); + assert(q != NULL); + + success = false; + return success; } Modified: soc2013/mattbw/backend/actions/get_files.c ============================================================================== --- soc2013/mattbw/backend/actions/get_files.c Thu Aug 15 20:33:17 2013 (r255995) +++ soc2013/mattbw/backend/actions/get_files.c Thu Aug 15 21:16:03 2013 (r255996) @@ -39,7 +39,7 @@ gboolean get_files_thread(PkBackend *backend) { - gboolean success; + bool success; assert(backend != NULL); Modified: soc2013/mattbw/backend/actions/get_requires.c ============================================================================== --- soc2013/mattbw/backend/actions/get_requires.c Thu Aug 15 20:33:17 2013 (r255995) +++ soc2013/mattbw/backend/actions/get_requires.c Thu Aug 15 21:16:03 2013 (r255996) @@ -20,9 +20,16 @@ #include /* assert */ #include /* gboolean */ +#include /* bool */ +#include "pkg.h" /* PKG_..., struct pkg, etc. */ #include "../pk-backend.h" /* PkBackend */ #include "../actions.h" /* Prototype */ +#include "../query.h" /* query_... */ + +static const unsigned int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_RDEPS; + +static bool emit(struct pkg *pkg, const gchar *id, struct query *q); /* * The thread that performs a GetRequires operation. Should be invoked by the @@ -31,7 +38,27 @@ gboolean get_requires_thread(PkBackend *backend) { + bool success; assert(backend != NULL); - return FALSE; + + (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); + success = query_match_id_to_emitter(backend, LOAD_FLAGS, emit); + + (void)pk_backend_finished(backend); + return success ? TRUE : FALSE; +} + +static bool +emit(struct pkg *pkg, const gchar *id, struct query *q) +{ + + bool success; + + assert(pkg != NULL); + assert(id != NULL); + assert(q != NULL); + + success = false; + return success; } Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Thu Aug 15 20:33:17 2013 (r255995) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Thu Aug 15 21:16:03 2013 (r255996) @@ -87,6 +87,18 @@ */ void +pk_backend_get_depends(PkBackend *backend, PkBitfield filters, + gchar **package_ids, gboolean recursive) +{ + + INTENTIONALLY_IGNORE(filters); /* retrieved from backend */ + INTENTIONALLY_IGNORE(package_ids); /* retrieved from backend */ + INTENTIONALLY_IGNORE(recursive); /* retrieved from backend */ + assert(backend != NULL); + THREAD(backend, get_depends_thread); +} + +void pk_backend_get_details(PkBackend *backend, gchar **package_ids) { @@ -104,6 +116,18 @@ THREAD(backend, get_files_thread); } +void +pk_backend_get_requires(PkBackend *backend, PkBitfield filters, + gchar **package_ids, gboolean recursive) +{ + + INTENTIONALLY_IGNORE(filters); /* retrieved from backend */ + INTENTIONALLY_IGNORE(package_ids); /* retrieved from backend */ + INTENTIONALLY_IGNORE(recursive); /* retrieved from backend */ + assert(backend != NULL); + THREAD(backend, get_requires_thread); +} + PkBitfield pk_backend_get_filters(PkBackend *backend) { From owner-svn-soc-all@FreeBSD.ORG Fri Aug 16 11:26:12 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 067CE998 for ; Fri, 16 Aug 2013 11:26:12 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E61E72089 for ; Fri, 16 Aug 2013 11:26:11 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7GBQBrK011571 for ; Fri, 16 Aug 2013 11:26:11 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7GBQBS9011554 for svn-soc-all@FreeBSD.org; Fri, 16 Aug 2013 11:26:11 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 16 Aug 2013 11:26:11 GMT Message-Id: <201308161126.r7GBQBS9011554@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256022 - in soc2013/mattbw/backend: . actions query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Aug 2013 11:26:12 -0000 Author: mattbw Date: Fri Aug 16 11:26:11 2013 New Revision: 256022 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256022 Log: Add more stub-work for GetDepends and GetRequires. Both of these actions will eventually be serviced by the same function with only the pkg_deps/pkg_rdeps function being passed in changing. Next is to implement the simpler case of GetDepends/GetRequires without recursion. I think this will likely need changes to the query system to allow multiple PackageIDs in one query, or else multiple copies of the same depends/requires might appear. That can be fixed later. The main sticking point is that dependencies are not packages - they might not exist at all in the repositories - so I'll need to write some new code to deal with these (the current emission code is for packages specifically). Added: soc2013/mattbw/backend/query/depends.c soc2013/mattbw/backend/query/depends.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get_depends.c soc2013/mattbw/backend/actions/get_requires.c soc2013/mattbw/backend/query.h Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Fri Aug 16 10:53:36 2013 (r256021) +++ soc2013/mattbw/backend/Makefile Fri Aug 16 11:26:11 2013 (r256022) @@ -52,6 +52,7 @@ SRCS+= \ query/core.c \ + query/depends.c \ query/do.c \ query/match.c Modified: soc2013/mattbw/backend/actions/get_depends.c ============================================================================== --- soc2013/mattbw/backend/actions/get_depends.c Fri Aug 16 10:53:36 2013 (r256021) +++ soc2013/mattbw/backend/actions/get_depends.c Fri Aug 16 11:26:11 2013 (r256022) @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + #include /* assert */ #include /* gboolean */ #include /* bool */ @@ -52,12 +53,9 @@ emit(struct pkg *pkg, const gchar *id, struct query *q) { - bool success; - assert(pkg != NULL); assert(id != NULL); assert(q != NULL); - success = false; - return success; + return query_depends_emit(query_backend(q), pkg, pkg_deps); } Modified: soc2013/mattbw/backend/actions/get_requires.c ============================================================================== --- soc2013/mattbw/backend/actions/get_requires.c Fri Aug 16 10:53:36 2013 (r256021) +++ soc2013/mattbw/backend/actions/get_requires.c Fri Aug 16 11:26:11 2013 (r256022) @@ -53,12 +53,9 @@ emit(struct pkg *pkg, const gchar *id, struct query *q) { - bool success; - assert(pkg != NULL); assert(id != NULL); assert(q != NULL); - success = false; - return success; + return query_depends_emit(query_backend(q), pkg, pkg_rdeps); } Modified: soc2013/mattbw/backend/query.h ============================================================================== --- soc2013/mattbw/backend/query.h Fri Aug 16 10:53:36 2013 (r256021) +++ soc2013/mattbw/backend/query.h Fri Aug 16 11:26:11 2013 (r256022) @@ -25,5 +25,6 @@ #include "query/do.h" /* query_do_... */ #include "query/match.h" /* query_match_... */ +#include "query/depends.h" /* query_depends_... */ #endif /* !_PKGNG_BACKEND_QUERY_H_ */ Added: soc2013/mattbw/backend/query/depends.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/query/depends.c Fri Aug 16 11:26:11 2013 (r256022) @@ -0,0 +1,43 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include /* assert */ +#include /* bool */ +#include "pkg.h" /* pkg... */ +#include "../pk-backend.h" /* PkBackend */ + +#include "depends.h" /* query_depends_... */ +#include "../utils.h" /* ERR */ + +bool +query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get) +{ + bool success; + + assert(backend != NULL); + assert(pkg != NULL); + assert(get != NULL); + + success = false; + + ERR(backend, PK_ERROR_ENUM_NOT_SUPPORTED, "soon"); + + return success; +} Added: soc2013/mattbw/backend/query/depends.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/query/depends.h Fri Aug 16 11:26:11 2013 (r256022) @@ -0,0 +1,33 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef _PKGNG_BACKEND_QUERY_DEPENDS_H_ +#define _PKGNG_BACKEND_QUERY_DEPENDS_H_ + +#include /* bool */ +#include "pkg.h" /* pkg_... */ +#include "../pk-backend.h" /* Pk... */ + + +typedef int (*depends_get_ptr) (const struct pkg *pkg, struct pkg_dep **dep); + +bool query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get); + +#endif /*_PKGNG_BACKEND_QUERY_DEPENDS_H_*/ + From owner-svn-soc-all@FreeBSD.ORG Fri Aug 16 11:32:56 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 80CBFA40 for ; Fri, 16 Aug 2013 11:32:56 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6D0B620EB for ; Fri, 16 Aug 2013 11:32:56 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7GBWuZh049033 for ; Fri, 16 Aug 2013 11:32:56 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7GBWuum049031 for svn-soc-all@FreeBSD.org; Fri, 16 Aug 2013 11:32:56 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 16 Aug 2013 11:32:56 GMT Message-Id: <201308161132.r7GBWuum049031@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256023 - soc2013/mattbw/backend/query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Aug 2013 11:32:56 -0000 Author: mattbw Date: Fri Aug 16 11:32:56 2013 New Revision: 256023 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256023 Log: Add the for-loop to query_depends_emit. This still doesn't do anything, unfortunately. Modified: soc2013/mattbw/backend/query/depends.c Modified: soc2013/mattbw/backend/query/depends.c ============================================================================== --- soc2013/mattbw/backend/query/depends.c Fri Aug 16 11:26:11 2013 (r256022) +++ soc2013/mattbw/backend/query/depends.c Fri Aug 16 11:32:56 2013 (r256023) @@ -30,6 +30,7 @@ query_depends_emit(PkBackend *backend, struct pkg *pkg, depends_get_ptr get) { bool success; + struct pkg_dep *dep; assert(backend != NULL); assert(pkg != NULL); @@ -37,6 +38,11 @@ success = false; + dep = NULL; + while (get(pkg, &dep) == EPKG_OK) { + ; /* Do something here */ + } + ERR(backend, PK_ERROR_ENUM_NOT_SUPPORTED, "soon"); return success; From owner-svn-soc-all@FreeBSD.ORG Fri Aug 16 19:34:23 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3B16AD0D for ; Fri, 16 Aug 2013 19:34:23 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 2676C2CCF for ; Fri, 16 Aug 2013 19:34:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7GJYN6j003598 for ; Fri, 16 Aug 2013 19:34:23 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7GJYNIa003578 for svn-soc-all@FreeBSD.org; Fri, 16 Aug 2013 19:34:23 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 16 Aug 2013 19:34:23 GMT Message-Id: <201308161934.r7GJYNIa003578@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256036 - in soc2013/dpl/head/lib/libzcap: . contrib test zlibworker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Aug 2013 19:34:23 -0000 Author: dpl Date: Fri Aug 16 19:34:22 2013 New Revision: 256036 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256036 Log: I'm writing a test bed to check that the functions are fine. Right now, I'm having some problems when sending back the results from zlibworker. Added: soc2013/dpl/head/lib/libzcap/test/functionstest.c soc2013/dpl/head/lib/libzcap/zlibworker/commands.c Deleted: soc2013/dpl/head/lib/libzcap/contrib/ soc2013/dpl/head/lib/libzcap/zlibworker/comands.c Modified: soc2013/dpl/head/lib/libzcap/Makefile soc2013/dpl/head/lib/libzcap/adler32.c soc2013/dpl/head/lib/libzcap/capsicum.c soc2013/dpl/head/lib/libzcap/capsicum.h soc2013/dpl/head/lib/libzcap/commands.c soc2013/dpl/head/lib/libzcap/commands.h soc2013/dpl/head/lib/libzcap/crc32.c soc2013/dpl/head/lib/libzcap/deflate.c soc2013/dpl/head/lib/libzcap/gzlib.c soc2013/dpl/head/lib/libzcap/gzread.c soc2013/dpl/head/lib/libzcap/gzwrite.c soc2013/dpl/head/lib/libzcap/infback.c soc2013/dpl/head/lib/libzcap/inflate.c soc2013/dpl/head/lib/libzcap/zlibworker/Makefile soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c soc2013/dpl/head/lib/libzcap/zutil.c Modified: soc2013/dpl/head/lib/libzcap/Makefile ============================================================================== --- soc2013/dpl/head/lib/libzcap/Makefile Fri Aug 16 18:47:18 2013 (r256035) +++ soc2013/dpl/head/lib/libzcap/Makefile Fri Aug 16 19:34:22 2013 (r256036) @@ -3,23 +3,20 @@ # #TODEL -CFLAGS+= -Wall -g -v -fno-color-diagnostics +CFLAGS+= -Wall -g -fno-color-diagnostics LIB= zcap SHLIBDIR?= /lib SHLIB_MAJOR= 6 -MAN= zcaplib.3 - -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-g -DDEBUG -#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ -# -Wstrict-prototypes -Wmissing-prototypes +NO_MAN= CFLAGS+= -DHAS_snprintf -DHAS_vsnprintf -I${.CURDIR} WARNS?= 3 CLEANFILES+= example.o example foo.gz minigzip.o minigzip +SRCS+= capsicum.c +SRCS+= commands.c SRCS+= adler32.c SRCS+= compress.c SRCS+= crc32.c @@ -36,29 +33,13 @@ SRCS+= uncompr.c SRCS+= zopen.c SRCS+= zutil.c -SRCS+= capsicum.c -SRCS+= commands.c -#.if ${MACHINE_ARCH} == "i386" && ${MACHINE_CPU:M*i686*} -#.PATH: ${.CURDIR}/contrib/asm686 -#SRCS+= match.S -#CFLAGS+= -DASMV -DNO_UNDERLINE -#ACFLAGS+= -Wa,--noexecstack -#.endif - -#.if ${MACHINE_ARCH} == "amd64" -#.PATH: ${.CURDIR}/contrib/gcc_gvmat64 -#SRCS+= gvmat64.S -#CFLAGS+= -DASMV -DNO_UNDERLINE -#ACFLAGS+= -Wa,--noexecstack -#.endif +SUBDIR= zlibworker VERSION_DEF= ${.CURDIR}/Versions.def SYMBOL_MAPS= ${.CURDIR}/Symbol.map CFLAGS+= -DSYMBOL_VERSIONING -INCS= zconf.h zlib.h - minigzip: all minigzip.o $(CC) -o minigzip minigzip.o -L. -lz @@ -71,7 +52,3 @@ echo hello world | ./minigzip | ./minigzip -d ) .include - -## XXX: clang integrated-as doesn't grok .intel_syntax directives yet -#ACFLAGS.gvmat64.S= ${CLANG_NO_IAS} -#ACFLAGS+= ${ACFLAGS.${.IMPSRC:T}} Modified: soc2013/dpl/head/lib/libzcap/adler32.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/adler32.c Fri Aug 16 18:47:18 2013 (r256035) +++ soc2013/dpl/head/lib/libzcap/adler32.c Fri Aug 16 19:34:22 2013 (r256036) @@ -11,55 +11,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); -#define BASE 65521 /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware -- - try it both ways to see which is faster */ -#ifdef NO_DIVIDE -/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 - (thank you to John Reiser for pointing this out) */ -# define CHOP(a) \ - do { \ - unsigned long tmp = a >> 16; \ - a &= 0xffffUL; \ - a += (tmp << 4) - tmp; \ - } while (0) -# define MOD28(a) \ - do { \ - CHOP(a); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD(a) \ - do { \ - CHOP(a); \ - MOD28(a); \ - } while (0) -# define MOD63(a) \ - do { /* this assumes a is not negative */ \ - z_off64_t tmp = a >> 32; \ - a &= 0xffffffffL; \ - a += (tmp << 8) - (tmp << 5) + tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD28(a) a %= BASE -# define MOD63(a) a %= BASE -#endif + /* ========================================================================= */ extern uLong zcapcmd_adler32(); @@ -68,16 +20,15 @@ const Bytef *buf; uInt len; { -#define MAX (5*1024) int ret = 0; /* We have to send the buffers value back and forth */ /* Send packets of 5kb size at most. */ - while(len > MAX) { - ret += zcapcmd_adler32(file, buf, MAX); - buf += MAX; - len -= MAX; + while(len > MAXLEN) { + ret += zcapcmd_adler32(adler, buf, MAXLEN); + buf += MAXLEN; + len -= MAXLEN; } - ret += zcapcmd_adler32(file, buf, len); + ret += zcapcmd_adler32(adler, buf, len); return ret; } Modified: soc2013/dpl/head/lib/libzcap/capsicum.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.c Fri Aug 16 18:47:18 2013 (r256035) +++ soc2013/dpl/head/lib/libzcap/capsicum.c Fri Aug 16 19:34:22 2013 (r256036) @@ -12,7 +12,7 @@ #define SUM 0 -pid_t pid = 0; +pid_t pid = 0; int sv[2]; int startChild(void); @@ -20,16 +20,17 @@ nvlist_t * sendCommand(nvlist_t *nvl); int -startChild() +startChild(void) { if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 ) perror("socketpair"); if( (pid = fork()) == 0 ){ close(STDIN_FILENO); - close(STDOUT_FILENO); + cap_rights_limit(STDOUT_FILENO, CAP_READ); + cap_rights_limit(STDERR_FILENO, CAP_WRITE); - dup(sv[1]); /* stdin is now the socket */ + dup(sv[1]); /* 3 is now the socket */ close(sv[0]); close(sv[1]); @@ -55,7 +56,6 @@ perror("nvlist_send()"); return NULL; } - nvlist_destroy(nvl); /* recv results */ @@ -63,10 +63,11 @@ perror("nvlist_send()"); return NULL; } + printf("done sending/recving\n"); return (nvl); } -void killChild(){ +void killChild(void){ kill(pid, SIGKILL); } \ No newline at end of file Modified: soc2013/dpl/head/lib/libzcap/capsicum.h ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.h Fri Aug 16 18:47:18 2013 (r256035) +++ soc2013/dpl/head/lib/libzcap/capsicum.h Fri Aug 16 19:34:22 2013 (r256036) @@ -1,15 +1,22 @@ /* * With Capsicum, we get a compartmentalized, and securer lib. */ -#if __FreeBSD_version >= 900041 -# define CAPSICUM -# include -# include -# include -# include -# include -# include -# include -# include -# include "commands.h" -#endif +#define CAPSICUM +#include +#include +#include +#include +#include +#include +#include +#include +#include "commands.h" + +#define MAXLEN (5*1024) + +extern int pid; +extern int sv[2]; + +extern int startChild(void); +extern void killChild(void); +extern nvlist_t * sendCommand(nvlist_t *nvl); Modified: soc2013/dpl/head/lib/libzcap/commands.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/commands.c Fri Aug 16 18:47:18 2013 (r256035) +++ soc2013/dpl/head/lib/libzcap/commands.c Fri Aug 16 19:34:22 2013 (r256036) @@ -3,50 +3,54 @@ */ #include "zlib.h" -#include "capsicum.c" #include "commands.h" +#include "capsicum.h" #include +void checkChild(void); +void destroy(void); + /* Basic functions */ int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, - int memLevel, int strategy, const char * version, - int stream_size); + int memLevel, int strategy, const char * version, + int stream_size); int zcapcmd_deflate(z_streamp strm, int flush); int zcapcmd_deflateEnd(z_streamp strm); -int zcapcmd_inflateInit(z_streamp strm); +int zcapcmd_inflateInit(z_streamp strm, int windowBits, const char *version, + int stream_size); int zcapcmd_inflate(z_streamp strm, int flush); int zcapcmd_inflateEnd(z_streamp strm); /* Advanced functions */ int zcapcmd_deflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); + uInt dictLength); int zcapcmd_deflateCopy(z_streamp dest, z_streamp source); int zcapcmd_deflateReset(z_streamp strm); int zcapcmd_deflateParams(z_streamp strm, int level, int strategy); int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, - int nice_length, int max_chain); + int nice_length, int max_chain); int zcapcmd_deflateBound(z_streamp strm, uLong sourceLen); int zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits); int zcapcmd_deflatePrime(z_streamp strm, int bits, int value); int zcapcmd_deflateSetHeader(z_streamp strm, gz_headerp head); int zcapcmd_inflateSetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); + uInt dictLength); int zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary, - uInt dictLength); + uInt *dictLength); int zcapcmd_inflateSync(z_streamp strm); int zcapcmd_inflateCopy(z_streamp strm, z_streamp source); int zcapcmd_inflateReset(z_streamp strm); int zcapcmd_inflateReset2(z_streamp strm, int windowBits); int zcapcmd_inflatePrime(z_streamp strm, int bits, int value); -int zcapcmd_inflateMark(z_streamp strm); +long zcapcmd_inflateMark(z_streamp strm); int zcapcmd_inflateGetHeader(z_streamp strm, gz_headerp head); int zcapcmd_inflateBackInit(z_streamp strm, int windowBits, - unsigned char *window); + unsigned char *window); int zcapcmd_inflateBack(z_streamp strm, in_func in, void *in_desc, - out_func out, void *out_desc); + out_func out, void *out_desc); int zcapcmd_inflateBackEnd(z_streamp strm); uLong zcapcmd_zlibCompileFlags(void); @@ -59,7 +63,7 @@ int zcapcmd_gzsetparams(gzFile file, int level, int strategy); int zcapcmd_gzread(gzFile file, voidp buf, unsigned len); int zcapcmd_gzwrite(gzFile file, voidp buf, unsigned len); -int zcapcmd_gzprintf(gzFile file, const char *format, ...); +int zcapcmd_gzprintf(gzFile file, const char *str); int zcapcmd_gzputs(gzFile file, const char *s); char *zcapcmd_gzgets(gzFile file, char *buf, int len); int zcapcmd_gzputc(gzFile file, int c); @@ -75,6 +79,7 @@ uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len); uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2); + extern pid_t pid; extern nvlist_t *sendCommand(nvlist_t *); extern void * data; @@ -82,9 +87,11 @@ nvlist_t *nvl, *args, *result; size_t gzfilesize = sizeof(struct gzFile_s); size_t gzheadersize = sizeof(struct gz_header_s); -size_t zstreamsize = sizeof(z_stream); +size_t z_streamsize = sizeof(z_stream); + -void checkChild(void) { +void +checkChild(void) { if (pid == 0) startChild(); } @@ -98,10 +105,9 @@ int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits, - int memLevel, int strategy, const char * version, int stream_size) + int memLevel, int strategy, const char * version, int stream_size) { uLong ret; - zstream * dataplace; checkChild(); @@ -112,7 +118,7 @@ } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); /* No worries here */ - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "level", level); nvlist_add_number(args, "method", method); nvlist_add_number(args, "windowBits", windowBits); @@ -131,8 +137,8 @@ buffers, and sync: next_in, avail_in, total_in, next_out, avail_out, total_out. */ /* Supposing there's already space reserved for z_stream */ - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); char *msg = nvlist_take_string(result, "msg"); memcpy(strm->msg, msg, strlen(msg)+1); destroy(); @@ -140,10 +146,36 @@ } int +zcapcmd_deflate(z_streamp strm, int flush) +{ + uLong ret; + + checkChild(); + + if( (args = nvlist_create(0)) == NULL || + (nvl = nvlist_create(0)) == NULL ) { + perror("nvlist_create"); + return(0); + } + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); + nvlist_add_nvlist(nvl, "args", args); + + result = sendCommand(nvl); + + ret = nvlist_take_number(result, "result"); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + /* Supposing there's already space reserved for z_stream */ + memcpy(strm, newstrm, z_streamsize); + destroy(); + return(ret); +} + + +int zcapcmd_deflateEnd(z_streamp strm) { uLong ret; - zstream * dataplace; checkChild(); @@ -153,15 +185,15 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); /* Supposing there's already space reserved for z_stream */ - memcpy(strm, newstrm, zstreamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -171,7 +203,6 @@ const char *version, int stream_size) { uLong ret; - zstream * dataplace; checkChild(); @@ -182,7 +213,7 @@ } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); /* No worries here */ - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "windowBits", windowBits); nvlist_add_string(args, "version", version); nvlist_add_number(args, "stream_size", stream_size); @@ -191,8 +222,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); char *msg = nvlist_take_string(result, "msg"); memcpy(strm->msg, msg, strlen(msg)+1); destroy(); @@ -200,10 +231,9 @@ } int -zcapcmd_inflateEnd(z_streamp strm) +zcapcmd_inflate(z_streamp strm, int flush) { uLong ret; - zstream * dataplace; checkChild(); @@ -213,26 +243,23 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + /* Supposing there's already space reserved for z_stream */ + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } -/* Advanced functions */ int -zcapcmd_deflateSetDictionary(z_streamp strm, - const Bytef *dictionary, uInt dictLength) +zcapcmd_inflateEnd(z_streamp strm) { - /* XXX */ uLong ret; - zstream * dataplace; checkChild(); @@ -241,28 +268,26 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "dictionary", *dictionary, dictLength); - nvlist_add_number(args, "dictLength", dictLength); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - if (ret == Z_OK) - dataplace = malloc(zstreamsize); - z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } +/* Advanced functions */ int -zcapcmd_deflateGetDictionary(z_streamp strm, - const Bytef *dictionary, uInt *dictLength) +zcapcmd_deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, uInt dictLength) { /* XXX */ uLong ret; - zstream * dataplace; checkChild(); @@ -271,7 +296,7 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETDICTIONARY); nvlist_add_binary(args, "dictionary", *dictionary, dictLength); nvlist_add_number(args, "dictLength", dictLength); nvlist_add_nvlist(nvl, "args", args); @@ -279,9 +304,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - if (ret == Z_OK) - dataplace = malloc(zstreamsize); - z_stream strm = nvlist_take_binary(result, "newstrm", zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -290,7 +314,6 @@ zcapcmd_deflateCopy(z_streamp dest, z_streamp source) { uLong ret; - zstream * dataplace; checkChild(); @@ -300,16 +323,16 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "dest", *dest, zstreamsize); - nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_binary(args, "dest", (void *)dest, z_streamsize); + nvlist_add_binary(args, "source", (void *)source, z_streamsize); nvlist_add_nvlist(nvl, "args", args); /* The two z_streamp are now copied at the worker. */ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(dest, newstrm, z_streamsize); destroy(); return(ret); } @@ -318,7 +341,6 @@ zcapcmd_deflateReset(z_streamp strm) { uLong ret; - zstream * dataplace; checkChild(); @@ -327,16 +349,16 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATERESET); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); /* Save the reseted strm. */ - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); char *msg = nvlist_take_string(result, "msg"); memcpy(strm->msg, msg, strlen(msg)+1); destroy(); @@ -344,10 +366,9 @@ } int -zcapcmd_deflateParams(z_streamp strm, int level, int int strategy) +zcapcmd_deflateParams(z_streamp strm, int level, int strategy) { uLong ret; - zstream * dataplace; checkChild(); @@ -356,8 +377,8 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPARAMS); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "level", level); nvlist_add_number(args, "strategy", strategy); nvlist_add_nvlist(nvl, "args", args); @@ -366,18 +387,17 @@ ret = nvlist_take_number(result, "result"); /* Overwrite the old streamp */ - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } int zcapcmd_deflateTune(z_streamp strm, int good_length, int max_lazy, - int nice_length, int max_chain) + int nice_length, int max_chain) { uLong ret; - zstream * dataplace; checkChild(); @@ -386,8 +406,8 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATETUNE); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "good_length", good_length); nvlist_add_number(args, "max_lazy", max_lazy); nvlist_add_number(args, "nice_length", nice_length); @@ -397,8 +417,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -407,7 +427,6 @@ zcapcmd_deflateBound(z_streamp strm, uLong sourceLen) { uLong ret; - zstream * dataplace; checkChild(); @@ -416,16 +435,16 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEBOUND); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "sourceLen", sourceLen); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -434,7 +453,6 @@ zcapcmd_deflatePending(z_streamp strm, unsigned *pending, int *bits) { uLong ret; - zstream * dataplace; checkChild(); @@ -443,8 +461,8 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPENDING); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); /* Will get malloc()ed at the worker. */ nvlist_add_number(args, "pending", *pending); nvlist_add_number(args, "bits", *bits); @@ -453,8 +471,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -463,7 +481,6 @@ zcapcmd_deflatePrime(z_streamp strm, int bits, int value) { uLong ret; - zstream * dataplace; checkChild(); @@ -473,7 +490,7 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "bits", bits); nvlist_add_number(args, "value", value); nvlist_add_nvlist(nvl, "args", args); @@ -481,8 +498,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -493,7 +510,6 @@ /* XXX: Beware of gz_headerp extra */ /* What happens with header->extra??? */ uLong ret; - zstream * dataplace; checkChild(); @@ -503,8 +519,8 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); - nvlist_add_binary(args, "head", *head, gzheadersize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); + nvlist_add_binary(args, "head", (void*)head, gzheadersize); nvlist_add_string(nvl, "name", head->name); nvlist_add_string(nvl, "comment", head->comment); nvlist_add_nvlist(nvl, "args", args); @@ -512,18 +528,17 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } int zcapcmd_inflateSetDictionary(z_streamp strm, - const Bytef *dictionary, uInt dictLength) + const Bytef *dictionary, uInt dictLength) { uLong ret; - zstream * dataplace; checkChild(); @@ -533,23 +548,23 @@ return(0); } nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } int -zcapcmd_inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength) +zcapcmd_inflateGetDictionary(z_streamp strm, const Bytef *dictionary, + uInt *dictLength) { uLong ret; - zstream * dataplace; checkChild(); @@ -558,15 +573,15 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETDICTIONARY); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -575,7 +590,6 @@ zcapcmd_inflateSync(z_streamp strm) { uLong ret; - zstream * dataplace; checkChild(); @@ -584,15 +598,15 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESYNC); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); destroy(); return(ret); } @@ -601,7 +615,6 @@ zcapcmd_inflateCopy(z_streamp dest, z_streamp source) { uLong ret; - zstream * dataplace; checkChild(); @@ -610,17 +623,17 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY); - nvlist_add_binary(args, "dest", *dest, zstreamsize); - nvlist_add_binary(args, "source", *source, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATECOPY); + nvlist_add_binary(args, "dest", (void *)dest, z_streamsize); + nvlist_add_binary(args, "source", (void *)source, z_streamsize); nvlist_add_nvlist(nvl, "args", args); /* The two z_streamp are now copied at the worker. */ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(dest, newstrm, z_streamsize); destroy(); return(ret); } @@ -629,7 +642,6 @@ zcapcmd_inflateReset(z_streamp strm) { uLong ret; - zstream * dataplace; checkChild(); @@ -638,15 +650,15 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); char *msg = nvlist_take_string(result, "msg"); memcpy(strm->msg, msg, strlen(msg)+1); destroy(); @@ -657,7 +669,6 @@ zcapcmd_inflateReset2(z_streamp strm, int windowBits) { uLong ret; - zstream * dataplace; checkChild(); @@ -666,16 +677,16 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET2); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(nvl, "windowBits", windowBits); nvlist_add_nvlist(nvl, "args", args); result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); - memcpy(strm, newstrm, zstreamsize); + z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize); + memcpy(strm, newstrm, z_streamsize); char *msg = nvlist_take_string(result, "msg"); memcpy(strm->msg, msg, strlen(msg)+1); destroy(); @@ -686,7 +697,6 @@ zcapcmd_inflatePrime(z_streamp strm, int bits, int value) { uLong ret; - zstream * dataplace; checkChild(); @@ -695,8 +705,8 @@ perror("nvlist_create"); return(0); } - nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETHEADER); - nvlist_add_binary(args, "strm", *strm, zstreamsize); + nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEPRIME); + nvlist_add_binary(args, "strm", (void *)strm, z_streamsize); nvlist_add_number(args, "bits", bits); nvlist_add_number(args, "value", value); nvlist_add_nvlist(nvl, "args", args); @@ -704,8 +714,8 @@ result = sendCommand(nvl); ret = nvlist_take_number(result, "result"); - z_stream *newstrm = nvlist_take_binary(result, "newstrm", zstreamsize); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***