Snap for 6188643 from 8fcb4fb5c580bfd9121dd8ddb93d4eb907d23f9e to rvc-release

Change-Id: I704989675c41022f65ca03c4777580d3cc38062b
diff --git a/Android.bp b/Android.bp
index dfc81e3..5544456 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,12 +15,14 @@
         "src/device.c",
         "src/local.c",
         "src/scan.c",
+        "src/sort.c",
         "src/utilities.c",
     ],
 
     cflags: [
         "-Wall",
         "-Werror",
+        "-Wno-sign-compare",
         "-Wno-unused-parameter",
     ],
 }
diff --git a/METADATA b/METADATA
index fc935fe..2299ea5 100644
--- a/METADATA
+++ b/METADATA
@@ -11,7 +11,7 @@
     type: GIT
     value: "https://github.com/analogdevicesinc/libiio"
   }
-  version: "6ecff5d46e1b12c2859f0b63a73282940e3402bb"
-  last_upgrade_date { year: 2018 month: 5 day: 7 }
+  version: "4e22517c60f3c5e691320871956edede15459ae3"
+  last_upgrade_date { year: 2020 month: 2 day: 3 }
   license_type: RESTRICTED
 }
diff --git a/src/CI/travis/after_deploy b/src/CI/travis/after_deploy
new file mode 100755
index 0000000..66705aa
--- /dev/null
+++ b/src/CI/travis/after_deploy
@@ -0,0 +1,7 @@
+#!/bin/sh -e
+
+. CI/travis/lib.sh
+
+should_trigger_next_builds "$TRAVIS_BRANCH" || exit 0
+
+trigger_adi_build "libad9361-iio" "$TRAVIS_BRANCH"
diff --git a/src/CI/travis/before_deploy b/src/CI/travis/before_deploy
index 1164dcf..9d3fd05 100755
--- a/src/CI/travis/before_deploy
+++ b/src/CI/travis/before_deploy
@@ -1,4 +1,6 @@
-#!/bin/sh
+#!/bin/sh -e
+
+. CI/travis/lib.sh
 
 # Don't prepare a deploy on a Coverity build
 if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
@@ -18,8 +20,11 @@
 fi
 pwd
 
+if [ -z "${LDIST}" -a -f "build/.LDIST" ] ; then
+	export LDIST="-$(cat build/.LDIST)"
+fi
 if [ -z "${LDIST}" ] ; then
-	LDIST=-$(lsb_release -c | awk '{print $NF}')
+	export LDIST="-$(get_ldist)"
 fi
 
 check_file()
@@ -27,7 +32,7 @@
 temp=""
 for i in $(find ./ -name CMakeCache.txt)
 do
-hit=$(find $(dirname ${i}) -maxdepth 1 -name "libiio*.$1" | grep -v -- ${LDIST})
+hit=$(find $(dirname ${i}) -maxdepth 1 -name "libiio*.$1" -a ! -name "*${LDIST}*")
 if [ "$(echo ${hit} | wc -w)" -gt "1"  ] ; then
 	echo "I am confused - more than 2 $1 files!"
 	echo $hit
@@ -52,7 +57,7 @@
 	deploy=$(expr ${deploy} + 1)
 	if [ -z "${TARGET_DEB}" ] ; then
 		export TARGET_DEB=$(echo ${temp} | \
-			sed -e 's:^./.*/::' -e 's:.deb$::')${LDIST}.deb
+			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.deb$::')${LDIST}.deb
 	fi
 	echo "deploying ${temp} to nightly $TARGET_DEB"
 	if [ -z "${RELEASE_PKG_FILE_DEB}" ] ; then
@@ -72,7 +77,7 @@
 	deploy=$(expr ${deploy} + 1)
 	if [ -z "${TARGET_RPM}" ] ; then
 		export TARGET_RPM=$(echo ${temp} | \
-			sed -e 's:^./.*/::' -e 's:.rpm$::')${LDIST}.rpm
+			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:.rpm$::')${LDIST}.rpm
 	fi
 	echo "deploying ${temp} to nightly $TARGET_RPM"
 	if [ -z "${RELEASE_PKG_FILE_RPM}" ] ; then
@@ -137,7 +142,7 @@
 		)
 
 		export TARGET_TGZ=$(echo ${temp} | \
-			sed -e 's:^./.*/::' -e 's:.tar.gz$::')${LDIST}.tar.gz;
+			sed -e 's:^./.*/::' -e 's:-Linux::' -e 's:-Darwin::' -e 's:.tar.gz$::')${LDIST}.tar.gz;
 	fi
 	echo "deploying ${temp} to $TARGET_TGZ"
 	if [ -z "${RELEASE_PKG_FILE_TGZ}" ] ; then
diff --git a/src/CI/travis/before_install_darwin b/src/CI/travis/before_install_darwin
index 68da765..f8645b3 100755
--- a/src/CI/travis/before_install_darwin
+++ b/src/CI/travis/before_install_darwin
@@ -1,11 +1,5 @@
-#!/bin/sh
+#!/bin/sh -e
 
-brew update
-if ! brew ls --version cmake &>/dev/null; then
-	brew install cmake
-else
-	brew upgrade cmake
-fi
-brew install doxygen
-brew install --build-from-source libusb
-brew install libxml2
+. CI/travis/lib.sh
+
+brew_install_or_upgrade cmake doxygen libusb libxml2
diff --git a/src/CI/travis/before_install_linux b/src/CI/travis/before_install_linux
index 76ee7db..b25a781 100755
--- a/src/CI/travis/before_install_linux
+++ b/src/CI/travis/before_install_linux
@@ -1,8 +1,34 @@
-#!/bin/sh
+#!/bin/sh -e
 
-sudo apt-get -qq update
-sudo apt-get install -y cmake doxygen libaio-dev libavahi-client-dev libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar bzip2 gzip
-if [ `sudo apt-cache search libserialport-dev | wc -l` -gt 0 ] ; then
-	sudo apt-get install -y libserialport-dev
-fi
+. CI/travis/lib.sh
 
+handle_centos() {
+	# FIXME: see about adding `libserialport-dev` from EPEL ; maybe libusb-1.0.0-devel...
+	yum -y groupinstall 'Development Tools'
+	yum -y install cmake libxml2-devel libusb1-devel doxygen libaio-devel \
+		avahi-devel bzip2 gzip rpm rpm-build
+}
+
+handle_centos_docker() {
+	prepare_docker_image "centos:centos${OS_VERSION}"
+}
+
+handle_ubuntu_docker() {
+	prepare_docker_image "ubuntu:${OS_VERSION}"
+}
+
+handle_default() {
+	sudo apt-get -qq update
+	sudo apt-get install -y cmake graphviz libaio-dev libavahi-client-dev libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar bzip2 gzip flex bison git
+	if [ -n "${GH_DOC_TOKEN}" ] ; then
+		sudo apt-get install -y doxygen
+	fi
+	if [ `sudo apt-cache search libserialport-dev | wc -l` -gt 0 ] ; then
+		sudo apt-get install -y libserialport-dev
+	fi
+}
+
+OS_TYPE=${1:-default}
+OS_VERSION=${2}
+
+handle_${OS_TYPE}
diff --git a/src/CI/travis/deploy b/src/CI/travis/deploy
index 18941f7..63a3f60 100755
--- a/src/CI/travis/deploy
+++ b/src/CI/travis/deploy
@@ -1,70 +1,10 @@
-#!/bin/sh
+#!/bin/sh -e
 
-cd $TRAVIS_BUILD_DIR
+. CI/travis/lib.sh
 
-send()
-{
-if [ "$#" -ne 3 ] ; then
-	echo "skipping deployment of something"
-        echo "send called with $@"
-	return
-fi
-
-if [ "x$1" = "x" ] ; then
-	echo no file to send
-	return
-fi
-
-if [ ! -r "$1" ] ; then
-	echo "file $1 is not readable"
-	ls -l $1
-	return
-fi
-
-if [ $BRANCH_PULL ] ; then
-	branch=$BRANCH_PULL
-else
-	branch=$BRANCH
-fi
-
-FROM=$1
-TO=${branch}_$2
-LATE=${branch}_latest_libiio${LDIST}$3
-GLOB=${DEPLOY_TO}/${branch}_libiio-*
-
-echo attemting to deploy $FROM to $TO
-echo and ${branch}_libiio${LDIST}$3
-ssh -V
-
-echo "cd ${DEPLOY_TO}" > script$3
-if curl -m 10 -s -I -f -o /dev/null http://swdownloads.analog.com/cse/travis_builds/${TO} ; then
-	echo "rm ${TO}" >> script$3
-fi
-echo "put ${FROM} ${TO}" >> script$3
-echo "ls -l ${TO}" >> script$3
-if curl -m 10 -s -I -f -o /dev/null http://swdownloads.analog.com/cse/travis_builds/${LATE} ; then
-	echo "rm ${LATE}" >> script$3
-fi
-echo "symlink ${TO} ${LATE}" >> script$3
-echo "ls -l ${LATE}" >> script$3
-echo "bye" >> script$3
-
-sftp ${EXTRA_SSH} -b script$3 ${SSHUSER}@${SSHHOST}
-
-# limit things to a few files, so things don't grow forever
-if [ "${LDIST}" = "-precise" -a "$3" = ".deb" ] ; then
-	for files in $(ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
-		"ls -lt ${GLOB}" | tail -n +100 | awk '{print $NF}')
-	do
-		ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
-			"rm ${DEPLOY_TO}/${files}"
-	done
-fi
-}
-
-#    from                   to             suffix
-send ${RELEASE_PKG_FILE_DEB} ${TARGET_DEB} .deb
-send ${RELEASE_PKG_FILE_RPM} ${TARGET_RPM} .rpm
-send ${RELEASE_PKG_FILE_TGZ} ${TARGET_TGZ} .tar.gz
-send ${RELEASE_PKG_FILE_PKG} ${TARGET_PKG} .pkg
+#                       libname    from                   to             suffix
+upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_DEB} ${TARGET_DEB} .deb
+upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_RPM} ${TARGET_RPM} .rpm
+upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_TGZ} ${TARGET_TGZ} .tar.gz
+upload_file_to_swdownloads libiio ${RELEASE_PKG_FILE_PKG} ${TARGET_PKG} .pkg
 
diff --git a/src/CI/travis/generateDocumentationAndDeploy.sh.in b/src/CI/travis/generateDocumentationAndDeploy.sh.in
new file mode 100644
index 0000000..079913a
--- /dev/null
+++ b/src/CI/travis/generateDocumentationAndDeploy.sh.in
@@ -0,0 +1,97 @@
+#!/bin/sh
+set -x
+################################################################################
+# Title          : generateDocumentationAndDeploy.sh
+# Date created   : 16Nov2018
+# Original Author: "Jeroen de Bruijn"
+# based on https://gist.github.com/vidavidorra/548ffbcdae99d752da02
+#
+# Preconditions:
+# - Packages doxygen graphviz must be installed.
+# - An gh-pages branch should already exist. See below for mor info on how to
+#   create a gh-pages branch.
+#
+# Required global variables:
+# - GH_DOC_TOKEN       : Secure token to the github repository.
+#
+# This script will generate Doxygen documentation and push the documentation to
+# the gh-pages branch of a repository specified by $TRAVIS_REPO_SLUG
+# Before this script is used there should already be a gh-pages branch in the
+# repository.
+#
+# This file is processed by CMAKE to get the version in the commit message
+# 
+################################################################################
+
+##### Setup this script and get the current gh-pages branch.
+echo 'Setting up the script...'
+GH_REPO_NAME=$(echo $TRAVIS_REPO_SLUG | awk -F/ '{print $2}')
+
+# Exit with nonzero exit code if anything fails
+set -e
+
+# by the time this script is run, we should have already made the docs
+cd $TRAVIS_BUILD_DIR/build
+#docs should be in the $TRAVIS_BUILD_DIR/build/html directory
+if [ ! -d "html" ] || [ ! -f "./html/index.html" ]; then
+	echo '' >&2
+	echo 'Warning: No documentation (html) files have been found!' >&2
+	echo 'Warning: Not going to push the documentation to GitHub!' >&2
+	exit 0
+fi
+
+if [ -z "${TRAVIS_TAG}" ] ; then
+	echo 'Warning: Not a tag' >&2
+	echo 'Warning: Not going to push the documentation to GitHub!' >&2
+	exit 0
+fi
+
+# Get the current gh-pages branch
+git clone -b gh-pages https://git@github.com/$TRAVIS_REPO_SLUG
+cd $GH_REPO_NAME
+
+# Remove everything currently in the gh-pages branch.
+# GitHub is smart enough to know which files have changed and which files have
+# stayed the same and will only update the changed files. So the gh-pages branch
+# can be safely cleaned, and it is sure that everything pushed later is the new
+# documentation.
+rm -rf *
+
+#copy the files over
+cp -a ../html/* ./
+
+##### Configure git.
+# Set the push default to simple i.e. push only the current branch.
+git config --global push.default simple
+# Pretend to be an user called Travis CI.
+git config user.name "Autogenerated by Travis CI"
+git config user.email "robin.getz@analog.com"
+
+# Need to create a .nojekyll file to allow filenames starting with an underscore
+# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.
+# Presumably this is only needed when the SHORT_NAMES option in Doxygen is set
+# to NO, which it is by default. So creating the file just in case.
+if [ ! -f ".nojekyll" ] ; then
+	touch .nojekyll
+fi
+
+################################################################################
+##### Upload the documentation to the gh-pages branch of the repository.   #####
+
+echo 'Uploading documentation to the gh-pages branch...'
+# Add everything in this directory (the Doxygen code documentation) to the
+# gh-pages branch.
+#
+# GitHub is smart enough to know which files have changed and which files have
+# stayed the same and will only update the changed files.
+git add --all
+
+# Commit the added files with a title and description containing the Travis CI
+# build number and the GitHub commit reference that issued this build.
+git commit -m "Deploy autogenerated docs for ${GH_REPO_NAME} v@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@-g@LIBIIO_VERSION_GIT@" --sign
+
+# Force push to the remote gh-pages branch.
+# The ouput is redirected to /dev/null to hide any sensitive credential data
+# that might otherwise be exposed.
+git push --force "https://${GH_DOC_TOKEN}@github.com/${TRAVIS_REPO_SLUG}" > /dev/null 2>&1
+
diff --git a/src/CI/travis/inside_docker.sh b/src/CI/travis/inside_docker.sh
new file mode 100755
index 0000000..7aa9522
--- /dev/null
+++ b/src/CI/travis/inside_docker.sh
@@ -0,0 +1,26 @@
+#!/bin/sh -e
+
+LIBNAME="$1"
+OS_TYPE="$2"
+
+export INSIDE_DOCKER="1"
+export TRAVIS_BUILD_DIR="/$LIBNAME"
+
+cd /$LIBNAME
+
+if [ -d "/$LIBNAME/CI" ] ; then
+	CI="/$LIBNAME/CI"
+elif [ -d "/$LIBNAME/ci" ] ; then
+	CI="/$LIBNAME/ci"
+else
+	echo "No CI/ci directory present"
+	exit 1
+fi
+
+$CI/travis/before_install_linux "$OS_TYPE"
+
+$CI/travis/make_linux "$OS_TYPE"
+
+# need to find this out inside the container
+. $CI/travis/lib.sh
+echo "$(get_ldist)" > /${LIBNAME}/build/.LDIST
diff --git a/src/CI/travis/jobs_running_cnt.py b/src/CI/travis/jobs_running_cnt.py
new file mode 100644
index 0000000..e5f4121
--- /dev/null
+++ b/src/CI/travis/jobs_running_cnt.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+import os
+import sys
+import urllib2
+import json
+
+# This is pretty constant, but allow it to be overriden via env-var
+url = os.getenv('TRAVIS_API_URL', 'https://api.travis-ci.org')
+
+if (not url.lower().startswith("https://")):
+    print (0)
+    sys.exit(0)
+
+ci_token = os.getenv('TRAVIS_API_TOKEN')
+build_id = os.getenv('TRAVIS_BUILD_ID')
+
+headers = {
+    'Content-Type': 'application/json',
+    'Accept': 'application/json',
+    'Travis-API-Version': "3",
+    'Authorization': "token {0}".format(ci_token)
+}
+
+# Codacy's bandit linter may complain that we haven't validated
+# this URL for permitted schemes; we have validated this a few lines above
+req = urllib2.Request("{0}/build/{1}/jobs".format(url, build_id),
+		      headers=headers)
+
+response = urllib2.urlopen(req).read()
+json_r = json.loads(response.decode('utf-8'))
+
+jobs_running = 0
+for job in json_r['jobs']:
+    # bump number of jobs higher, so nothing triggers
+    if (job['state'] in [ 'canceled', 'failed' ]):
+        jobs_running += 99
+        break
+    if (job['state'] in [ 'started', 'created', 'queued', 'received' ]):
+        jobs_running += 1
+
+print (jobs_running)
diff --git a/src/CI/travis/lib.sh b/src/CI/travis/lib.sh
new file mode 100644
index 0000000..a071cfc
--- /dev/null
+++ b/src/CI/travis/lib.sh
@@ -0,0 +1,304 @@
+#!/bin/sh -e
+
+export TRAVIS_API_URL="https://api.travis-ci.org"
+LOCAL_BUILD_DIR=${LOCAL_BUILD_DIR:-build}
+
+COMMON_SCRIPTS="jobs_running_cnt.py inside_docker.sh"
+
+echo_red()   { printf "\033[1;31m$*\033[m\n"; }
+echo_green() { printf "\033[1;32m$*\033[m\n"; }
+echo_blue()  { printf "\033[1;34m$*\033[m\n"; }
+
+get_script_path() {
+	local script="$1"
+
+	[ -n "$script" ] || return 1
+
+	if [ -f "CI/travis/$script" ] ; then
+		echo "CI/travis/$script"
+	elif [ -f "ci/travis/$script" ] ; then
+		echo "ci/travis/$script"
+	elif [ -f "${LOCAL_BUILD_DIR}/$script" ] ; then
+		echo "${LOCAL_BUILD_DIR}/$script"
+	else
+		return 1
+	fi
+}
+
+pipeline_branch() {
+	local branch=$1
+
+	[ -n "$branch" ] || return 1
+
+	# master is a always a pipeline branch
+	[ "$branch" = "master" ] && return 0
+
+	set +x
+	# Check if branch name is 20XX_RY where:
+	#   XX - 14 to 99 /* wooh, that's a lot of years */
+	#   Y  - 1 to 9   /* wooh, that's a lot of releases per year */
+	for year in $(seq 2014 2099) ; do
+		for rel_num in $(seq 1 9) ; do
+			[ "$branch" = "${year}_R${rel_num}" ] && \
+				return 0
+		done
+	done
+
+	return 1
+}
+
+should_trigger_next_builds() {
+	local branch="$1"
+
+	[ -z "${COVERITY_SCAN_PROJECT_NAME}" ] || return 1
+
+	# These Travis-CI vars have to be non-empty
+	[ -n "$TRAVIS_PULL_REQUEST" ] || return 1
+	[ -n "$branch" ] || return 1
+	set +x
+	[ -n "$TRAVIS_API_TOKEN" ] || return 1
+
+	# Has to be a non-pull-request
+	[ "$TRAVIS_PULL_REQUEST" = "false" ] || return 1
+
+	pipeline_branch "$branch" || return 1
+
+	local python_script="$(get_script_path jobs_running_cnt.py)"
+	if [ -z "$python_script" ] ; then
+		echo "Could not find 'jobs_running_cnt.py'"
+		return 1
+	fi
+
+	local jobs_cnt=$(python $python_script)
+
+	# Trigger next job if we are the last job running
+	[ "$jobs_cnt" = "1" ]
+}
+
+trigger_build() {
+	local repo_slug="$1"
+	local branch="$2"
+
+	[ -n "$repo_slug" ] || return 1
+	[ -n "$branch" ] || return 1
+
+	local body="{
+		\"request\": {
+			\"branch\":\"$branch\"
+		}
+	}"
+
+	# Turn off tracing here (shortly)
+	set +x
+	curl -s -X POST \
+		-H "Content-Type: application/json" \
+		-H "Accept: application/json" \
+		-H "Travis-API-Version: 3" \
+		-H "Authorization: token $TRAVIS_API_TOKEN" \
+		-d "$body" \
+		https://api.travis-ci.org/repo/$repo_slug/requests
+}
+
+trigger_adi_build() {
+	local adi_repo="$1"
+	local branch="$2"
+
+	[ -n "$adi_repo" ] || return 1
+	trigger_build "analogdevicesinc%2F$adi_repo" "$branch"
+}
+
+command_exists() {
+	local cmd=$1
+	[ -n "$cmd" ] || return 1
+	type "$cmd" >/dev/null 2>&1
+}
+
+get_ldist() {
+	case "$(uname)" in
+	Linux*)
+		if [ ! -f /etc/os-release ] ; then
+			if [ -f /etc/centos-release ] ; then
+				echo "centos-$(sed -e 's/CentOS release //' -e 's/(.*)$//' \
+					-e 's/ //g' /etc/centos-release)-$(uname -m)"
+				return 0
+			fi
+			ls /etc/*elease
+			[ -z "${OSTYPE}" ] || {
+				echo "${OSTYPE}-unknown"
+				return 0
+			}
+			echo "linux-unknown"
+			return 0
+		fi
+		. /etc/os-release
+		if ! command_exists dpkg ; then
+			echo $ID-$VERSION_ID-$(uname -m)
+		else
+			echo $ID-$VERSION_ID-$(dpkg --print-architecture)
+		fi
+		;;
+	Darwin*)
+		echo "darwin-$(sw_vers -productVersion)"
+		;;
+	*)
+		echo "$(uname)-unknown"
+		;;
+	esac
+	return 0
+}
+
+__brew_install_or_upgrade() {
+	brew install $1 || \
+		brew upgrade $1 || \
+		brew ls --version $1
+}
+
+brew_install_or_upgrade() {
+	while [ -n "$1" ] ; do
+		__brew_install_or_upgrade "$1" || return 1
+		shift
+	done
+}
+
+sftp_cmd_pipe() {
+	sftp ${EXTRA_SSH} ${SSHUSER}@${SSHHOST}
+}
+
+sftp_rm_artifact() {
+	local artifact="$1"
+	sftp_cmd_pipe <<-EOF
+		cd ${DEPLOY_TO}
+		rm ${artifact}
+	EOF
+}
+
+sftp_upload() {
+	local FROM="$1"
+	local TO="$2"
+	local LATE="$3"
+
+	sftp_cmd_pipe <<-EOF
+		cd ${DEPLOY_TO}
+
+		put ${FROM} ${TO}
+		ls -l ${TO}
+
+		symlink ${TO} ${LATE}
+		ls -l ${LATE}
+		bye
+	EOF
+}
+
+upload_file_to_swdownloads() {
+
+	if [ "$#" -ne 4 ] ; then
+		echo "skipping deployment of something"
+		echo "send called with $@"
+		return 0
+	fi
+
+	local LIBNAME=$1
+	local FROM=$2
+	local FNAME=$3
+	local EXT=$4
+
+	if [ -z "$FROM" ] ; then
+		echo no file to send
+		return 1
+	fi
+
+	if [ ! -r "$FROM" ] ; then
+		echo "file $FROM is not readable"
+		return 1
+	fi
+
+	if [ -n "$TRAVIS_PULL_REQUEST_BRANCH" ] ; then
+		local branch="$TRAVIS_PULL_REQUEST_BRANCH"
+	else
+		local branch="$TRAVIS_BRANCH"
+	fi
+
+	local TO=${branch}_${FNAME}
+	local LATE=${branch}_latest_${LIBNAME}${LDIST}${EXT}
+	local GLOB=${DEPLOY_TO}/${branch}_${LIBNAME}-*
+
+	echo attemting to deploy $FROM to $TO
+	echo and ${branch}_${LIBNAME}${LDIST}${EXT}
+	ssh -V
+
+	for rmf in ${TO} ${LATE} ; do
+		sftp_rm_artifact ${rmf} || \
+			echo_blue "Could not delete ${rmf}"
+	done
+
+	sftp_upload "${FROM}" "${TO}" "${LATE}" || {
+		echo_red "Failed to upload artifact from '${FROM}', to '${TO}', symlink '${LATE}'"
+		return 1
+	}
+
+	# limit things to a few files, so things don't grow forever
+	if [ "${EXT}" = ".deb" ] ; then
+		for files in $(ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
+			"ls -lt ${GLOB}" | tail -n +100 | awk '{print $NF}')
+		do
+			ssh ${EXTRA_SSH} ${SSHUSER}@${SSHHOST} \
+				"rm ${DEPLOY_TO}/${files}" || \
+				return 1
+		done
+	fi
+
+	return 0
+}
+
+prepare_docker_image() {
+	local DOCKER_IMAGE="$1"
+	sudo apt-get -qq update
+	echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s devicemapper"' | sudo tee /etc/default/docker > /dev/null
+	sudo service docker restart
+	sudo docker pull "$DOCKER_IMAGE"
+}
+
+run_docker_script() {
+	local DOCKER_SCRIPT="$(get_script_path $1)"
+	local DOCKER_IMAGE="$2"
+	local OS_TYPE="$3"
+	local MOUNTPOINT="${4:-docker_build_dir}"
+	sudo docker run --rm=true \
+		-v "$(pwd):/${MOUNTPOINT}:rw" \
+		$DOCKER_IMAGE \
+		/bin/bash -e "/${MOUNTPOINT}/${DOCKER_SCRIPT}" "${MOUNTPOINT}" "${OS_TYPE}"
+}
+
+ensure_command_exists() {
+	local cmd="$1"
+	local package="$2"
+	[ -n "$cmd" ] || return 1
+	[ -n "$package" ] || package="$cmd"
+	! command_exists "$cmd" || return 0
+	# go through known package managers
+	for pacman in apt-get brew yum ; do
+		command_exists $pacman || continue
+		$pacman install -y $package || {
+			# Try an update if install doesn't work the first time
+			$pacman -y update && \
+				$pacman install -y $package
+		}
+		return $?
+	done
+	return 1
+}
+
+ensure_command_exists sudo
+
+# Other scripts will download lib.sh [this script] and lib.sh will
+# in turn download the other scripts it needs.
+# This gives way more flexibility when changing things, as they propagate
+for script in $COMMON_SCRIPTS ; do
+	[ ! -f "CI/travis/$script" ] || continue
+	[ ! -f "ci/travis/$script" ] || continue
+	[ ! -f "${LOCAL_BUILD_DIR}/$script" ] || continue
+	mkdir -p ${LOCAL_BUILD_DIR}
+	ensure_command_exists wget
+	wget https://raw.githubusercontent.com/analogdevicesinc/libiio/master/CI/travis/$script \
+		-O $LOCAL_BUILD_DIR/$script
+done
diff --git a/src/CI/travis/make_darwin b/src/CI/travis/make_darwin
index 4fe4e44..aff1af9 100755
--- a/src/CI/travis/make_darwin
+++ b/src/CI/travis/make_darwin
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 
 if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
 
diff --git a/src/CI/travis/make_linux b/src/CI/travis/make_linux
index 688fabd..0e1e5c9 100755
--- a/src/CI/travis/make_linux
+++ b/src/CI/travis/make_linux
@@ -1,8 +1,42 @@
-#!/bin/sh
+#!/bin/sh -e
 
 if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi
 
-cd $TRAVIS_BUILD_DIR/build
-cmake -DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON ..
-make && make package
+. CI/travis/lib.sh
+
+handle_default() {
+	mkdir -p build
+	cd build
+	cmake -DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON ..
+	make && make package
+	if [ -n "${GH_DOC_TOKEN}" ] && \
+			[ -f "./generateDocumentationAndDeploy.sh" ] ; then
+		sh generateDocumentationAndDeploy.sh
+	fi
+	cd ..
+}
+
+handle_centos() {
+	mkdir -p build
+	cd build
+	cmake -DENABLE_PACKAGING=ON ..
+	make && make package
+	cd ..
+}
+
+handle_centos_docker() {
+	run_docker_script inside_docker.sh \
+		"centos:centos${OS_VERSION}" "centos"
+}
+
+handle_ubuntu_docker() {
+	run_docker_script inside_docker.sh \
+		"ubuntu:${OS_VERSION}"
+}
+
+LIBNAME="$1"
+OS_TYPE=${2:-default}
+OS_VERSION="$3"
+
+handle_${OS_TYPE}
 
diff --git a/src/CI/travis/make_linux_qemu b/src/CI/travis/make_linux_qemu
new file mode 100755
index 0000000..b1d101d
--- /dev/null
+++ b/src/CI/travis/make_linux_qemu
@@ -0,0 +1,13 @@
+#!/bin/bash
+set -ex
+
+CHROOT_DIR=/tmp/arm-chroot
+
+sudo chroot ${CHROOT_DIR} bash -c "cd ${TRAVIS_BUILD_DIR} && ./CI/travis/make_linux libiio"
+sudo chroot ${CHROOT_DIR} bash -c ". ${TRAVIS_BUILD_DIR}/CI/travis/lib.sh && get_ldist > ${TRAVIS_BUILD_DIR}/build/.LDIST"
+
+#move the artifacts back to the non-qemu place
+sudo rsync -av ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}/ ${TRAVIS_BUILD_DIR}/
+#make sure the normal travis user can read them
+sudo chown -R ${USER} ${TRAVIS_BUILD_DIR}
+
diff --git a/src/CI/travis/setup_qemu_for_arm.sh b/src/CI/travis/setup_qemu_for_arm.sh
new file mode 100755
index 0000000..2904e94
--- /dev/null
+++ b/src/CI/travis/setup_qemu_for_arm.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+# Based on a test script from avsm/ocaml repo https://github.com/avsm/ocaml
+set -ex
+
+if [ $# -ne 1 ] ; then
+	echo Must include debian distribution ie wheezy, jessie, stretch, or buster
+	exit -1
+fi
+if [[ ! $1 =~ ^wheezy|jessie|stretch|buster$ ]] ; then
+	echo Must include debian distribution ie wheezy, jessie, stretch, or buster
+	exit -1
+fi
+
+CHROOT_DIR=/tmp/arm-chroot
+MIRROR=http://archive.raspbian.org/raspbian
+# wheezy = 7 (2013-05-04); jessie = 8 (2015-04-26); stretch = 9 (2017-06-17); buster = 10 (2019-03-12)
+VERSION=$1
+echo building for ${VERSION}
+CHROOT_ARCH=armhf
+
+# Host dependencies
+sudo apt-get update
+sudo apt-get install -qq -y qemu-user-static binfmt-support sbuild wget debian-archive-keyring ubuntu-keyring gnupg libudev1 libudev-dev liblzma-dev libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev
+# need a newer version of qemu :(
+QEMU_DIR=/tmp/qemu
+sudo mkdir -p ${QEMU_DIR}
+sudo chown ${USER} /tmp/qemu
+cd ${QEMU_DIR}
+wget https://download.qemu.org/qemu-3.1.0.tar.xz
+tar xf qemu-3.1.0.tar.xz
+cd qemu-3.1.0
+mkdir build
+mkdir install
+cd build
+../configure --prefix=${QEMU_DIR}/install --disable-bsd-user --disable-guest-agent --disable-strip --disable-werror --disable-gcrypt --disable-debug-info --disable-debug-tcg --disable-docs --disable-tcg-interpreter --enable-attr --disable-brlapi --disable-linux-aio --disable-bzip2 --disable-bluez --disable-cap-ng --disable-curl --disable-fdt --disable-glusterfs --disable-gnutls --disable-nettle --disable-gtk --disable-rdma --disable-libiscsi --disable-vnc-jpeg --disable-kvm --disable-lzo --disable-curses --disable-libnfs --disable-numa --disable-opengl --disable-vnc-png --disable-rbd --disable-vnc-sasl --disable-sdl --disable-seccomp --disable-smartcard --disable-snappy --disable-spice --disable-libssh2 --disable-libusb --disable-usb-redir --disable-vde --disable-vhost-net --disable-virglrenderer --disable-virtfs --disable-vnc --disable-vte --disable-xen --disable-xen-pci-passthrough --disable-xfsctl --enable-linux-user --disable-system --disable-blobs --disable-tools --target-list=arm-linux-user --static --disable-pie
+make -j $(nproc)
+make install
+ls -lR ${QEMU_DIR}/install
+cd /tmp
+
+# per https://wiki.ubuntu.com/DebootstrapChroot
+if [[ "$VERSION" =~ ^wheezy|jessie$ ]] ; then
+	sudo apt-get install -qq -y debootstrap
+
+elif [[ "$VERSION" =~ ^stretch$ ]] ; then
+	sudo add-apt-repository -r "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-updates main restricted universe multiverse "
+	sudo apt-get install -qq -y -t $(lsb_release -cs)-updates debootstrap
+elif [[ "$VERSION" =~ ^buster$ ]] ; then
+	wget http://http.us.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.111_all.deb -O /tmp/debootstrap_1.0.111_all.deb
+	sudo dpkg --install /tmp/debootstrap_1.0.111_all.deb
+fi
+
+# Create chrooted environment
+sudo mkdir ${CHROOT_DIR}
+sudo debootstrap --foreign --no-check-gpg --include=fakeroot,build-essential --arch=${CHROOT_ARCH} ${VERSION} ${CHROOT_DIR} ${MIRROR}
+sudo cp ${QEMU_DIR}/install/bin/qemu-arm ${CHROOT_DIR}/usr/bin/qemu-arm-static
+${CHROOT_DIR}/usr/bin/qemu-arm-static -version
+sudo chroot ${CHROOT_DIR} ./debootstrap/debootstrap --second-stage
+sudo sbuild-createchroot --arch=${CHROOT_ARCH} --foreign --setup-only ${VERSION} ${CHROOT_DIR} ${MIRROR}
+
+# Create file with environment variables which will be used inside chrooted
+# environment
+echo "export ARCH=${ARCH}" > envvars.sh
+echo "export TRAVIS_BUILD_DIR=${TRAVIS_BUILD_DIR}" >> envvars.sh
+chmod a+x envvars.sh
+
+# Install dependencies inside chroot
+sudo chroot ${CHROOT_DIR} dpkg --add-architecture ${CHROOT_ARCH}
+sudo chroot ${CHROOT_DIR} dpkg --remove-architecture amd64
+sudo chroot ${CHROOT_DIR} apt-get update
+sudo chroot ${CHROOT_DIR} apt-get --allow-unauthenticated install -qq -y locales
+sudo chroot ${CHROOT_DIR} locale 
+sudo chroot ${CHROOT_DIR} bash -c "echo en_US.UTF-8 UTF-8 > /etc/locale.gen"
+sudo chroot ${CHROOT_DIR} locale-gen
+#sudo chroot ${CHROOT_DIR} bash -c "echo -e 'LANG=\"en_US.UTF-8\"\\nLANGUAGE=\"en_US:en\"\\n' > /etc/default/locale"
+sudo chroot ${CHROOT_DIR} apt-get --allow-unauthenticated install -qq -y build-essential git m4 sudo python cmake
+
+# Create build dir and copy travis build files to our chroot environment
+sudo mkdir -p ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}
+sudo rsync -av ${TRAVIS_BUILD_DIR}/ ${CHROOT_DIR}/${TRAVIS_BUILD_DIR}/
+
+# Indicate chroot environment has been set up
+sudo touch ${CHROOT_DIR}/.chroot_is_done
+
+# Call standard before_install_linux in chroot environment
+sudo chroot ${CHROOT_DIR} bash -c "cd ${TRAVIS_BUILD_DIR} && pwd && ./CI/travis/before_install_linux"
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1e198e2..d9b7ea1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,7 @@
 project(libiio C)
 
 set(LIBIIO_VERSION_MAJOR 0)
-set(LIBIIO_VERSION_MINOR 15)
+set(LIBIIO_VERSION_MINOR 18)
 set(VERSION "${LIBIIO_VERSION_MAJOR}.${LIBIIO_VERSION_MINOR}")
 if (WIN32)
 	string(TIMESTAMP BUILD_YEAR "%Y")
@@ -15,6 +15,10 @@
 
 set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/${PROJECT_NAME}${LIBIIO_VERSION_MAJOR}-doc)")
 include(GNUInstallDirs)
+if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+	set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
+	set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+endif()
 set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}${LIBIIO_VERSION_MAJOR}-doc")
 
 set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
@@ -99,7 +103,7 @@
 	endif()
 endif()
 
-set(LIBIIO_CFILES backend.c channel.c device.c context.c buffer.c utilities.c scan.c)
+set(LIBIIO_CFILES backend.c channel.c device.c context.c buffer.c utilities.c scan.c sort.c)
 set(LIBIIO_HEADERS iio.h)
 
 add_definitions(-D_POSIX_C_SOURCE=200809L -D__XSI_VISIBLE=500 -DLIBIIO_EXPORTS=1)
@@ -112,6 +116,7 @@
 		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 		OUTPUT_VARIABLE LIBIIO_GIT_REPO
 		OUTPUT_STRIP_TRAILING_WHITESPACE
+		ERROR_QUIET
 	)
 
 	if ("${LIBIIO_GIT_REPO}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
@@ -157,6 +162,7 @@
 find_library(LIBUSB_LIBRARIES usb-1.0)
 find_path(LIBUSB_INCLUDE_DIR libusb-1.0/libusb.h)
 if (LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIR)
+	message(STATUS "Looking for libusb-1.0 : Found")
 	option(WITH_USB_BACKEND "Enable the libusb backend" ON)
 
 	if(WITH_USB_BACKEND)
@@ -168,7 +174,16 @@
 		set(NEED_THREADS 1)
 
 		include_directories(${LIBUSB_INCLUDE_DIR})
+
+		set(TEMP ${CMAKE_REQUIRED_LIBRARIES})
+		set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+			 ${LIBUSB_LIBRARIES})
+		check_symbol_exists(libusb_get_version "libusb-1.0/libusb.h"
+			HAS_LIBUSB_GETVERSION)
+		set(CMAKE_REQUIRED_LIBRARIES ${TEMP})
 	endif()
+else()
+	message(STATUS "Looking for libusb-1.0 : Failed; building without usb")
 endif()
 
 find_library(LIBSERIALPORT_LIBRARIES serialport)
@@ -341,8 +356,20 @@
 if(DOXYGEN_FOUND)
 	option(WITH_DOC "Generate documentation with Doxygen" ON)
 
+	# It is not an error when 'dot' is not found, just switching off the Doxygen's HAVE_DOT option
+	find_package_handle_standard_args (Dot REQUIRED_VARS DOXYGEN_DOT_EXECUTABLE)
+
+	include(cmake/CheckCaseSensitiveFileSystem.cmake)
+	if (HAVE_CASE_SENSITIVE_FILESYSTEM)
+		set(CMAKE_CASE_SENSITIVE_FILESYSTEM "YES")
+	else()
+		set(CMAKE_CASE_SENSITIVE_FILESYSTEM "NO")
+	endif()
+
 	if (WITH_DOC)
 		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
+		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CI/travis/generateDocumentationAndDeploy.sh.in
+				${CMAKE_CURRENT_BINARY_DIR}/generateDocumentationAndDeploy.sh @ONLY)
 		set(HTML_DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/html)
 		file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/doc DESTINATION ${HTML_DEST_DIR})
 
diff --git a/src/Doxyfile.in b/src/Doxyfile.in
index 6a25526..2dc2d92 100644
--- a/src/Doxyfile.in
+++ b/src/Doxyfile.in
@@ -372,7 +372,7 @@
 # and Mac users are advised to set this option to NO.
 # The default value is: system dependent.
 
-CASE_SENSE_NAMES       = YES
+CASE_SENSE_NAMES       = @CMAKE_CASE_SENSITIVE_FILESYSTEM@
 
 # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
 # their full class and namespace scopes in the documentation. If set to YES the
@@ -716,7 +716,7 @@
 # that contain images that are to be included in the documentation (see the
 # \image command).
 
-IMAGE_PATH             =
+IMAGE_PATH             = @CMAKE_SOURCE_DIR@/doc
 
 # The INPUT_FILTER tag can be used to specify a program that doxygen should
 # invoke to filter for each input file. Doxygen will invoke the filter program
@@ -1599,7 +1599,7 @@
 # set to NO
 # The default value is: NO.
 
-HAVE_DOT               = NO
+HAVE_DOT               = @DOXYGEN_DOT_FOUND@
 
 # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
 # to run in parallel. When set to 0 doxygen will base this on the number of
@@ -1715,7 +1715,7 @@
 # The default value is: NO.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-CALL_GRAPH             = NO
+CALL_GRAPH             = YES
 
 # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
 # dependency graph for every global function or class method.
@@ -1726,7 +1726,7 @@
 # The default value is: NO.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-CALLER_GRAPH           = NO
+CALLER_GRAPH           = YES
 
 # If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
 # hierarchy of all classes instead of a textual one.
@@ -1771,7 +1771,7 @@
 # found. If left blank, it is assumed the dot tool can be found in the path.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-DOT_PATH               =
+DOT_PATH               = "@DOXYGEN_DOT_PATH@"
 
 # The DOTFILE_DIRS tag can be used to specify one or more directories that
 # contain dot files that are included in the documentation (see the \dotfile
@@ -1802,7 +1802,7 @@
 # Minimum value: 0, maximum value: 10000, default value: 50.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-DOT_GRAPH_MAX_NODES    = 50
+DOT_GRAPH_MAX_NODES    = 25
 
 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
 # generated by dot. A depth value of 3 means that only nodes reachable from the
@@ -1814,7 +1814,7 @@
 # Minimum value: 0, maximum value: 1000, default value: 0.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-MAX_DOT_GRAPH_DEPTH    = 0
+MAX_DOT_GRAPH_DEPTH    = 10
 
 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
 # background. This is disabled by default, because dot on Windows does not seem
@@ -1826,7 +1826,7 @@
 # The default value is: NO.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-DOT_TRANSPARENT        = NO
+DOT_TRANSPARENT        = YES
 
 # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
 # files in one run (i.e. multiple -o and -T options on the command line). This
@@ -1835,7 +1835,7 @@
 # The default value is: NO.
 # This tag requires that the tag HAVE_DOT is set to YES.
 
-DOT_MULTI_TARGETS      = YES
+DOT_MULTI_TARGETS      = NO
 
 # If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
 # explaining the meaning of the various boxes and arrows in the dot generated
diff --git a/src/README.md b/src/README.md
index f3dd05a..4ea237a 100644
--- a/src/README.md
+++ b/src/README.md
@@ -11,19 +11,28 @@
 Downloads :  [![Github All Releases](https://img.shields.io/github/downloads/analogdevicesinc/libiio/total.svg)](https://github.com/analogdevicesinc/libiio/releases/latest)
 
 Scans : [![Coverity Scan Build Status](https://img.shields.io/coverity/scan/4796.svg)](https://scan.coverity.com/projects/analogdevicesinc-libiio)
+Release docs: [![Documentation](https://codedocs.xyz/analogdevicesinc/libiio.svg)](http://analogdevicesinc.github.io/libiio/)
+Issues : [![open bugs](https://img.shields.io/github/issues/analogdevicesinc/libiio.svg)](https://github.com/analogdevicesinc/libiio/issues)
+[![closed bugs](https://img.shields.io/github/issues-closed/analogdevicesinc/libiio.svg)](https://github.com/analogdevicesinc/libiio/issues?q=is%3Aissue+is%3Aclosed)
+
+Support:<br>
+If you have a question about libiio and an Analog Devices IIO kernel driver please ask on : [![EngineerZone](https://img.shields.io/badge/chat-on%20EngineerZone-blue.svg)](https://ez.analog.com/linux-device-drivers/linux-software-drivers). If you have a question about a non-ADI devices, please ask it on [github](https://github.com/analogdevicesinc/libiio/issues).
 
 As with many open source packages, we use [GitHub](https://github.com/analogdevicesinc/libiio) to do develop and maintain the source, and [Travis CI](https://travis-ci.com/) and [Appveyor](https://www.appveyor.com/) for continuous integration.
   - If you want to just use libiio, we suggest using the [latest release](https://github.com/analogdevicesinc/libiio/releases/latest).
-  - If you think you have found a bug in the release, or need a feature which isn't in the release, try the latest **untested** binaries from the master branch. We provide builds for a few operating systems. If you need something else, we can most likely add that -- just ask.
+  - If you think you have found a bug in the release, or need a feature which isn't in the release, try the latest **untested** binaries from the master branch and check out the [documentation](https://codedocs.xyz/analogdevicesinc/libiio/) based on the master branch. We provide builds for a few operating systems. If you need something else, we can most likely add that -- just ask.
 
-| Operating System        | GitHub master status  | Version |  Installer Package  | tarball or zip |
+| Operating System        | GitHub master status  | Version |  Primary Installer Package  | Alternative Package, tarball or zip |
 |:-----------------------:|:---------------------:|:-------:|:-------------------:|:--------------:|
 | Windows                 | [![Windows Status](https://ci.appveyor.com/api/projects/status/github/analogdevicesinc/libiio?svg=true)](https://ci.appveyor.com/project/analogdevicesinc/libiio/branch/master) | Windows 10<br />Windows 8.1<br />Windows 8<br />Windows 7 | [![Latest Windows installer](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/win_box.png)](https://ci.appveyor.com/api/projects/analogdevicesinc/libiio/artifacts/libiio-setup.exe?branch=master) | [![Latest Windows zip](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/win_box.png)](https://ci.appveyor.com/api/projects/analogdevicesinc/libiio/artifacts/libiio.zip?branch=master) |
-| OS X                    | [![OSX Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=osx&passingTex=foo)](https://travis-ci.org/analogdevicesinc/libiio) | macOS Sierra<br />(v 10.12) | [![OS-X package 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.12.pkg) | [![OS-X tarball 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.12.tar.gz) |
-|                  |                     |  OS X El Capitan<br />(v 10.11) | [![OS-X package 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.11.pkg) | [![OS-X tarball 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.11.tar.gz) |
-|                  |                     |  OS X Yosemite<br />(v 10.10) | [![OS-X package 10.10](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.10.pkg) | [![OS-X tarball 10.10](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-osx_10.10.tar.gz) |
-| Linux                   | [![Linux Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=linux)](https://travis-ci.org/analogdevicesinc/libiio) | Ubuntu Trusty Tahr<br />(v 14.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-trusty.deb) [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-trusty.rpm)<sup>3</sup> | [![tar.gz file](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-trusty.tar.gz) |
-|  |  | Ubuntu Precise Pangolin<br />(v 12.04)<sup>2</sup>  | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-precise.deb) [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-precise.rpm)<sup>3</sup> | [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-precise.tar.gz) |
+| OS X              |  [![OSX Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=osx&passingTex=foo)](https://travis-ci.org/analogdevicesinc/libiio) |  OS X High Sierra <br />(v 10.13) | [![OS-X package 10.13](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.13.6.pkg) | [![OS-X tarball 10.10](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.13.6.tar.gz) |
+|                    |                     | macOS Sierra<br />(v 10.12) | [![OS-X package 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.12.6.pkg) | [![OS-X tarball 10.12](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.12.6.tar.gz) |
+|                  |                     |  OS X El Capitan<br />(v 10.11) | [![OS-X package 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.11.6.pkg) | [![OS-X tarball 10.11](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/osx_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-darwin-10.11.6.tar.gz) |
+| Linux     | [![Linux Status](https://api.travis-ci.org/analogdevicesinc/libiio.svg?branch=master&label=linux)](https://travis-ci.org/analogdevicesinc/libiio) | Ubuntu Bionic Beaver<br />(v 18.04)<sup>1</sup>  | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.rpm) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-18.04-amd64.tar.gz) |
+|  |  | Ubuntu Xenial Xerus<br />(v 16.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.rpm)  [![tar.gz file](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-16.04-amd64.tar.gz) |
+|  |  | Ubuntu Trusty Tahr<br />(v 14.04)<sup>1</sup> | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.deb) | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.rpm) [![tar.gz file](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-ubuntu-14.04-amd64.tar.gz) |
+|  |  | CentOS 7  | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.rpm)  | [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.deb) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-7-x86_64.tar.gz) |
+|  |  | CentOS 6  | [![RPM File](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/rpm.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.rpm) |  [![Debian](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/deb.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.deb) [![tar.gz](https://raw.githubusercontent.com/wiki/analogdevicesinc/libiio/img/linux_box.png)](http://swdownloads.analog.com/cse/travis_builds/master_latest_libiio-centos-6.10-x86_64.tar.gz) |
 
 If you use it, and like it - please let us know. If you use it, and hate it - please let us know that too. The goal of the project is to try to make Linux IIO devices easier to use on a variety of platforms. If we aren't doing that - we will try to make it better.
 
@@ -39,9 +48,5 @@
   * Libiio : http://wiki.analog.com/resources/tools-software/linux-software/libiio
   * Libiio internals : http://wiki.analog.com/resources/tools-software/linux-software/libiio_internals
 
-1. This is known to work on Debian Jessie(v 8) as well.<br />
-Package dependencies: libc6 (>= 2.19), libaio1 (>= 0.3.109), libavahi-client3 (>= 0.6.31), libavahi-common-data (>= 0.6.31), libavahi-common3 (>= 0.6.31), libusb-1.0-0 (>= 2:1.0.17), libxml2 (>= 2.9.1)<br />
-2. This is known to work on Debian Wheezy(v 7) as well.<br />
-Package dependencies: libc6 (>= 2.15), libaio1 (>= 0.3.109), libavahi-client3 (>= 0.6.30), libavahi-common-data (>= 0.6.30), libavahi-common3 (>= 0.6.30), libusb-1.0-0 (>= 2:1.0.9~rc3), libxml2 (>= 2.8.0~precise1)<br />
-3. The rpm packages are listed under Ubuntu, since we take advantage of the Debian/Ubuntu ability to build rpm packages. These are not actually built on Red Hat/Fedora based systems, but are known to work.
+1. The Ubuntu packages are known to work on their Debian counterpart releases.
 
diff --git a/src/appveyor.yml b/src/appveyor.yml
index 02acb86..47216c4 100644
--- a/src/appveyor.yml
+++ b/src/appveyor.yml
@@ -1,4 +1,4 @@
-version: 2015.1.{build}
+version: '{branch}.{build}'
 clone_depth: 1
 
 skip_commits:
@@ -40,9 +40,13 @@
     - C:\msys64\usr\bin\bash -lc "pwd"
     - C:\msys64\usr\bin\bash -lc "pacman -Rs --noconfirm mingw-w64-i686-gcc-ada mingw-w64-i686-gcc-fortran mingw-w64-i686-gcc-libgfortran mingw-w64-i686-gcc-objc"
     - C:\msys64\usr\bin\bash -lc "rm /mingw32/etc/gdbinit"
+    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy  mingw-w64-i686-gcc mingw-w64-i686-libusb mingw-w64-i686-curl mingw-w64-i686-cmake mingw-w64-i686-libxml2 mingw-w64-i686-pkg-config mingw-w64-i686-libzip"
+    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu"
     # Newer llvm breaks doxygen, use old version for now
     - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-llvm-5.0.0-3-any.pkg.tar.xz http://repo.msys2.org/mingw/i686/mingw-w64-i686-clang-5.0.0-3-any.pkg.tar.xz"
-    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy  mingw-w64-i686-gcc mingw-w64-i686-libusb mingw-w64-i686-cmake mingw-w64-i686-libxml2 mingw-w64-i686-pkg-config mingw-w64-i686-libzip mingw-w64-i686-doxygen"
+    # set the specific version of doxygen (06-Jun-2018), need to look at this later.
+    - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-doxygen-1.8.14-2-any.pkg.tar.xz"
+    - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/i686/mingw-w64-i686-graphviz-2.40.1-4-any.pkg.tar.xz"
     # Download a 32-bit version of windres.exe
     - appveyor DownloadFile http://swdownloads.analog.com/cse/build/windres.exe.gz -FileName C:\windres.exe.gz
     - C:\msys64\usr\bin\bash -lc "cd /c ; gunzip windres.exe.gz"
@@ -57,9 +61,13 @@
     - C:\msys64\usr\bin\bash -lc "pwd"
     - C:\msys64\usr\bin\bash -lc "pacman -Rs --noconfirm mingw-w64-x86_64-gcc-ada mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-gcc-libgfortran mingw-w64-x86_64-gcc-objc"
     - C:\msys64\usr\bin\bash -lc "rm /mingw64/etc/gdbinit"
+    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy mingw-w64-x86_64-gcc mingw-w64-x86_64-libusb mingw-w64-x86_64-curl mingw-w64-x86_64-cmake mingw-w64-x86_64-libxml2 mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libzip"
+    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu"
     # Newer llvm breaks doxygen, use old version for now
     - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-llvm-5.0.0-3-any.pkg.tar.xz http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-clang-5.0.0-3-any.pkg.tar.xz"
-    - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Sy  mingw-w64-x86_64-gcc mingw-w64-x86_64-libusb mingw-w64-x86_64-cmake mingw-w64-x86_64-libxml2 mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libzip mingw-w64-x86_64-doxygen"
+    # set the specific version of doxygen, need to look at this later.
+    - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-doxygen-1.8.14-2-any.pkg.tar.xz"
+    - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-graphviz-2.40.1-4-any.pkg.tar.xz"
     - C:\msys64\usr\bin\bash -lc "cmake -G '%GENERATOR%' -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=/mingw64 -DCMAKE_C_COMPILER:FILEPATH=/mingw64/bin/x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=/mingw64/bin/x86_64-w64-mingw32-g++.exe -DCSHARP_BINDINGS:BOOL=OFF -DPKG_CONFIG_EXECUTABLE:FILEPATH=/mingw64/bin/pkg-config.exe -DENABLE_IPV6:BOOL=OFF -DPYTHON_BINDINGS:BOOL=OFF -DLIBSERIALPORT_LIBRARIES=/c/libs/64/libserialport.dll.a -DLIBSERIALPORT_INCLUDE_DIR=/c/include /c/projects/libiio && make -j3"
 
     # Move the tests folder
diff --git a/src/bindings/matlab/iio_sys_obj_matlab.m b/src/bindings/matlab/iio_sys_obj_matlab.m
index babe948..572ec03 100644
--- a/src/bindings/matlab/iio_sys_obj_matlab.m
+++ b/src/bindings/matlab/iio_sys_obj_matlab.m
@@ -333,7 +333,18 @@
         
         function ret = writeFirData(obj, fir_data_file)
             fir_data_str = fileread(fir_data_file);
+            ret = writeAttributeString(obj.libiio_ctrl_dev, 'in_out_voltage_filter_fir_en', '0');
+            if ret<0
+                return;
+            end
             ret = writeAttributeString(obj.libiio_ctrl_dev, 'filter_fir_config', fir_data_str);
+            if ret<0
+                return;
+            end
+            ret = writeAttributeString(obj.libiio_ctrl_dev, 'in_out_voltage_filter_fir_en', '1');
+            if ret<0
+                return;
+            end
         end
     end
-end
\ No newline at end of file
+end
diff --git a/src/buffer.c b/src/buffer.c
index ba5bfa5..91aeff6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -223,14 +223,14 @@
 				break;
 
 			/* Test if the buffer has samples for this channel */
-			if (!TEST_BIT(buffer->mask, chn->index))
+			if (!TEST_BIT(buffer->mask, chn->number))
 				continue;
 
 			if ((ptr - start) % length)
 				ptr += length - ((ptr - start) % length);
 
 			/* Test if the client wants samples from this channel */
-			if (TEST_BIT(dev->mask, chn->index)) {
+			if (TEST_BIT(dev->mask, chn->number)) {
 				ssize_t ret = callback(chn,
 						(void *) ptr, length, d);
 				if (ret < 0)
@@ -272,7 +272,7 @@
 			break;
 
 		/* Test if the buffer has samples for this channel */
-		if (!TEST_BIT(buffer->mask, cur->index))
+		if (!TEST_BIT(buffer->mask, cur->number))
 			continue;
 
 		/* Two channels with the same index use the same samples */
diff --git a/src/channel.c b/src/channel.c
index ccecf8e..e360a63 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -141,7 +141,7 @@
 		if (strncmp(iio_chan_type_name_spec[i], chn->id, len) != 0)
 			continue;
 		/* Type must be followed by either a '_' or a digit */
-		if (chn->id[len] != '_' && chn->id[len] < '0' && chn->id[len] > '9')
+		if (chn->id[len] != '_' && (chn->id[len] < '0' || chn->id[len] > '9'))
 			continue;
 
 		chn->type = (enum iio_chan_type) i;
@@ -159,9 +159,6 @@
 		len = strlen(modifier_names[i]);
 		if (strncmp(modifier_names[i], mod, len) != 0)
 			continue;
-		/* Modifier must be followed by a '_' */
-		if (mod[len] != '_')
-			continue;
 
 		chn->modifier = (enum iio_modifier) i;
 		break;
@@ -190,7 +187,7 @@
 
 static char * get_scan_element(const struct iio_channel *chn, size_t *length)
 {
-	char buf[1024], repeat[8] = "", *str;
+	char buf[1024], repeat[12] = "", *str;
 	char processed = (chn->format.is_fully_defined ? 'A' - 'a' : 0);
 
 	if (chn->format.repeat > 1)
diff --git a/src/cmake/CheckCaseSensitiveFileSystem.cmake b/src/cmake/CheckCaseSensitiveFileSystem.cmake
new file mode 100644
index 0000000..8bbf81c
--- /dev/null
+++ b/src/cmake/CheckCaseSensitiveFileSystem.cmake
@@ -0,0 +1,38 @@
+#
+# Check if the file system is case sensitive or not
+# Inspired by Andreas Lauser's cmake at:
+# https://github.com/OPM/opm-parser/blob/master/cmake/Modules/CheckCaseSensitiveFileSystem.cmake
+# Included in libiio (LGPL2) with permission.
+#
+# Sets the following variable:
+# HAVE_CASE_SENSITIVE_FILESYSTEM   True if the file system honors the case of files
+#
+# I dislike that we have to emit a file from CMake, but I can't think of a better way.
+
+message(STATUS "Check for case-sensitive file systems")
+string(RANDOM LENGTH 6 ALPHABET abcdefghijklmnopqrstuvwxyz TMP_FILE_L)
+set(TMP_FILE_L "${TMP_FILE_L}.tmp")
+string(TOUPPER ${TMP_FILE_L} TMP_FILE_U)
+string(TIMESTAMP TMP_TIME)
+set(TMP_FILE_CONTENTS "${TMP_FILE_L} ${TMP_TIME}")
+# create a uppercase file
+file(WRITE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}" "${TMP_FILE_CONTENTS}")
+
+# test if lowercase file can be opened
+set(FileContents "")
+if (EXISTS "${CMAKE_BINARY_DIR}/${TMP_FILE_L}")
+	file(READ "${CMAKE_BINARY_DIR}/${TMP_FILE_L}" FileContents)
+endif()
+
+# remove the file
+file(REMOVE "${CMAKE_BINARY_DIR}/${TMP_FILE_U}")
+
+# check the contents
+# If it is empty, the file system is case sensitive.
+if ("${FileContents}" STREQUAL "${TMP_FILE_CONTENTS}")
+	message(STATUS "File system is not case-sensitive")
+	set(HAVE_CASE_SENSITIVE_FILESYSTEM 0)
+else()
+	message(STATUS "File system is case-sensitive")
+	set(HAVE_CASE_SENSITIVE_FILESYSTEM 1)
+endif()
diff --git a/src/cmake/LinuxPackaging.cmake b/src/cmake/LinuxPackaging.cmake
index bdd28a5..72f1c18 100644
--- a/src/cmake/LinuxPackaging.cmake
+++ b/src/cmake/LinuxPackaging.cmake
@@ -6,8 +6,21 @@
 if (RPMBUILD_CMD)
 	set(CPACK_PACKAGE_RELOCATABLE OFF)
 	set(CPACK_GENERATOR ${CPACK_GENERATOR};RPM)
+	set(CPACK_RPM_PACKAGE_REQUIRES "libaio >= 0.3.107, avahi >= 0.6.25, libusb1 >= 1.0.9, libxml2 >= 2.7.6")
 endif()
 
+# Add these for CentOS 7
+set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
+	/lib
+	/lib/udev
+	/lib/udev/rules.d
+	/usr/sbin
+	/usr/lib/python2.7
+	/usr/lib/python2.7/site-packages
+	/usr/lib/pkgconfig
+	/usr/lib64/pkgconfig
+)
+
 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
 set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR})
 set(CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR})
@@ -47,6 +60,9 @@
 	if(WITH_XML_BACKEND)
 		set(PACKAGES "${PACKAGES} libxml2")
 	endif()
+	if(WITH_SERIAL_BACKEND)
+		set(PACKAGES "${PACKAGES} libserialport0")
+	endif()
 	# find the version of the installed package, which is hard to do in
 	# cmake first, turn the list into an list (seperated by semicolons)
 	string(REGEX REPLACE " " ";" PACKAGES ${PACKAGES})
@@ -99,10 +115,26 @@
 		${CPACK_DEBIAN_PACKAGE_DEPENDS})
 else()
 	# assume everything is turned on, and running on a modern OS
-	set(CPACK_DEBIAN_PACKAGE_DEPENDS "libaio-dev (>= 0.3.109), libavahi-client-dev (>= 0.6.31), libavahi-common-dev (>= 0.6.31), libc6-dev (>= 2.19), libusb-1.0-0-dev (>= 2:1.0.17), libxml2-dev (>= 2.9.1)")
+	set(CPACK_DEBIAN_PACKAGE_DEPENDS "libaio (>= 0.3.109), libavahi-client (>= 0.6.31), libavahi-common (>= 0.6.31), libc6 (>= 2.19), libusb-1.0-0 (>= 2:1.0.17), libxml2 (>= 2.9.1), libserialport0 (>=0.1.1)")
 	message(STATUS "Using default dependencies for packaging")
 endif()
 
-message(STATUS "Package dependencies: " ${CPACK_DEBIAN_PACKAGE_DEPENDS})
+message(STATUS "Package dependencies (.deb): " ${CPACK_DEBIAN_PACKAGE_DEPENDS})
+if (CPACK_RPM_PACKAGE_REQUIRES)
+	message(STATUS "Package dependencies (.rpm): " ${CPACK_RPM_PACKAGE_REQUIRES})
+endif()
 
+if(${CMAKE_MAJOR_VERSION} LESS 3)
+	# old versions of cmake dont include this, but the same vintage of dpkg requires it
+	IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
+		FIND_PROGRAM(DPKG_CMD dpkg)
+		IF(NOT DPKG_CMD)
+			MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
+			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
+		ENDIF(NOT DPKG_CMD)
+		EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
+			OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
+			OUTPUT_STRIP_TRAILING_WHITESPACE)
+	ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
+endif()
 include(CPack)
diff --git a/src/context.c b/src/context.c
index b124801..2b54730 100644
--- a/src/context.c
+++ b/src/context.c
@@ -19,6 +19,7 @@
 #include "debug.h"
 #include "iio-config.h"
 #include "iio-private.h"
+#include "sort.h"
 
 #include <errno.h>
 #include <string.h>
diff --git a/src/iio-config.h b/src/iio-config.h
index 312c7a7..a689f85 100644
--- a/src/iio-config.h
+++ b/src/iio-config.h
@@ -2,10 +2,10 @@
 #define IIO_CONFIG_H
 
 #define LIBIIO_VERSION_MAJOR	0
-#define LIBIIO_VERSION_MINOR	15
-#define LIBIIO_VERSION_GIT	"19d8880"
+#define LIBIIO_VERSION_MINOR	18
+#define LIBIIO_VERSION_GIT	"4e22517"
 
-#define LOG_LEVEL Info
+#define LOG_LEVEL Info_L
 
 #define WITH_LOCAL_BACKEND
 #undef WITH_XML_BACKEND
@@ -26,5 +26,6 @@
 #undef HAVE_IPV6
 #undef HAVE_AVAHI
 #undef NO_THREADS
+#undef HAS_LIBUSB_GETVERSION
 
 #endif /* IIO_CONFIG_H */
diff --git a/src/iio-config.h.cmakein b/src/iio-config.h.cmakein
index 6700326..580e78a 100644
--- a/src/iio-config.h.cmakein
+++ b/src/iio-config.h.cmakein
@@ -26,5 +26,6 @@
 #cmakedefine HAVE_IPV6
 #cmakedefine HAVE_AVAHI
 #cmakedefine NO_THREADS
+#cmakedefine HAS_LIBUSB_GETVERSION
 
 #endif /* IIO_CONFIG_H */
diff --git a/src/iio-private.h b/src/iio-private.h
index a4d17d4..685c290 100644
--- a/src/iio-private.h
+++ b/src/iio-private.h
@@ -138,6 +138,11 @@
 	int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
 };
 
+/*
+ * If these structures are updated, the qsort functions defined in sort.c
+ * may need to be updated.
+ */
+
 struct iio_context_pdata;
 struct iio_device_pdata;
 struct iio_channel_pdata;
diff --git a/src/iio.h b/src/iio.h
index 5d8ca5a..b9d78a0 100644
--- a/src/iio.h
+++ b/src/iio.h
@@ -1402,7 +1402,7 @@
  * @return A pointer to the first sample found, or to the end of the buffer if
  * no sample for the given channel is present in the buffer
  *
- * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end,
+ * <b>NOTE:</b> This function, coupled with iio_buffer_step and iio_buffer_end,
  * can be used to iterate on all the samples of a given channel present in the
  * buffer, doing the following:
  *
diff --git a/src/iiod/ops.c b/src/iiod/ops.c
index 3f783a0..bf26bc1 100644
--- a/src/iiod/ops.c
+++ b/src/iiod/ops.c
@@ -362,7 +362,7 @@
 		void *src, size_t length, void *d)
 {
 	struct sample_cb_info *info = d;
-	if (chn->index < 0 || !TEST_BIT(info->mask, chn->index))
+	if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
 		return 0;
 	if (info->nb_bytes < length)
 		return 0;
@@ -389,7 +389,7 @@
 		void *dst, size_t length, void *d)
 {
 	struct sample_cb_info *info = d;
-	if (chn->index < 0 || !TEST_BIT(info->mask, chn->index))
+	if (chn->index < 0 || !TEST_BIT(info->mask, chn->number))
 		return 0;
 	if (info->cpt == info->nb_bytes)
 		return 0;
@@ -560,7 +560,10 @@
 				struct iio_channel *chn = dev->channels[i];
 				long index = chn->index;
 
-				if (index >= 0 && TEST_BIT(entry->mask, i))
+				if (index < 0)
+					continue;
+
+				if (TEST_BIT(entry->mask, chn->number))
 					iio_channel_enable(chn);
 				else
 					iio_channel_disable(chn);
diff --git a/src/local.c b/src/local.c
index 839ddd5..d05afb6 100644
--- a/src/local.c
+++ b/src/local.c
@@ -18,6 +18,7 @@
 
 #include "debug.h"
 #include "iio-private.h"
+#include "sort.h"
 
 #include <dirent.h>
 #include <errno.h>
@@ -424,7 +425,7 @@
 			pdata->buffer_enabled = true;
 	}
 
-	return 0;
+	return ret;
 }
 
 static int local_set_kernel_buffers_count(const struct iio_device *dev,
@@ -1158,7 +1159,7 @@
 
 	if (chn->name) {
 		size_t len = strlen(chn->name);
-		if  (strncmp(chn->name, ptr, len) == 0 && ptr[len] == '_')
+		if (strncmp(chn->name, ptr, len) == 0 && ptr[len] == '_')
 			ptr += len + 1;
 	}
 
@@ -1359,7 +1360,9 @@
 
 	channels[dev->nb_channels++] = chn;
 	dev->channels = channels;
-	DEBUG("Added channel \'%s\' to device \'%s\'\n", chn->id, dev->id);
+	DEBUG("Added %s channel \'%s\' to device \'%s\'\n",
+		chn->is_output ? "output" : "input", chn->id, dev->id);
+
 	return 0;
 }
 
@@ -1708,6 +1711,9 @@
 		int ret = foreach_in_dir(dev, buf, false, add_buffer_attr);
 		if (ret < 0)
 			return ret;
+
+		qsort(dev->buffer_attrs, dev->nb_buffer_attrs, sizeof(char *),
+			iio_buffer_attr_compare);
 	}
 
 	return 0;
@@ -1748,7 +1754,7 @@
 	ret = add_buffer_attributes(dev, path);
 	if (ret < 0)
 		goto err_free_device;
-	
+
 	ret = add_scan_elements(dev, path);
 	if (ret < 0)
 		goto err_free_scan_elements;
@@ -1767,6 +1773,15 @@
 	if (ret < 0)
 		goto err_free_device;
 
+	/* sorting is done after global attrs are added */
+	for (i = 0; i < dev->nb_channels; i++) {
+		struct iio_channel *chn = dev->channels[i];
+		qsort(chn->attrs,  chn->nb_attrs, sizeof(struct iio_channel_attr),
+			iio_channel_attr_compare);
+	}
+	qsort(dev->attrs, dev->nb_attrs, sizeof(char *),
+		iio_device_attr_compare);
+
 	dev->words = (dev->nb_channels + 31) / 32;
 	if (dev->words) {
 		mask = calloc(dev->words, sizeof(*mask));
@@ -1990,6 +2005,9 @@
 	if (ret < 0)
 		goto err_context_destroy;
 
+	qsort(ctx->devices, ctx->nb_devices, sizeof(struct iio_device *),
+		iio_device_compare);
+
 	foreach_in_dir(ctx, "/sys/kernel/debug/iio", true, add_debug);
 
 	init_scan_elements(ctx);
diff --git a/src/mainpage.dox b/src/mainpage.dox
index 3a3a94a..0965351 100644
--- a/src/mainpage.dox
+++ b/src/mainpage.dox
@@ -126,8 +126,8 @@
 
 Also, not all channels can be enabled. To know whether or not one channel can be enabled, use iio_channel_is_scan_element().
 
-Once the channels have been enabled, the iio_buffer object can be created from the iio_device object that will be used, with the function iio_device_create_buffer().
-This call will fail if no channels have been enabled.
+Once the channels have been enabled, and triggers assigned (for triggered buffers) the iio_buffer object can be created from the iio_device object that will be used, with the function iio_device_create_buffer().
+This call will fail if no channels have been enabled, or for triggered buffers, if the trigger has not been assigned.
 
 When the object is no more needed, it can be destroyed with iio_buffer_destroy().
 
diff --git a/src/sort.c b/src/sort.c
new file mode 100644
index 0000000..f90123c
--- /dev/null
+++ b/src/sort.c
@@ -0,0 +1,93 @@
+/*
+ * libiio - Library for interfacing industrial I/O (IIO) devices
+ *
+ * Copyright (C) 2018 Analog Devices, Inc.
+ * Author: Robin Getz <robin.getz@analog.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * */
+
+#include "iio-private.h"
+#include <string.h>
+
+/* These are a few functions to do sorting via qsort for various
+ * iio structures. For more info, see the qsort(3) man page.
+ *
+ * The qsort comparison function must return an integer less than, equal to,
+ * or greater than zero if the first argument is considered to be
+ * respectively less than, equal to, or greater than the second. If two
+ * members compare as equal, their order in the sort order is undefined.
+ *
+ * If the structures are updated, the compare functions may
+ * need to be updated.
+ *
+ * The actual arguments to these function are "pointers to
+ * pointers to char", but strcmp(3) arguments are "pointers
+ * to char", hence the cast plus dereference
+ */
+
+int iio_channel_compare(const void *p1, const void *p2)
+{
+	const struct iio_channel *tmp1 = *(struct iio_channel **)p1;
+	const struct iio_channel *tmp2 = *(struct iio_channel **)p2;
+
+	/* make sure buffer enabled channels are first */
+	if (iio_channel_is_scan_element(tmp1) && !iio_channel_is_scan_element(tmp2))
+		return -1;
+	if (!iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2))
+		return 1;
+	/* and sort them by index */
+	if (iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2)){
+		if (iio_channel_get_index(tmp1) > iio_channel_get_index(tmp2))
+			return 1;
+		return -1;
+	}
+	/* otherwise, if the ID is the same, input channels first */
+	if (strcmp(tmp1->id, tmp2->id) == 0)
+		return !iio_channel_is_output(tmp1);
+
+	/* finally by ID */
+	return strcmp(tmp1->id, tmp2->id);
+}
+
+int iio_channel_attr_compare(const void *p1, const void *p2)
+{
+	const struct iio_channel_attr *tmp1 = (struct iio_channel_attr *)p1;
+	const struct iio_channel_attr *tmp2 = (struct iio_channel_attr *)p2;
+	/* qsort channel attributes by name */
+	return strcmp(tmp1->name, tmp2->name);
+}
+
+int iio_device_compare(const void *p1, const void *p2)
+{
+	const struct iio_device *tmp1 = *(struct iio_device **)p1;
+	const struct iio_device *tmp2 = *(struct iio_device **)p2;
+	/* qsort devices by ID */
+	return strcmp(tmp1->id, tmp2->id);
+}
+
+int iio_device_attr_compare(const void *p1, const void *p2)
+{
+	const char *tmp1 = *(const char **)p1;
+	const char *tmp2 = *(const char **)p2;
+	/* qsort device attributes by name */
+	return strcmp(tmp1, tmp2);
+}
+
+int iio_buffer_attr_compare(const void *p1, const void *p2)
+{
+	const char *tmp1 = *(const char **)p1;
+	const char *tmp2 = *(const char **)p2;
+	/* qsort buffer attributes by name */
+	return strcmp(tmp1, tmp2);
+}
+
diff --git a/src/sort.h b/src/sort.h
new file mode 100644
index 0000000..9f7cf33
--- /dev/null
+++ b/src/sort.h
@@ -0,0 +1,28 @@
+/*
+ * libiio - Library for interfacing industrial I/O (IIO) devices
+ *
+ * Copyright (C) 2018 Analog Devices, Inc.
+ * Author: Robin Getz <robin.getz@analog.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * */
+
+#ifndef __IIO_QSORT_H__
+#define __IIO_QSORT_H__
+
+int iio_channel_compare(const void *p1, const void *p2);
+int iio_channel_attr_compare(const void *p1, const void *p2);
+int iio_device_compare(const void *p1, const void *p2);
+int iio_device_attr_compare(const void *p1, const void *p2);
+int iio_buffer_attr_compare(const void *p1, const void *p2);
+
+#endif /* __IIO_QSORT_H__ */
diff --git a/src/tests/iio_attr.c b/src/tests/iio_attr.c
index e4d05d7..03dfcfd 100644
--- a/src/tests/iio_attr.c
+++ b/src/tests/iio_attr.c
@@ -644,7 +644,7 @@
 						const struct iio_data_format *format =
 							iio_channel_get_data_format(ch);
 						char sign = format->is_signed ? 's' : 'u';
-						char repeat[8] = "";
+						char repeat[12] = "";
 
 						if (format->is_fully_defined)
 							sign += 'A' - 'a';
diff --git a/src/tests/iio_info.c b/src/tests/iio_info.c
index 338ac38..a7ef57f 100644
--- a/src/tests/iio_info.c
+++ b/src/tests/iio_info.c
@@ -324,7 +324,7 @@
 				const struct iio_data_format *format =
 					iio_channel_get_data_format(ch);
 				char sign = format->is_signed ? 's' : 'u';
-				char repeat[8] = "";
+				char repeat[12] = "";
 
 				if (format->is_fully_defined)
 					sign += 'A' - 'a';
diff --git a/src/usb.c b/src/usb.c
index 2a48744..141bd41 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -150,7 +150,7 @@
 	return timeout / 2;
 }
 
-#define USB_PIPE_CTRL_TIMEOUT 200 /* These should not take long */
+#define USB_PIPE_CTRL_TIMEOUT 1000 /* These should not take long */
 
 #define IIO_USD_CMD_RESET_PIPES 0
 #define IIO_USD_CMD_OPEN_PIPE 1
@@ -740,6 +740,22 @@
 		}
 	}
 
+#ifdef HAS_LIBUSB_GETVERSION
+	/*
+	 * libusb_get_version was added 2012-04-17: v1.0.10,
+	 * before LIBUSB_API_VERSION was added - Jan 8, 2014
+	 * so, you can't use that to determine if it is here
+	 */
+	{
+	struct libusb_version const *ver = libusb_get_version();
+	iio_snprintf(buffer, sizeof(buffer), "%i.%i.%i.%i%s",
+			ver->major, ver->minor, ver->micro,
+			ver->nano, ver->rc);
+	ret = iio_context_add_attr(ctx, "usb,libusb", buffer);
+	if (ret < 0)
+		return ret;
+	}
+#endif
 	return 0;
 }
 
@@ -844,7 +860,8 @@
 	ret = libusb_claim_interface(hdl, interface);
 	if (ret) {
 		ret = -(int) libusb_to_errno(ret);
-		ERROR("Unable to claim interface %u: %i\n", interface, ret);
+		ERROR("Unable to claim interface %u:%u:%u: %i\n",
+		      bus, address, interface, ret);
 		goto err_libusb_close;
 	}